Remove pkg/term dependency

This commit is contained in:
Christian Rocha 2020-10-13 12:52:30 -04:00
parent 9c9a92c349
commit 4d14af713f
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
5 changed files with 30 additions and 57 deletions

1
go.mod
View File

@ -4,7 +4,6 @@ go 1.13
require ( require (
github.com/muesli/termenv v0.7.2 github.com/muesli/termenv v0.7.2
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634
) )

4
go.sum
View File

@ -8,11 +8,7 @@ github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/Qd
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/muesli/termenv v0.7.2 h1:r1raklL3uKE7rOvWgSenmEm2px+dnc33OTisZ8YR1fw= github.com/muesli/termenv v0.7.2 h1:r1raklL3uKE7rOvWgSenmEm2px+dnc33OTisZ8YR1fw=
github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8= github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8=
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU=
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI=
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

27
tty.go Normal file
View File

@ -0,0 +1,27 @@
package tea
import (
"os"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh/terminal"
)
var origTTYState *terminal.State
func initTerminal() error {
var err error
origTTYState, err = terminal.MakeRaw(int(os.Stdin.Fd())) // enter raw mode
if err != nil {
return err
}
enableAnsiColors()
termenv.HideCursor()
return nil
}
func restoreTerminal() error {
termenv.ShowCursor()
return terminal.Restore(int(os.Stdin.Fd()), origTTYState) // exit raw mode
}

View File

@ -2,32 +2,6 @@
package tea package tea
import ( // enableAnsiColors is only needed for Windows, so for other systems this is
"github.com/muesli/termenv" // a no-op.
"github.com/pkg/term" func enableAnsiColors() {}
)
var (
tty *term.Term
)
func initTerminal() error {
var err error
tty, err = term.Open("/dev/tty")
if err != nil {
return err
}
err = tty.SetRaw()
if err != nil {
return err
}
termenv.HideCursor()
return nil
}
func restoreTerminal() {
termenv.ShowCursor()
_ = tty.Restore()
}

View File

@ -5,15 +5,9 @@ package tea
import ( import (
"os" "os"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
var (
origTTYState *terminal.State
)
// enableAnsiColors enables support for ANSI color sequences in Windows // enableAnsiColors enables support for ANSI color sequences in Windows
// default console. Note that this only works with Windows 10. // default console. Note that this only works with Windows 10.
func enableAnsiColors() { func enableAnsiColors() {
@ -23,20 +17,3 @@ func enableAnsiColors() {
windows.GetConsoleMode(stdout, &originalMode) windows.GetConsoleMode(stdout, &originalMode)
windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
} }
func initTerminal() error {
var err error
origTTYState, err = terminal.MakeRaw(int(os.Stdin.Fd())) // enter raw mode
if err != nil {
return err
}
enableAnsiColors()
termenv.HideCursor()
return nil
}
func restoreTerminal() {
_ = terminal.Restore(int(os.Stdin.Fd()), origTTYState) // exit raw mode
termenv.ShowCursor()
}