From 9c20cc5895e9becbe066abab66d468e961af0467 Mon Sep 17 00:00:00 2001 From: citrons Date: Sun, 1 Jun 2025 15:28:50 -0500 Subject: NoWrap --- tui/layout.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'tui') 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 { -- cgit v1.2.3