fix(cli): respect stdin override in Scanln

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 13:18:36 +00:00
parent 905dfae6b1
commit 821f7d191d
2 changed files with 19 additions and 1 deletions

View file

@ -132,7 +132,7 @@ func Label(word, value string) {
// Scanln reads from stdin. // Scanln reads from stdin.
func Scanln(a ...any) (int, error) { func Scanln(a ...any) (int, error) {
return fmt.Scanln(a...) return fmt.Fscanln(newReader(), a...)
} }
// Task prints a task header: "[label] message" // Task prints a task header: "[label] message"

View file

@ -141,3 +141,21 @@ func TestSection_GlyphTheme(t *testing.T) {
t.Fatalf("expected glyph theme to avoid unicode dashes, got %q", out) t.Fatalf("expected glyph theme to avoid unicode dashes, got %q", out)
} }
} }
func TestScanln_UsesOverrideStdin(t *testing.T) {
SetStdin(strings.NewReader("hello\n"))
defer SetStdin(nil)
var got string
n, err := Scanln(&got)
if err != nil {
t.Fatalf("Scanln returned error: %v", err)
}
if n != 1 {
t.Fatalf("expected 1 scanned item, got %d", n)
}
if got != "hello" {
t.Fatalf("expected %q, got %q", "hello", got)
}
}