diff --git a/db/db.go b/db/db.go index e818f7e..70d91e8 100644 --- a/db/db.go +++ b/db/db.go @@ -200,6 +200,7 @@ type Settings struct { BlinkOffMs int ColorClock string ColorAlarm string + ShowSeconds bool } func DefaultSettings() Settings { @@ -211,6 +212,7 @@ func DefaultSettings() Settings { BlinkOffMs: 500, ColorClock: "#00FF88", ColorAlarm: "#FF4444", + ShowSeconds: true, } } @@ -223,6 +225,7 @@ func (s *Store) LoadSettings() Settings { cfg.BlinkOffMs = s.getSettingInt("blink_off_ms", cfg.BlinkOffMs) cfg.ColorClock = s.GetSetting("color_clock", cfg.ColorClock) cfg.ColorAlarm = s.GetSetting("color_alarm", cfg.ColorAlarm) + cfg.ShowSeconds = s.GetSetting("show_seconds", "true") == "true" return cfg } @@ -235,6 +238,7 @@ func (s *Store) SaveSettings(cfg Settings) error { "blink_off_ms": fmt.Sprintf("%d", cfg.BlinkOffMs), "color_clock": cfg.ColorClock, "color_alarm": cfg.ColorAlarm, + "show_seconds": fmt.Sprintf("%t", cfg.ShowSeconds), } for k, v := range pairs { if err := s.SetSetting(k, v); err != nil { diff --git a/ui/clock.go b/ui/clock.go index 72ba94a..8c119dd 100644 --- a/ui/clock.go +++ b/ui/clock.go @@ -132,12 +132,17 @@ var bigColonBlink = []string{ // RenderBigClock renders the current time as massive ASCII block digits. // Format: HH:MM:SS in 24h. blinkOnMs/blinkOffMs control the colon blink cycle. -func RenderBigClock(t time.Time, blinkOnMs, blinkOffMs int) string { +func RenderBigClock(t time.Time, blinkOnMs, blinkOffMs int, showSeconds bool) string { h := t.Hour() m := t.Minute() s := t.Second() - timeStr := fmt.Sprintf("%02d:%02d:%02d", h, m, s) + var timeStr string + if showSeconds { + timeStr = fmt.Sprintf("%02d:%02d:%02d", h, m, s) + } else { + timeStr = fmt.Sprintf("%02d:%02d", h, m) + } cycle := int64(blinkOnMs + blinkOffMs) colonVisible := t.UnixMilli()%cycle < int64(blinkOnMs) diff --git a/ui/config.go b/ui/config.go index 606e7b9..a5aab7f 100644 --- a/ui/config.go +++ b/ui/config.go @@ -19,6 +19,7 @@ const ( cfgBlinkOffMs cfgColorClock cfgColorAlarm + cfgShowSeconds cfgFieldCount ) @@ -37,6 +38,11 @@ func newConfigModel(cfg db.Settings) *configModel { c.fields[cfgBlinkOffMs] = strconv.Itoa(cfg.BlinkOffMs) c.fields[cfgColorClock] = cfg.ColorClock c.fields[cfgColorAlarm] = cfg.ColorAlarm + if cfg.ShowSeconds { + c.fields[cfgShowSeconds] = "true" + } else { + c.fields[cfgShowSeconds] = "false" + } return c } @@ -74,8 +80,27 @@ func (c *configModel) HandleKey(msg tea.KeyMsg, m *Model) (tea.Model, tea.Cmd) { c.err = "" return *m, nil + case " ": + // Toggle boolean fields + if c.active == cfgShowSeconds { + if c.fields[cfgShowSeconds] == "true" { + c.fields[cfgShowSeconds] = "false" + } else { + c.fields[cfgShowSeconds] = "true" + } + return *m, nil + } + // Space as literal for other fields + c.fields[c.active] += " " + c.err = "" + return *m, nil + default: if len(key) == 1 { + // Don't allow free typing on boolean fields + if c.active == cfgShowSeconds { + return *m, nil + } c.fields[c.active] += key c.err = "" } @@ -130,6 +155,9 @@ func (c *configModel) save(m *Model) (tea.Model, tea.Cmd) { ColorAlarm: colorAlarm, } + showSec := strings.TrimSpace(c.fields[cfgShowSeconds]) + cfg.ShowSeconds = showSec == "true" + if cfg.DefaultSound == "" { cfg.DefaultSound = "default" } @@ -156,6 +184,7 @@ func (c *configModel) View() string { "Blink off (ms):", "Clock color:", "Alarm color:", + "Show seconds:", } hints := [cfgFieldCount]string{ @@ -166,6 +195,7 @@ func (c *configModel) View() string { "100-5000", "hex e.g. #00FF88", "hex e.g. #FF4444", + "space to toggle", } var lines []string diff --git a/ui/model.go b/ui/model.go index b71ceb2..02447d5 100644 --- a/ui/model.go +++ b/ui/model.go @@ -350,7 +350,7 @@ func (m Model) View() string { var sections []string // Big clock - clockStr := RenderBigClock(m.now, m.settings.BlinkOnMs, m.settings.BlinkOffMs) + clockStr := RenderBigClock(m.now, m.settings.BlinkOnMs, m.settings.BlinkOffMs, m.settings.ShowSeconds) if m.firingAlarm != nil && m.firingBlink { clockStr = ClockAlarmStyle.Render(clockStr) } else { diff --git a/woke b/woke index 4b9dade..11765cc 100755 Binary files a/woke and b/woke differ