From eb4ee13f73329b9165627aac4f4ed789c78a387a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Aug 2022 21:30:00 +0530 Subject: [PATCH] Drop another dependency --- go.mod | 1 - go.sum | 2 -- tools/cli/infrastructure.go | 4 ++-- tools/cmd/at/main.go | 3 +-- tools/tty/tty.go | 6 ++++++ 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 4532d18ff..a12ada7c8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module kitty go 1.19 require ( - github.com/mattn/go-isatty v0.0.14 github.com/mattn/go-runewidth v0.0.13 github.com/seancfoley/ipaddress-go v1.2.1 github.com/spf13/cobra v1.5.0 diff --git a/go.sum b/go.sum index fe10686b8..5eb1ff929 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= diff --git a/tools/cli/infrastructure.go b/tools/cli/infrastructure.go index 13102ed21..ec76d4bd5 100644 --- a/tools/cli/infrastructure.go +++ b/tools/cli/infrastructure.go @@ -10,13 +10,13 @@ import ( "strings" "unicode" - "github.com/mattn/go-isatty" "github.com/mattn/go-runewidth" "github.com/spf13/cobra" "github.com/spf13/pflag" "golang.org/x/sys/unix" "kitty" + "kitty/tools/tty" "kitty/tools/utils" ) @@ -488,7 +488,7 @@ func Init(root *cobra.Command) { if kitty.VCSRevision != "" { vs = vs + " (" + kitty.VCSRevision + ")" } - stdout_is_terminal = isatty.IsTerminal(os.Stdout.Fd()) + stdout_is_terminal = tty.IsTerminal(os.Stdout.Fd()) RootCmd = root root.Version = vs root.SetUsageFunc(func(cmd *cobra.Command) error { return show_usage(cmd, false) }) diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index 66efc1db7..efb5c23f0 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/mattn/go-isatty" "github.com/spf13/cobra" "github.com/spf13/pflag" "golang.org/x/sys/unix" @@ -254,7 +253,7 @@ func get_password(password string, password_file string, password_env string, us } if ans == "" && password_file != "" { if password_file == "-" { - if isatty.IsTerminal(os.Stdin.Fd()) { + if tty.IsTerminal(os.Stdin.Fd()) { q, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { ans = string(q) diff --git a/tools/tty/tty.go b/tools/tty/tty.go index 959a01a04..4221c2112 100644 --- a/tools/tty/tty.go +++ b/tools/tty/tty.go @@ -19,6 +19,12 @@ const ( TCSAFLUSH = 2 ) +func IsTerminal(fd uintptr) bool { + var t unix.Termios + err := Tcgetattr(int(fd), &t) + return err == nil +} + type Term struct { name string fd int