@@ -25,16 +25,12 @@ type Column struct {
2525// for displaying a slice of structs
2626type Table struct {
2727 X , Y int
28- W , H int
2928 Win * goncurses.Window
3029
3130 // See column struct for docs
3231 Columns []Column
33- // Each sub-slice represents each column entry (eg, 0 = first column)
34- Items [][]string
35-
36- scroll int
37- sel int
32+ // Each slice represents each column entry (eg, 0 = first column)
33+ List [[]string ]
3834
3935 prevw , prevh int
4036 prevlen int
@@ -43,6 +39,9 @@ type Table struct {
4339// Render immediately renders the table to the requested coords X and Y
4440// with the space taken up limited to the space W*H
4541func (t * Table ) Render () {
42+ // Reduce height to be actual usable space (minus headings)
43+ t .H -= 2
44+
4645 items := t .Items [t .scroll :]
4746 if t .prevw != t .W || t .prevh != t .H {
4847 t .scroll = 0
@@ -77,7 +76,7 @@ func (t *Table) Render() {
7776 for j , entry := range items {
7877 if i >= len (entry ) {
7978 panic ("invalid table entry: missing fields" )
80- } else if j > t .H - 2 {
79+ } else if j > t .H {
8180 break
8281 }
8382
@@ -110,43 +109,3 @@ func (t *Table) Render() {
110109 off += colw
111110 }
112111}
113-
114- // GetSelection returns the text of the currently
115- // selected menu element. If there are no items selected,
116- // GetSelection returns an empty slice.
117- func (t * Table ) GetSelection () (int , []string ) {
118- if len (t .Items ) < 1 {
119- return 0 , []string {}
120- }
121-
122- return t .sel , t .Items [t .sel ]
123- }
124-
125- // ChangeSelection changes the selection to the index specified.
126- // If index is out of range, no action is taken.
127- func (t * Table ) ChangeSelection (index int ) {
128- if index >= len (t .Items ) || index < 0 {
129- return
130- }
131-
132- t .sel = index
133-
134- // Scroll at the last possible visible element
135- // Underscroll at the first possible visible element
136- scrollAt := t .H + t .scroll - 1
137- underscrollAt := t .scroll - 1
138-
139- if t .sel >= scrollAt {
140- t .scroll += (t .sel - scrollAt ) + 1
141- } else if t .sel <= underscrollAt {
142- t .scroll -= (t .sel - underscrollAt ) + 1
143- }
144- }
145-
146- // MoveSelection changes the selected item relative to the current
147- // position. If the new selection would be out of range, no action
148- // is taken.
149- func (t * Table ) MoveSelection (offset int ) {
150- off := t .sel + offset
151- t .ChangeSelection (off )
152- }
0 commit comments