From fab29fbfe76947a5140bb0cab6f2f9a61a30caa2 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 6 Jul 2025 11:42:57 -0400 Subject: add more ways to interact with a buffer's lines --- go/ui/buffer.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/go/ui/buffer.go b/go/ui/buffer.go index 3abbc2cc..8294c905 100644 --- a/go/ui/buffer.go +++ b/go/ui/buffer.go @@ -2,6 +2,7 @@ package ui import ( "image/color" + "iter" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/text/v2" @@ -72,6 +73,21 @@ func (b *Buffer) Remove(idx int) { b.ForceRedraw() } +func (b *Buffer) PrefixLine(idx int, prefix string) { + b.lines[idx] = prefix + b.lines[idx] + b.ForceRedraw() +} + +func (b *Buffer) LinesSeq() iter.Seq[string] { + return func(yield func(string) bool) { + for _, l := range b.lines { + if !yield(l) { + return + } + } + } +} + func (*Buffer) IsScrollable() bool { return true } func (b *Buffer) Scroll(x, y int) { -- cgit v1.2.3