diff options
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/ansi.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/parse/ansi.go b/lib/parse/ansi.go index a9a46fdd..94f0c4fc 100644 --- a/lib/parse/ansi.go +++ b/lib/parse/ansi.go @@ -67,9 +67,30 @@ func (rb *RuneBuffer) Write(r rune, style tcell.Style) { } // Prepend inserts the rune at the beginning of the rune buffer -func (rb *RuneBuffer) Prepend(r rune, style tcell.Style) { - w := runewidth.RuneWidth(r) - rb.buf = append([]*StyledRune{{r, w, style}}, rb.buf...) +func (rb *RuneBuffer) PadLeft(width int, r rune, style tcell.Style) { + w := rb.Len() + if w >= width { + return + } + w = width - w + for w > 0 { + ww := runewidth.RuneWidth(r) + w -= ww + rb.buf = append([]*StyledRune{{r, ww, style}}, rb.buf...) + } +} + +func (rb *RuneBuffer) PadRight(width int, r rune, style tcell.Style) { + w := rb.Len() + if w >= width { + return + } + w = width - w + for w > 0 { + ww := runewidth.RuneWidth(r) + w -= ww + rb.buf = append(rb.buf, &StyledRune{r, ww, style}) + } } // String outputs a styled-string using TERM=xterm-256color |