File: main.go

package info (click to toggle)
golang-github-rivo-tview 0.0~git20221029.c4a7e50-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 3,848 kB
  • sloc: makefile: 3
file content (44 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"fmt"
	"math"

	"github.com/rivo/tview"
)

type TableData struct {
	tview.TableContentReadOnly
}

func (d *TableData) GetCell(row, column int) *tview.TableCell {
	letters := [...]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A' + byte(row%26)} // log(math.MaxInt64) / log(26) ~= 14
	start := len(letters) - 1
	row /= 26
	for row > 0 {
		start--
		row--
		letters[start] = 'A' + byte(row%26)
		row /= 26
	}
	return tview.NewTableCell(fmt.Sprintf("[red]%s[green]%d", letters[start:], column))
}

func (d *TableData) GetRowCount() int {
	return math.MaxInt64
}

func (d *TableData) GetColumnCount() int {
	return math.MaxInt64
}

func main() {
	data := &TableData{}
	table := tview.NewTable().
		SetBorders(false).
		SetSelectable(true, true).
		SetContent(data)
	if err := tview.NewApplication().SetRoot(table, true).EnableMouse(true).Run(); err != nil {
		panic(err)
	}
}