mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Add comment calling out the fork + import table_test.go too
This commit is contained in:
parent
269ccc9f9a
commit
e1cb97f7c6
@ -1,3 +1,5 @@
|
||||
// Forked from https://github.com/charmbracelet/bubbles/blob/master/table/table.go to add horizontal scrolling
|
||||
|
||||
package table
|
||||
|
||||
import (
|
||||
@ -137,9 +139,9 @@ func New(opts ...Option) Model {
|
||||
KeyMap: DefaultKeyMap(),
|
||||
styles: DefaultStyles(),
|
||||
|
||||
hcol: -1,
|
||||
hstep: 10,
|
||||
hcursor: 0,
|
||||
hcol: -1,
|
||||
hstep: 10,
|
||||
hcursor: 0,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@ -326,7 +328,7 @@ func (m *Model) MaxHScroll() int {
|
||||
maxWidth = max(len(row[index]), maxWidth)
|
||||
}
|
||||
}
|
||||
return max(maxWidth-m.cols[index].Width+1, 0)
|
||||
return max(maxWidth-m.cols[index].Width+1, 0)
|
||||
}
|
||||
|
||||
// SetWidth sets the width of the viewport of the table.
|
||||
|
56
client/table/table_test.go
Normal file
56
client/table/table_test.go
Normal file
@ -0,0 +1,56 @@
|
||||
// Forked from https://github.com/charmbracelet/bubbles/blob/master/table/table_test.go to add horizontal scrolling
|
||||
|
||||
package table
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFromValues(t *testing.T) {
|
||||
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
|
||||
table := New(WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
table.FromValues(input, ",")
|
||||
|
||||
if len(table.rows) != 3 {
|
||||
t.Fatalf("expect table to have 3 rows but it has %d", len(table.rows))
|
||||
}
|
||||
|
||||
expect := []Row{
|
||||
{"foo1", "bar1"},
|
||||
{"foo2", "bar2"},
|
||||
{"foo3", "bar3"},
|
||||
}
|
||||
if !deepEqual(table.rows, expect) {
|
||||
t.Fatal("table rows is not equals to the input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromValuesWithTabSeparator(t *testing.T) {
|
||||
input := "foo1.\tbar1\nfoo,bar,baz\tbar,2"
|
||||
table := New(WithColumns([]Column{{Title: "Foo"}, {Title: "Bar"}}))
|
||||
table.FromValues(input, "\t")
|
||||
|
||||
if len(table.rows) != 2 {
|
||||
t.Fatalf("expect table to have 2 rows but it has %d", len(table.rows))
|
||||
}
|
||||
|
||||
expect := []Row{
|
||||
{"foo1.", "bar1"},
|
||||
{"foo,bar,baz", "bar,2"},
|
||||
}
|
||||
if !deepEqual(table.rows, expect) {
|
||||
t.Fatal("table rows is not equals to the input")
|
||||
}
|
||||
}
|
||||
|
||||
func deepEqual(a, b []Row) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, r := range a {
|
||||
for j, f := range r {
|
||||
if f != b[i][j] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user