Agreeable goat

This commit is contained in:
2026-02-01 21:27:52 +02:00
parent 06d5a6a779
commit f283c5e99e
4 changed files with 91 additions and 33 deletions

View File

@@ -154,6 +154,12 @@ func (f *formModel) save(m *Model) (tea.Model, tea.Cmd) {
return *m, nil
}
const (
formLabelWidth = 14 // longest label is "Time (HH:MM):" = 13 + 1 padding
formValueWidth = 30
formHintWidth = 32
)
func (f *formModel) View() string {
title := "Add Alarm"
if f.editing != nil {
@@ -161,11 +167,11 @@ func (f *formModel) View() string {
}
labels := [fieldCount]string{
"Name: ",
"Description: ",
"Name:",
"Description:",
"Time (HH:MM):",
"Trigger: ",
"Sound: ",
"Trigger:",
"Sound:",
}
hints := [fieldCount]string{
@@ -180,19 +186,27 @@ func (f *formModel) View() string {
lines = append(lines, TitleStyle.Render(title), "")
for i := formField(0); i < fieldCount; i++ {
label := FormLabelStyle.Render(labels[i])
value := f.fields[i]
hint := HelpStyle.Render(hints[i])
// Right-align labels in a fixed-width column
labelStr := fmt.Sprintf("%*s", formLabelWidth, labels[i])
value := f.fields[i]
var style lipgloss.Style
if i == f.active {
style = FormActiveStyle
value += "█" // cursor
value += "█"
} else {
style = FormLabelStyle
}
line := fmt.Sprintf(" %s %s %s", label, style.Render(value), hint)
// Truncate from the left if too long, then pad to fixed width
if len(value) > formValueWidth {
value = value[len(value)-formValueWidth:]
}
valueStr := fmt.Sprintf("%-*s", formValueWidth, value)
hintStr := fmt.Sprintf("%-*s", formHintWidth, hints[i])
line := FormLabelStyle.Render(labelStr) + " " + style.Render(valueStr) + " " + HelpStyle.Render(hintStr)
lines = append(lines, line)
}