summaryrefslogtreecommitdiff
path: root/tui/builder.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-05-31 17:16:38 -0500
committercitrons <citrons@mondecitronne.com>2025-05-31 17:16:57 -0500
commitb11c892158772f508e494b2726a5d4db1bb74d23 (patch)
tree16113353422520259ccc7937e9085a68ac6663a6 /tui/builder.go
parent0a58e68ad438ff43fa5bbecdb8914aa00cab5099 (diff)
text input box
Diffstat (limited to 'tui/builder.go')
-rw-r--r--tui/builder.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/tui/builder.go b/tui/builder.go
new file mode 100644
index 0000000..e969cec
--- /dev/null
+++ b/tui/builder.go
@@ -0,0 +1,39 @@
+package tui
+
+import (
+ "github.com/rivo/uniseg"
+)
+
+type builder struct {
+ runs []textRun
+ width int
+}
+
+func (b *builder) add(s string, style *Style) {
+ b.width += uniseg.StringWidth(s)
+ if len(b.runs) == 0 || style != b.runs[len(b.runs) - 1].style {
+ b.runs = append(b.runs, textRun {s, style, false})
+ } else {
+ run := b.runs[len(b.runs) - 1]
+ run.text += s
+ b.runs[len(b.runs) - 1] = run
+ }
+}
+
+func (b *builder) addRun(run textRun) {
+ b.width += uniseg.StringWidth(run.text)
+ b.runs = append(b.runs, run)
+}
+
+func (b *builder) addRuns(runs []textRun) {
+ for _, run := range runs {
+ b.addRun(run)
+ }
+}
+
+func (b *builder) flush() []textRun {
+ runs := b.runs
+ b.width = 0
+ b.runs = nil
+ return runs
+}