Add seconds config
This commit is contained in:
4
db/db.go
4
db/db.go
@@ -200,6 +200,7 @@ type Settings struct {
|
|||||||
BlinkOffMs int
|
BlinkOffMs int
|
||||||
ColorClock string
|
ColorClock string
|
||||||
ColorAlarm string
|
ColorAlarm string
|
||||||
|
ShowSeconds bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultSettings() Settings {
|
func DefaultSettings() Settings {
|
||||||
@@ -211,6 +212,7 @@ func DefaultSettings() Settings {
|
|||||||
BlinkOffMs: 500,
|
BlinkOffMs: 500,
|
||||||
ColorClock: "#00FF88",
|
ColorClock: "#00FF88",
|
||||||
ColorAlarm: "#FF4444",
|
ColorAlarm: "#FF4444",
|
||||||
|
ShowSeconds: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +225,7 @@ func (s *Store) LoadSettings() Settings {
|
|||||||
cfg.BlinkOffMs = s.getSettingInt("blink_off_ms", cfg.BlinkOffMs)
|
cfg.BlinkOffMs = s.getSettingInt("blink_off_ms", cfg.BlinkOffMs)
|
||||||
cfg.ColorClock = s.GetSetting("color_clock", cfg.ColorClock)
|
cfg.ColorClock = s.GetSetting("color_clock", cfg.ColorClock)
|
||||||
cfg.ColorAlarm = s.GetSetting("color_alarm", cfg.ColorAlarm)
|
cfg.ColorAlarm = s.GetSetting("color_alarm", cfg.ColorAlarm)
|
||||||
|
cfg.ShowSeconds = s.GetSetting("show_seconds", "true") == "true"
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +238,7 @@ func (s *Store) SaveSettings(cfg Settings) error {
|
|||||||
"blink_off_ms": fmt.Sprintf("%d", cfg.BlinkOffMs),
|
"blink_off_ms": fmt.Sprintf("%d", cfg.BlinkOffMs),
|
||||||
"color_clock": cfg.ColorClock,
|
"color_clock": cfg.ColorClock,
|
||||||
"color_alarm": cfg.ColorAlarm,
|
"color_alarm": cfg.ColorAlarm,
|
||||||
|
"show_seconds": fmt.Sprintf("%t", cfg.ShowSeconds),
|
||||||
}
|
}
|
||||||
for k, v := range pairs {
|
for k, v := range pairs {
|
||||||
if err := s.SetSetting(k, v); err != nil {
|
if err := s.SetSetting(k, v); err != nil {
|
||||||
|
|||||||
@@ -132,12 +132,17 @@ var bigColonBlink = []string{
|
|||||||
|
|
||||||
// RenderBigClock renders the current time as massive ASCII block digits.
|
// RenderBigClock renders the current time as massive ASCII block digits.
|
||||||
// Format: HH:MM:SS in 24h. blinkOnMs/blinkOffMs control the colon blink cycle.
|
// 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()
|
h := t.Hour()
|
||||||
m := t.Minute()
|
m := t.Minute()
|
||||||
s := t.Second()
|
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)
|
cycle := int64(blinkOnMs + blinkOffMs)
|
||||||
colonVisible := t.UnixMilli()%cycle < int64(blinkOnMs)
|
colonVisible := t.UnixMilli()%cycle < int64(blinkOnMs)
|
||||||
|
|||||||
30
ui/config.go
30
ui/config.go
@@ -19,6 +19,7 @@ const (
|
|||||||
cfgBlinkOffMs
|
cfgBlinkOffMs
|
||||||
cfgColorClock
|
cfgColorClock
|
||||||
cfgColorAlarm
|
cfgColorAlarm
|
||||||
|
cfgShowSeconds
|
||||||
cfgFieldCount
|
cfgFieldCount
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,6 +38,11 @@ func newConfigModel(cfg db.Settings) *configModel {
|
|||||||
c.fields[cfgBlinkOffMs] = strconv.Itoa(cfg.BlinkOffMs)
|
c.fields[cfgBlinkOffMs] = strconv.Itoa(cfg.BlinkOffMs)
|
||||||
c.fields[cfgColorClock] = cfg.ColorClock
|
c.fields[cfgColorClock] = cfg.ColorClock
|
||||||
c.fields[cfgColorAlarm] = cfg.ColorAlarm
|
c.fields[cfgColorAlarm] = cfg.ColorAlarm
|
||||||
|
if cfg.ShowSeconds {
|
||||||
|
c.fields[cfgShowSeconds] = "true"
|
||||||
|
} else {
|
||||||
|
c.fields[cfgShowSeconds] = "false"
|
||||||
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +80,27 @@ func (c *configModel) HandleKey(msg tea.KeyMsg, m *Model) (tea.Model, tea.Cmd) {
|
|||||||
c.err = ""
|
c.err = ""
|
||||||
return *m, nil
|
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:
|
default:
|
||||||
if len(key) == 1 {
|
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.fields[c.active] += key
|
||||||
c.err = ""
|
c.err = ""
|
||||||
}
|
}
|
||||||
@@ -130,6 +155,9 @@ func (c *configModel) save(m *Model) (tea.Model, tea.Cmd) {
|
|||||||
ColorAlarm: colorAlarm,
|
ColorAlarm: colorAlarm,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showSec := strings.TrimSpace(c.fields[cfgShowSeconds])
|
||||||
|
cfg.ShowSeconds = showSec == "true"
|
||||||
|
|
||||||
if cfg.DefaultSound == "" {
|
if cfg.DefaultSound == "" {
|
||||||
cfg.DefaultSound = "default"
|
cfg.DefaultSound = "default"
|
||||||
}
|
}
|
||||||
@@ -156,6 +184,7 @@ func (c *configModel) View() string {
|
|||||||
"Blink off (ms):",
|
"Blink off (ms):",
|
||||||
"Clock color:",
|
"Clock color:",
|
||||||
"Alarm color:",
|
"Alarm color:",
|
||||||
|
"Show seconds:",
|
||||||
}
|
}
|
||||||
|
|
||||||
hints := [cfgFieldCount]string{
|
hints := [cfgFieldCount]string{
|
||||||
@@ -166,6 +195,7 @@ func (c *configModel) View() string {
|
|||||||
"100-5000",
|
"100-5000",
|
||||||
"hex e.g. #00FF88",
|
"hex e.g. #00FF88",
|
||||||
"hex e.g. #FF4444",
|
"hex e.g. #FF4444",
|
||||||
|
"space to toggle",
|
||||||
}
|
}
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ func (m Model) View() string {
|
|||||||
var sections []string
|
var sections []string
|
||||||
|
|
||||||
// Big clock
|
// 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 {
|
if m.firingAlarm != nil && m.firingBlink {
|
||||||
clockStr = ClockAlarmStyle.Render(clockStr)
|
clockStr = ClockAlarmStyle.Render(clockStr)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user