Add seconds config
This commit is contained in:
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
|
||||
|
||||
Reference in New Issue
Block a user