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-08-20 15:57:25 +0200
commitfab29fbfe76947a5140bb0cab6f2f9a61a30caa2 (patch)
treebc7310a9a4e29e019db21dee9979cace09b3061e
parent6f69c5a37ac8bbbd1b35aaea5bb816418d4cb4c7 (diff)
downloadmuhqs-game-fab29fbfe76947a5140bb0cab6f2f9a61a30caa2.tar.gz
muhqs-game-fab29fbfe76947a5140bb0cab6f2f9a61a30caa2.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) {