oh-my-posh/segment_executiontime.go

38 lines
764 B
Go
Raw Normal View History

2020-12-06 13:03:40 -08:00
package main
import (
"time"
)
type executiontime struct {
props *properties
env environmentInfo
output string
}
const (
// ThresholdProperty represents minimum duration (milliseconds) required to enable this segment
ThresholdProperty Property = "threshold"
)
func (t *executiontime) enabled() bool {
executionTimeMs := t.env.executionTime()
thresholdMs := t.props.getFloat64(ThresholdProperty, float64(500))
if executionTimeMs < thresholdMs {
return false
}
duration := time.Duration(executionTimeMs) * time.Millisecond
t.output = duration.String()
return t.output != ""
}
func (t *executiontime) string() string {
return t.output
}
func (t *executiontime) init(props *properties, env environmentInfo) {
t.props = props
t.env = env
}