From 821f7d191de2acf267adf2566bbf5e19bb5ddb03 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 13:18:36 +0000 Subject: [PATCH] fix(cli): respect stdin override in Scanln Co-Authored-By: Virgil --- pkg/cli/output.go | 2 +- pkg/cli/output_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/cli/output.go b/pkg/cli/output.go index e9c58e0..fb246b8 100644 --- a/pkg/cli/output.go +++ b/pkg/cli/output.go @@ -132,7 +132,7 @@ func Label(word, value string) { // Scanln reads from stdin. func Scanln(a ...any) (int, error) { - return fmt.Scanln(a...) + return fmt.Fscanln(newReader(), a...) } // Task prints a task header: "[label] message" diff --git a/pkg/cli/output_test.go b/pkg/cli/output_test.go index 0930285..47d4f5a 100644 --- a/pkg/cli/output_test.go +++ b/pkg/cli/output_test.go @@ -141,3 +141,21 @@ func TestSection_GlyphTheme(t *testing.T) { 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) + } +} -- 2.45.3