Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 12h mode alignment #17

Merged
merged 5 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ The configuration is stored in `$XDG_CONFIG_HOME/gotz/config.json` (usually `~/.
// Dynamic mode colors
// - tcell color names like crimson, green, etc.
// - hex codes like #DC143C, #00ff00, etc.
// Note that some symbols are not fully opaque and will show the background color, thus,
// making the color appear darker (or lighter for white/light terminal backgrounds)
"coloring": {
// Color of the morning segment for static mode
"StaticColorMorning": "#EC3620",
Expand Down
14 changes: 10 additions & 4 deletions core/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ type Plotter struct {

// formatTime formats the time in the default way (distinguishing 12/24 hours
// though).
func formatTime(twelve bool, t time.Time) string {
func formatTime(twelve, flush bool, t time.Time) string {
if twelve {
return t.Format("3:04PM")
// 12-hour format
s := t.Format("3:04PM")
if flush {
return fmt.Sprintf("%7s", s)
}
return s
} else {
// 24-hour format
return t.Format("15:04")
}
}
Expand Down Expand Up @@ -266,7 +272,7 @@ func PlotTime(plt Plotter, cfg Config, t time.Time) error {
headLine := strings.Repeat(" ",
timeInfoWidth+nowSlot-(len(nowTag)+1)) +
nowTag + " v " +
formatTime(cfg.Hours12, t)
formatTime(cfg.Hours12, false, t)
if len(headLine) > plt.TerminalWidth {
// Truncate head line if it is too long
headLine = headLine[:plt.TerminalWidth]
Expand Down Expand Up @@ -351,7 +357,7 @@ func createTimeInfos(cfg Config, t time.Time) (timeInfos []string, times []*time
"%s: %s %s",
timeInfo,
formatDay(cfg.Hours12, t.In(timeZones[i])),
formatTime(cfg.Hours12, t.In(timeZones[i])))
formatTime(cfg.Hours12, true, t.In(timeZones[i])))
timeInfos[i] = timeInfo
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/static_hours12.golden
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
now v 4:00PM
Local : Sat 24 Aug 1985 2:00PM |
Local : Sat 24 Aug 1985 2:00PM |
▒▒▒▒▒▒██████████████████|███████████▒▒▒▒▒▒▒▒▒▒▒▒
New York: Sat 24 Aug 1985 10:00AM |
▒▒▒▒▒▒██████|███████████████████████▒▒▒▒▒▒▒▒▒▒▒▒
Berlin : Sat 24 Aug 1985 4:00PM |
Berlin : Sat 24 Aug 1985 4:00PM |
▒▒▒▒▒▒████████████████████████|█████▒▒▒▒▒▒▒▒▒▒▒▒
Shanghai: Sat 24 Aug 1985 10:00PM |
████████████████████████▒▒▒▒▒▒▒▒▒▒▒▒| ▒▒▒▒▒▒██████
Expand Down
Loading