summaryrefslogtreecommitdiff
path: root/internal/atable
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 16:46:39 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-21 16:46:39 +0300
commitb98ec7ee519b0ef118cffa54ee51f384e836c5e8 (patch)
tree6e62e0998339c34640f66acc3989036ac149bf22 /internal/atable
parentb53da415ee2347d9f6b10c2e1c3256f0a9ccca67 (diff)
Highlight spacing in selected row
Diffstat (limited to 'internal/atable')
-rw-r--r--internal/atable/table.go36
1 files changed, 28 insertions, 8 deletions
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
+}