gitstack

grindlemire/go-tui code browser

1.0 KB Go 42 lines 2026-06-03 · d15bb9f raw
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
package tui

import (
	"fmt"
	"strings"
)

func inlineAppendWriteLine(seq *strings.Builder, row int, text string) {
	if row < 0 {
		return
	}
	seq.WriteString(fmt.Sprintf("\033[%d;1H\033[2K", row+1))
	seq.WriteString(text)
}

// inlineAppendUpdateLine overwrites an existing row in-place. Identical to
// inlineAppendWriteLine — separated for semantic clarity in call sites.
func inlineAppendUpdateLine(seq *strings.Builder, row int, text string) {
	inlineAppendWriteLine(seq, row, text)
}

func inlineAppendScrollUp(seq *strings.Builder, topRow, bottomRow, n int) {
	if n < 1 || topRow < 0 || bottomRow < 0 || topRow > bottomRow {
		return
	}
	seq.WriteString(fmt.Sprintf("\033[%d;%dr", topRow+1, bottomRow+1))
	seq.WriteString(fmt.Sprintf("\033[%d;1H", bottomRow+1))
	for range n {
		seq.WriteString("\n")
	}
	seq.WriteString("\033[r")
}

func inlineAppendClearRows(seq *strings.Builder, startRow, count int) {
	if startRow < 0 || count < 1 {
		return
	}
	for i := range count {
		row := startRow + i
		seq.WriteString(fmt.Sprintf("\033[%d;1H\033[2K", row+1))
	}
}