aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-06 11:42:57 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-06 11:49:26 -0400
commit5295d34aad7aed6923973458006464da177035ed (patch)
tree65f4f9288ff044aca7f22f9032755e9093dbe046
parent7e44005b62ab0de1d40f6527ea21eecfeff0969a (diff)
downloadmuhqs-game-5295d34aad7aed6923973458006464da177035ed.tar.gz
muhqs-game-5295d34aad7aed6923973458006464da177035ed.zip
add more ways to interact with a buffer's lines
-rw-r--r--go/ui/buffer.go16
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) {