Add seconds config
This commit is contained in:
@@ -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)
|
||||
|
||||
30
ui/config.go
30
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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user