From e80fbd00fd1d95ea39fbcc891a9028237abe946b Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 13 Feb 2023 19:55:40 +1100 Subject: [PATCH 1/2] Expose stdin and stdout in term package --- pkg/term/env.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/term/env.go b/pkg/term/env.go index 44b2983..8288dd7 100644 --- a/pkg/term/env.go +++ b/pkg/term/env.go @@ -14,7 +14,9 @@ import ( // Term represents information about the terminal that a process is connected to. type Term struct { + in *os.File out *os.File + err *os.File isTTY bool colorEnabled bool is256enabled bool @@ -61,7 +63,9 @@ func FromEnv() Term { } return Term{ + in: os.Stdin, out: os.Stdout, + err: os.Stderr, isTTY: stdoutIsTTY, colorEnabled: isColorEnabled, is256enabled: isVirtualTerminal || is256ColorSupported(), @@ -71,11 +75,21 @@ func FromEnv() Term { } } +// In is the reader reading from standard input. +func (t Term) In() io.Reader { + return t.in +} + // Out is the writer writing to standard output. func (t Term) Out() io.Writer { return t.out } +// Err is the writer writing to standard error. +func (t Term) Err() io.Writer { + return t.err +} + // IsTerminalOutput returns true if standard output is connected to a terminal. func (t Term) IsTerminalOutput() bool { return t.isTTY From c045f5b431ca4f6c61c0d89b6064a8e3ee9cb0a8 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Sun, 19 Feb 2023 19:26:33 +1100 Subject: [PATCH 2/2] Err to ErrOut --- pkg/term/env.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/term/env.go b/pkg/term/env.go index 8288dd7..a5a7d55 100644 --- a/pkg/term/env.go +++ b/pkg/term/env.go @@ -16,7 +16,7 @@ import ( type Term struct { in *os.File out *os.File - err *os.File + errOut *os.File isTTY bool colorEnabled bool is256enabled bool @@ -65,7 +65,7 @@ func FromEnv() Term { return Term{ in: os.Stdin, out: os.Stdout, - err: os.Stderr, + errOut: os.Stderr, isTTY: stdoutIsTTY, colorEnabled: isColorEnabled, is256enabled: isVirtualTerminal || is256ColorSupported(), @@ -85,9 +85,9 @@ func (t Term) Out() io.Writer { return t.out } -// Err is the writer writing to standard error. -func (t Term) Err() io.Writer { - return t.err +// ErrOut is the writer writing to standard error. +func (t Term) ErrOut() io.Writer { + return t.errOut } // IsTerminalOutput returns true if standard output is connected to a terminal.