From 1ef877dcc7cf967e143496a7c08d237f552cc065 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Wed, 1 Jun 2022 19:51:39 -0400 Subject: [PATCH] Try harder to make it possible to go install termshark This detail of Go's replace directive means that I cannot go install termshark: - No module is considered the "main" module. If the module containing packages named on the command line has a go.mod file, it must not contain directives (replace and exclude) that would cause it to be interpreted differently than if it were the main module. The module must not require a higher version of itself. https://pkg.go.dev/cmd/go#hdr-The_go_mod_file Termshark's go.mod has a replace directive for pkg/term to a fork I posted, gcla/term, with some stub functions needed to compile on openbsd (they aren't called by termshark, but the compiler needs them). These changes wouldn't be suitable for upstream, since they don't add the needed functionality - so I haven't tried to get them merged. But the presence of this replace directive means I cannot now go install termshark directly, which is not ideal. I'd like it to be as easy as possible for users to grab termshark and compile it. I don't like the idea of hosting gcla/term because it implies an authorship that isn't true - none of pkg/term is mine. But I'm not sure if there is a better solution that lets me remove the replace directive. --- go.mod | 7 ++----- go.sum | 10 +++------- tty/tty.go | 13 +++++++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 9d80f825..eaab3dc2 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/gcla/deep v1.0.2 github.com/gcla/gowid v1.3.1-0.20220530181752-072f0882aae0 github.com/gcla/tail v1.0.1-0.20190505190527-650e90873359 + github.com/gcla/term v0.0.0-20220601234708-3e6af2ebff27 github.com/gdamore/tcell/v2 v2.5.0 github.com/gin-gonic/gin v1.7.0 // indirect github.com/go-test/deep v1.0.2 // indirect @@ -24,7 +25,6 @@ require ( github.com/mreiferson/go-snappystream v0.2.3 github.com/pelletier/go-toml v1.8.1 // indirect github.com/pkg/errors v0.9.1 - github.com/pkg/term v1.1.0 github.com/psanford/wormhole-william v1.0.6-0.20210402190004-049df45b8d5a github.com/rakyll/statik v0.1.7 github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0 @@ -36,14 +36,11 @@ require ( github.com/stretchr/testify v1.7.0 github.com/tevino/abool v1.2.0 golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect + golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 gopkg.in/fsnotify/fsnotify.v1 v1.4.7 gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) -replace github.com/pkg/term => github.com/gcla/term v0.0.0-20191015020247-31cba2f9f402 - //replace github.com/gcla/gowid => /home/gcla/go/src/github.com/gcla/gowid - -//replace github.com/gdamore/tcell/v2 => /home/gcla/source/tcell diff --git a/go.sum b/go.sum index 3d39b5f8..ac1ac89c 100644 --- a/go.sum +++ b/go.sum @@ -57,14 +57,12 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gcla/deep v1.0.2 h1:qBOx6eepcOSRYnHJ+f2ih4hP4Vca1YnLtXxp73n5KWI= github.com/gcla/deep v1.0.2/go.mod h1:evE9pbpSGhItmFoBIk8hPOIC/keKTGYhFl6Le1Av+GE= -github.com/gcla/gowid v1.3.1-0.20220427034012-f8f1f91caee4 h1:SBgNi1aZzqhP+KlSAu8ppxYIr68XLN/mC7I1XSUFuHE= -github.com/gcla/gowid v1.3.1-0.20220427034012-f8f1f91caee4/go.mod h1:7T4Xzfznq31XvQyAOX+SZzQjvF7RX16mjXDXGB7R/44= github.com/gcla/gowid v1.3.1-0.20220530181752-072f0882aae0 h1:myaHMntGEyzp1nWI8QL6596lwKKxclaPOS9D1XlvOGI= github.com/gcla/gowid v1.3.1-0.20220530181752-072f0882aae0/go.mod h1:7T4Xzfznq31XvQyAOX+SZzQjvF7RX16mjXDXGB7R/44= github.com/gcla/tail v1.0.1-0.20190505190527-650e90873359 h1:3xEhacR7pIJV8daurdBygptxhzTJeYFqJp1V6SDl+pE= github.com/gcla/tail v1.0.1-0.20190505190527-650e90873359/go.mod h1:Wn+pZpM98JHSOYkPDtmdvlqmc0OzQGHWOsHB2d28WtQ= -github.com/gcla/term v0.0.0-20191015020247-31cba2f9f402 h1:d8cpYNgYjXDjvrdnSaFy4+o1D3BpPUKTBIcijrBKv4c= -github.com/gcla/term v0.0.0-20191015020247-31cba2f9f402/go.mod h1:YCPU+G35BFc/575HWMl8oeqq+dTbunufWbWaV0Y2sqY= +github.com/gcla/term v0.0.0-20220601234708-3e6af2ebff27 h1:OmzD2vZl1UeSblMmUo4mKjnrtsn+VLxhkkqnDOPHrXY= +github.com/gcla/term v0.0.0-20220601234708-3e6af2ebff27/go.mod h1:clvpNvF78b5j4SoZwUykoKNbZwjlDmFeHGbKeixkScI= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.5.0 h1:/LA5f/wqTP5mWT79czngibKVVx5wOgdFTIXPQ68fMO8= @@ -72,7 +70,6 @@ github.com/gdamore/tcell/v2 v2.5.0/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tv github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU= github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= @@ -86,7 +83,6 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= @@ -381,10 +377,10 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/tty/tty.go b/tty/tty.go index 7263216a..5625390f 100644 --- a/tty/tty.go +++ b/tty/tty.go @@ -10,13 +10,14 @@ import ( "os" "syscall" - "github.com/pkg/term/termios" + "github.com/gcla/term/termios" + "golang.org/x/sys/unix" ) //====================================================================== type TerminalSignals struct { - tiosp syscall.Termios + tiosp *unix.Termios out *os.File set bool } @@ -28,7 +29,7 @@ func (t *TerminalSignals) IsSet() bool { func (t *TerminalSignals) Restore() { if t.out != nil { fd := uintptr(t.out.Fd()) - termios.Tcsetattr(fd, termios.TCSANOW, &t.tiosp) + termios.Tcsetattr(fd, termios.TCSANOW, t.tiosp) t.out.Close() t.out = nil @@ -38,7 +39,7 @@ func (t *TerminalSignals) Restore() { func (t *TerminalSignals) Set() error { var e error - var newtios syscall.Termios + var newtios unix.Termios var fd uintptr outtty := "/dev/tty" @@ -54,11 +55,11 @@ func (t *TerminalSignals) Set() error { fd = uintptr(t.out.Fd()) - if e = termios.Tcgetattr(fd, &t.tiosp); e != nil { + if t.tiosp, e = termios.Tcgetattr(fd); e != nil { goto failed } - newtios = t.tiosp + newtios = *t.tiosp newtios.Lflag |= syscall.ISIG // Enable ctrl-z for suspending the foreground process group via the