diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-06 11:42:57 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-06 11:49:26 -0400 |
| commit | 5295d34aad7aed6923973458006464da177035ed (patch) | |
| tree | 65f4f9288ff044aca7f22f9032755e9093dbe046 | |
| parent | 7e44005b62ab0de1d40f6527ea21eecfeff0969a (diff) | |
| download | muhqs-game-5295d34aad7aed6923973458006464da177035ed.tar.gz muhqs-game-5295d34aad7aed6923973458006464da177035ed.zip | |
add more ways to interact with a buffer's lines
| -rw-r--r-- | go/ui/buffer.go | 16 |
1 files changed, 16 insertions, 0 deletions
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) { |
