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) {
36 func (t *Textview) ScrollUp() {
37 if newLine := t.CurrentLine + 1; newLine < len(t.parsedLines) {
38 t.CurrentLine = newLine
42 func (t *Textview) ScrollDown() {
43 if newLine := t.CurrentLine - 1; newLine >= 0 {
44 t.CurrentLine = newLine
48 func (t *Textview) ScrollTop() {
49 if newLine := len(t.parsedLines) - 1; newLine > 0 {
50 t.CurrentLine = newLine
56 func (t *Textview) ScrollBottom() {
60 func (t *Textview) updateParsedLines() {
61 width := t.x1 - t.x0 - 3
63 if t.Lines == nil || width <= 0 {
68 parsed := make([]string, 0, len(t.Lines))
69 for _, line := range t.Lines {
72 reader := strings.NewReader(line)
75 parsed = append(parsed, current)
79 if reader.Len() <= 0 {
81 parsed = append(parsed, current)
85 if ch, _, err := reader.ReadRune(); err == nil {
86 current = current + string(ch)
91 t.parsedLines = parsed
94 func (t *Textview) AddLine(line string) {
95 t.Lines = append(t.Lines, line)
99 func (t *Textview) Clear() {
105 func (t *Textview) uiDraw() {
106 var reader *strings.Reader
107 line := len(t.parsedLines) - 1 - t.CurrentLine
111 totalLines := len(t.parsedLines)
115 currentScrollLine := t.y1 - 1 - int((float32(t.CurrentLine)/float32(totalLines))*float32(t.y1-t.y0))
116 for y := t.y1 - 1; y >= t.y0; y-- {
117 if t.parsedLines != nil && line >= 0 {
118 reader = strings.NewReader(t.parsedLines[line])
122 for x := t.x0; x < t.x1; x++ {
124 if x == t.x1-1 { // scrollbar
125 if y == currentScrollLine {
130 } else if x < t.x1-3 {
132 if ch, _, err := reader.ReadRune(); err == nil {
137 termbox.SetCell(x, y, chr, termbox.Attribute(t.Fg), termbox.Attribute(t.Bg))
143 func (t *Textview) uiKeyEvent(mod Modifier, key Key) {
146 func (t *Textview) uiCharacterEvent(chr rune) {