Drop another dependency

This commit is contained in:
Kovid Goyal 2022-08-22 21:30:00 +05:30
parent cf287015de
commit eb4ee13f73
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 9 additions and 7 deletions

1
go.mod
View File

@ -3,7 +3,6 @@ module kitty
go 1.19 go 1.19
require ( require (
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-runewidth v0.0.13 github.com/mattn/go-runewidth v0.0.13
github.com/seancfoley/ipaddress-go v1.2.1 github.com/seancfoley/ipaddress-go v1.2.1
github.com/spf13/cobra v1.5.0 github.com/spf13/cobra v1.5.0

2
go.sum
View File

@ -1,8 +1,6 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 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 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=

View File

@ -10,13 +10,13 @@ import (
"strings" "strings"
"unicode" "unicode"
"github.com/mattn/go-isatty"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"kitty" "kitty"
"kitty/tools/tty"
"kitty/tools/utils" "kitty/tools/utils"
) )
@ -488,7 +488,7 @@ func Init(root *cobra.Command) {
if kitty.VCSRevision != "" { if kitty.VCSRevision != "" {
vs = vs + " (" + kitty.VCSRevision + ")" vs = vs + " (" + kitty.VCSRevision + ")"
} }
stdout_is_terminal = isatty.IsTerminal(os.Stdout.Fd()) stdout_is_terminal = tty.IsTerminal(os.Stdout.Fd())
RootCmd = root RootCmd = root
root.Version = vs root.Version = vs
root.SetUsageFunc(func(cmd *cobra.Command) error { return show_usage(cmd, false) }) root.SetUsageFunc(func(cmd *cobra.Command) error { return show_usage(cmd, false) })

View File

@ -9,7 +9,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/mattn/go-isatty"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"golang.org/x/sys/unix" "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 ans == "" && password_file != "" {
if 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())) q, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil { if err != nil {
ans = string(q) ans = string(q)

View File

@ -19,6 +19,12 @@ const (
TCSAFLUSH = 2 TCSAFLUSH = 2
) )
func IsTerminal(fd uintptr) bool {
var t unix.Termios
err := Tcgetattr(int(fd), &t)
return err == nil
}
type Term struct { type Term struct {
name string name string
fd int fd int