From 42449043cf1903e0e72295b096274d26187a61b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Fri, 20 Jun 2025 22:53:21 +0300 Subject: Space separated tags and table column spacing --- internal/atable/table.go | 18 ++++++++++++++++-- internal/task/task.go | 2 +- internal/ui/table.go | 6 +++--- internal/ui/table_test.go | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) (limited to 'internal') diff --git a/internal/atable/table.go b/internal/atable/table.go index 8f2b3c0..7251b11 100644 --- a/internal/atable/table.go +++ b/internal/atable/table.go @@ -472,7 +472,7 @@ func (m Model) headersView() string { renderedCell := style.Render(ansi.Truncate(col.Title, col.Width, "…")) s = append(s, m.styles.Header.Render(renderedCell)) } - return lipgloss.JoinHorizontal(lipgloss.Top, s...) + return lipgloss.JoinHorizontal(lipgloss.Top, addSpacing(s)...) } func (m *Model) renderRow(r int) string { @@ -490,9 +490,23 @@ func (m *Model) renderRow(r int) string { s = append(s, renderedCell) } - return lipgloss.JoinHorizontal(lipgloss.Top, s...) + return lipgloss.JoinHorizontal(lipgloss.Top, addSpacing(s)...) } func clamp(v, low, high int) int { return min(max(v, low), high) } + +func addSpacing(cells []string) []string { + if len(cells) <= 1 { + return cells + } + spaced := make([]string, 0, len(cells)*2-1) + for i, cell := range cells { + if i > 0 { + spaced = append(spaced, " ") + } + spaced = append(spaced, cell) + } + return spaced +} diff --git a/internal/task/task.go b/internal/task/task.go index 9c715c8..4acfec9 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -250,7 +250,7 @@ func SortTasks(tasks []Task) { } cpy := append([]string(nil), tags...) sort.Strings(cpy) - return strings.Join(cpy, ",") + return strings.Join(cpy, " ") } priVal := func(p string) int { diff --git a/internal/ui/table.go b/internal/ui/table.go index 530e813..2ba73c3 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -132,7 +132,7 @@ func (m *Model) reload() error { for i, tsk := range tasks { rows = append(rows, taskToRowSearch(tsk, m.searchRegex)) if m.searchRegex != nil { - tags := strings.Join(tsk.Tags, ",") + tags := strings.Join(tsk.Tags, " ") if m.searchRegex.MatchString(tags) { m.searchMatches = append(m.searchMatches, cellMatch{row: i, col: 5}) } @@ -508,7 +508,7 @@ func taskToRow(t task.Task) atable.Row { age = fmt.Sprintf("%dd", days) } - tags := strings.Join(t.Tags, ",") + tags := strings.Join(t.Tags, " ") urg := fmt.Sprintf("%.1f", t.Urgency) var anns []string @@ -597,7 +597,7 @@ func taskToRowSearch(t task.Task, re *regexp.Regexp) atable.Row { age = fmt.Sprintf("%dd", days) } - tags := strings.Join(t.Tags, ",") + tags := strings.Join(t.Tags, " ") urg := fmt.Sprintf("%.1f", t.Urgency) var anns []string diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go index d120337..d7ee19d 100644 --- a/internal/ui/table_test.go +++ b/internal/ui/table_test.go @@ -470,7 +470,7 @@ func TestEscClosesHelp(t *testing.T) { t.Fatalf("New: %v", err) } - mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) + mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'h'}}) m = mv.(Model) if !m.showHelp { t.Fatalf("help not shown") -- cgit v1.2.3