You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems we might have redundant handling of the "Are we in a terminal?" and "is output being redirected?"
ctxutil.IsTerminal relies on https://github.com/mattn/go-isatty in order to tell if we are in a terminal or not, which is great because it is very cross-platform, even supporting Plan9 and Windows.
I recently added in #2019 a method called OutputIsRedirected in our out package, which is meant to say if we are being redirected or not:
It is not clear to me if this is equivalent to saying whether or not we are in a terminal, but it's pretty clear it probably isn't very cross-platform as is.
If "not being a tty" is including "being redirected", then we might want to change this new function to rely on go-isatty/ctxutil.IsTerminal(ctx) instead...
I just confirmed using the following example code from isatty:
package main
import (
"fmt"
"github.com/mattn/go-isatty"
"os"
)
func main() {
if isatty.IsTerminal(os.Stdout.Fd()) {
fmt.Println("Is Terminal")
} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
fmt.Println("Is Cygwin/MSYS2 Terminal")
} else {
fmt.Println("Is Not Terminal")
}
}
That both piping and redirecting output returns "not a terminal", we can therefore replace the non-cross platform code for out.OutputIsRedirected with the cross platform ctxutil.IsTerminal function.
It seems we might have redundant handling of the "Are we in a terminal?" and "is output being redirected?"
ctxutil.IsTerminal
relies on https://github.com/mattn/go-isatty in order to tell if we are in a terminal or not, which is great because it is very cross-platform, even supporting Plan9 and Windows.I recently added in #2019 a method called
OutputIsRedirected
in ourout
package, which is meant to say if we are being redirected or not:gopass/internal/out/print.go
Lines 30 to 34 in b490c57
It is not clear to me if this is equivalent to saying whether or not we are in a terminal, but it's pretty clear it probably isn't very cross-platform as is.
If "not being a tty" is including "being redirected", then we might want to change this new function to rely on go-isatty/
ctxutil.IsTerminal(ctx)
instead...Originally posted by in #2024 (comment)
The text was updated successfully, but these errors were encountered: