summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-01 15:28:50 -0500
committercitrons <citrons@mondecitronne.com>2025-06-01 15:28:50 -0500
commit9c20cc5895e9becbe066abab66d468e961af0467 (patch)
treeed88d6354214ebf3bd3fcb3e824cd305dce6940e
parent4aea639772ce02d3f3f67b1830c4fa363c980a02 (diff)
NoWrap
-rw-r--r--tui/layout.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/tui/layout.go b/tui/layout.go
index 1413243..398c0b1 100644
--- a/tui/layout.go
+++ b/tui/layout.go
@@ -13,6 +13,7 @@ type Box struct {
Style *Style
Margins [4]int
Scroll *ScrollState
+ NoWrap bool
text []textRun
computedLines [][]textRun
children []*Box
@@ -215,14 +216,18 @@ func (b *Box) computeText(axis int) {
}
g := uniseg.NewGraphemes(run.text)
for g.Next() {
- word.add(g.Str(), run.style)
- if word.width >= limit {
- line.addRuns(word.flush())
- } else if line.width + word.width > limit {
- b.computedLines = append(b.computedLines, line.flush())
- }
- if unicode.IsSpace(g.Runes()[0]) {
- line.addRuns(word.flush())
+ if !b.NoWrap {
+ word.add(g.Str(), run.style)
+ if word.width >= limit {
+ line.addRuns(word.flush())
+ } else if line.width + word.width > limit {
+ b.computedLines = append(b.computedLines, line.flush())
+ }
+ if unicode.IsSpace(g.Runes()[0]) {
+ line.addRuns(word.flush())
+ }
+ } else {
+ line.add(g.Str(), run.style)
}
if g.Str() == "\n" {
line.addRuns(word.flush())
@@ -377,7 +382,14 @@ func (b *Box) drawComputed(parentRect rect, parentStyle Style) {
if t.hasCursor {
ShowCursor(x, y)
}
- x += WriteAt(x, y, t.text, s)
+ g := uniseg.NewGraphemes(t.text)
+ for g.Next() {
+ if x + g.Width() <= b.computedRect.max[0] {
+ x += WriteAt(x, y, g.Str(), s)
+ } else {
+ break
+ }
+ }
}
}
for _, c := range b.children {