Skip to content

Commit

Permalink
Use IsTerminal instead of OutputIsRedirected (gopasspw#2248)
Browse files Browse the repository at this point in the history
* Use IsTermninal instead of OutputIsRedirected

RELEASE_NOTES=[CLEANUP] Deprecate OutputIsRedirected in favour of IsTerminal

Fixes gopasspw#2025

Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>

* Fix lint

Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
  • Loading branch information
AnomalRoil authored May 31, 2022
1 parent f92971c commit d00a8e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/action/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bo
ctx, cancel := context.WithCancel(ctx)
defer cancel()

skip := ctxutil.IsHidden(ctx) || pw || qrf != "" || out.OutputIsRedirected() || !ctxutil.IsInteractive(ctx) || clip
skip := ctxutil.IsHidden(ctx) || pw || qrf != "" || !ctxutil.IsTerminal(ctx) || !ctxutil.IsInteractive(ctx) || clip
if !skip {
// let us monitor key presses for cancellation:.
go waitForKeyPress(ctx, cancel)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bo
}

// check if we are in "password only" or in "qr code" mode or being redirected to a pipe.
if pw || qrf != "" || out.OutputIsRedirected() {
if pw || qrf != "" || !ctxutil.IsTerminal(ctx) {
out.Printf(ctx, "%s", token)
cancel()
} else { // if not then we want to print a progress bar with the expiry time.
Expand Down
7 changes: 0 additions & 7 deletions internal/out/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ func (s Secret) SafeStr() string {
return "(elided)"
}

// OutputIsRedirected returns true if the current os.Stdout is a pipe instead of a terminal.
func OutputIsRedirected() bool {
o, _ := os.Stdout.Stat()

return (o.Mode() & os.ModeCharDevice) != os.ModeCharDevice
}

func newline(ctx context.Context) string {
if HasNewline(ctx) {
return "\n"
Expand Down

0 comments on commit d00a8e1

Please sign in to comment.