Skip to content

Commit

Permalink
Right-align horizontal scrolling caret (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras authored Jun 5, 2022
1 parent 6410a6a commit 0d4a851
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions table/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (m Model) renderRowColumnData(row Row, column Column, rowStyle lipgloss.Sty
str = m.unselectedText
}
} else if column.key == columnKeyOverflowRight {
cellStyle = cellStyle.Align(lipgloss.Right)
str = ">"
} else if column.key == columnKeyOverflowLeft {
str = "<"
Expand Down
33 changes: 33 additions & 0 deletions table/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,36 @@ func TestScrolledTableSizesFooterCorrectly(t *testing.T) {
rendered := model.View()
assert.Equal(t, expectedTable, rendered)
}

func TestHorizontalScrollCaretIsRightAligned(t *testing.T) {
leftAlign := lipgloss.NewStyle().Align(lipgloss.Left)
model := New([]Column{
NewColumn("1", "1", 4),
NewColumn("2", "2", 4),
NewColumn("3", "3", 4),
NewColumn("4", "4", 4),
}).
WithRows([]Row{
NewRow(RowData{
"1": "x1",
"2": "x2",
"3": "x3",
"4": "x4",
}).WithStyle(leftAlign),
}).
HeaderStyle(leftAlign).
WithStaticFooter("Footer").
WithMaxTotalWidth(17)

const expectedTable = `┏━━━━┳━━━━┳━━━━━┓
┃1 ┃2 ┃ >┃
┣━━━━╋━━━━╋━━━━━┫
┃x1 ┃x2 ┃ >┃
┣━━━━┻━━━━┻━━━━━┫
┃ Footer┃
┗━━━━━━━━━━━━━━━┛`

rendered := model.View()

assert.Equal(t, expectedTable, rendered)
}

0 comments on commit 0d4a851

Please sign in to comment.