Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose stdin and stdout in term package #103

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/term/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down