Skip to content

Commit

Permalink
Merge pull request #308 from pridkett/feat/307-duration-min-precision
Browse files Browse the repository at this point in the history
feat(duration): add low precision duration setting
  • Loading branch information
justjanne authored Apr 8, 2021
2 parents d46c75c + 4cc0876 commit b5a2519
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type arguments struct {
PathAliases *string
Duration *string
DurationMin *string
DurationLowPrecision *bool
Eval *bool
Condensed *bool
IgnoreWarnings *bool
Expand Down Expand Up @@ -192,6 +193,10 @@ var args = arguments{
"duration-min",
defaults.DurationMin,
comments("The minimal time a command has to take before the duration segment is shown")),
DurationLowPrecision: flag.Bool(
"duration-low-precision",
defaults.DurationLowPrecision,
comments("Use low precision timing for duration with milliseconds as maximum resolution")),
Eval: flag.Bool(
"eval",
defaults.Eval,
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
PathAliases AliasMap `json:"path-aliases"`
Duration string `json:"-"`
DurationMin string `json:"duration-min"`
DurationLowPrecision bool `json:"duration-low-precision"`
Eval bool `json:"eval"`
Condensed bool `json:"condensed"`
IgnoreWarnings bool `json:"ignore-warnings"`
Expand Down
1 change: 1 addition & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var defaults = Config{
PathAliases: AliasMap{},
Duration: "",
DurationMin: "0",
DurationLowPrecision: false,
Eval: false,
Condensed: false,
IgnoreWarnings: false,
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func main() {
cfg.Duration = *args.Duration
case "duration-min":
cfg.DurationMin = *args.DurationMin
case "duration-low-precision":
cfg.DurationLowPrecision = *args.DurationLowPrecision
case "eval":
cfg.Eval = *args.Eval
case "condensed":
Expand Down
8 changes: 6 additions & 2 deletions segment-duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ func segmentDuration(p *powerline) []pwl.Segment {
ns -= secs * seconds
millis := ns / milliseconds
content = fmt.Sprintf("%ds %dms", secs, millis)
} else if ns > milliseconds {
} else if ns > milliseconds || p.cfg.DurationLowPrecision {
millis := ns / milliseconds
ns -= millis * milliseconds
micros := ns / microseconds
content = fmt.Sprintf("%dms %d\u00B5s", millis, micros)
if p.cfg.DurationLowPrecision {
content = fmt.Sprintf("%dms", millis)
} else {
content = fmt.Sprintf("%dms %d\u00B5s", millis, micros)
}
} else {
content = fmt.Sprintf("%d\u00B5s", ns/microseconds)
}
Expand Down

0 comments on commit b5a2519

Please sign in to comment.