Skip to content

Commit

Permalink
Merge pull request #321 from ndgit/flybyray/issue238
Browse files Browse the repository at this point in the history
Add support to show current date and time
  • Loading branch information
justjanne authored Feb 17, 2022
2 parents 0c029fc + c776714 commit 712a3a2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type arguments struct {
Eval *bool
Condensed *bool
IgnoreWarnings *bool
Time *string
}

var args = arguments{
Expand Down Expand Up @@ -194,6 +195,12 @@ var args = arguments{
"duration",
defaults.Duration,
comments("The elapsed clock-time of the previous command")),
Time: flag.String(
"time",
defaults.Time,
comments("The layout string how a reference time should be represented.",
"The reference time is predefined and not user choosen.",
"Consult the golang documentation for details: https://pkg.go.dev/time#example-Time.Format")),
DurationMin: flag.String(
"duration-min",
defaults.DurationMin,
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {
Modes SymbolMap `json:"modes"`
Shells ShellMap `json:"shells"`
Themes ThemeMap `json:"themes"`
Time string `json:"-"`
}

func (mode *SymbolTemplate) UnmarshalJSON(data []byte) error {
Expand Down
1 change: 1 addition & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ var defaults = Config{
NixShellBg: gruvbox_faded_purple,
},
},
Time: "15:04:05",
}

const (
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func main() {
cfg.Condensed = *args.Condensed
case "ignore-warnings":
cfg.IgnoreWarnings = *args.IgnoreWarnings
case "time":
cfg.Time = *args.Time
}
})

Expand Down
3 changes: 2 additions & 1 deletion segment-time.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"strings"
pwl "github.com/justjanne/powerline-go/powerline"
"time"
)

func segmentTime(p *powerline) []pwl.Segment {
return []pwl.Segment{{
Name: "time",
Content: time.Now().Format("15:04:05"),
Content: time.Now().Format(strings.TrimSpace(p.cfg.Time)),
Foreground: p.theme.TimeFg,
Background: p.theme.TimeBg,
}}
Expand Down

0 comments on commit 712a3a2

Please sign in to comment.