From b98ec7ee519b0ef118cffa54ee51f384e836c5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sat, 21 Jun 2025 16:46:39 +0300 Subject: Highlight spacing in selected row --- internal/atable/table.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'internal/atable') diff --git a/internal/atable/table.go b/internal/atable/table.go index 03e946f..3e6cc93 100644 --- a/internal/atable/table.go +++ b/internal/atable/table.go @@ -476,19 +476,22 @@ func (m Model) headersView() string { } func (m *Model) renderRow(r int) string { + highlightRow := r == m.cursor + rowStyle := m.styles.Cell + if highlightRow { + rowStyle = rowStyle. + Background(lipgloss.Color("57")). + Foreground(lipgloss.Color("0")). + Bold(false) + } + s := make([]string, 0, len(m.cols)) for i, value := range m.rows[r] { if m.cols[i].Width <= 0 { continue } - style := m.styles.Cell - if r == m.cursor { - style = style. - Background(lipgloss.Color("57")). - Foreground(lipgloss.Color("0")). - Bold(false) - } - if r == m.cursor && i == m.colCursor { + style := rowStyle + if highlightRow && i == m.colCursor { style = m.styles.Selected } style = style.Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true) @@ -496,6 +499,9 @@ func (m *Model) renderRow(r int) string { s = append(s, renderedCell) } + if highlightRow { + return lipgloss.JoinHorizontal(lipgloss.Top, addSpacingStyled(s, rowStyle)...) + } return lipgloss.JoinHorizontal(lipgloss.Top, addSpacing(s)...) } @@ -516,3 +522,17 @@ func addSpacing(cells []string) []string { } return spaced } + +func addSpacingStyled(cells []string, style lipgloss.Style) []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, style.Render(" ")) + } + spaced = append(spaced, cell) + } + return spaced +} -- cgit v1.2.3