6 "github.com/nsf/termbox-go"
21 func (t *Textview) uiInitialize(ui *Ui) {
25 func (t *Textview) uiSetActive(active bool) {
28 func (t *Textview) uiSetBounds(x0, y0, x1, y1 int) {
37 func (t *Textview) ScrollUp() {
38 if newLine := t.CurrentLine + 1; newLine < len(t.parsedLines) {
39 t.CurrentLine = newLine
44 func (t *Textview) ScrollDown() {
45 if newLine := t.CurrentLine - 1; newLine >= 0 {
46 t.CurrentLine = newLine
51 func (t *Textview) ScrollTop() {
52 if newLine := len(t.parsedLines) - 1; newLine > 0 {
53 t.CurrentLine = newLine
60 func (t *Textview) ScrollBottom() {
65 func (t *Textview) updateParsedLines() {
66 width := t.x1 - t.x0 - 3
68 if t.Lines == nil || width <= 0 {
73 parsed := make([]string, 0, len(t.Lines))
74 for _, line := range t.Lines {
77 reader := strings.NewReader(line)
80 parsed = append(parsed, current)
84 if reader.Len() <= 0 {
86 parsed = append(parsed, current)
90 if ch, _, err := reader.ReadRune(); err == nil {
91 current = current + string(ch)
96 t.parsedLines = parsed
99 func (t *Textview) AddLine(line string) {
100 t.Lines = append(t.Lines, line)
101 t.updateParsedLines()
105 func (t *Textview) Clear() {
112 func (t *Textview) uiDraw() {
116 var reader *strings.Reader
117 line := len(t.parsedLines) - 1 - t.CurrentLine
121 totalLines := len(t.parsedLines)
125 currentScrollLine := t.y1 - 1 - int((float32(t.CurrentLine)/float32(totalLines))*float32(t.y1-t.y0))
126 for y := t.y1 - 1; y >= t.y0; y-- {
127 if t.parsedLines != nil && line >= 0 {
128 reader = strings.NewReader(t.parsedLines[line])
132 for x := t.x0; x < t.x1; x++ {
134 if x == t.x1-1 { // scrollbar
135 if y == currentScrollLine {
140 } else if x < t.x1-3 {
142 if ch, _, err := reader.ReadRune(); err == nil {
147 termbox.SetCell(x, y, chr, termbox.Attribute(t.Fg), termbox.Attribute(t.Bg))
153 func (t *Textview) uiKeyEvent(mod Modifier, key Key) {
156 func (t *Textview) uiCharacterEvent(chr rune) {