From 5d8894781722b4ff56aa87f0ec03d2fc95e8c1a9 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sun, 26 Jun 2022 16:44:42 -0400 Subject: [PATCH 1/2] Update to latest gowid For new tty argument to NewApp(). --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 776dfde..0f195e8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/blang/semver v3.5.1+incompatible github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/gcla/deep v1.0.2 - github.com/gcla/gowid v1.3.1-0.20220603022106-4d04cba8013a + github.com/gcla/gowid v1.3.1-0.20220626203558-a594805196f2 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 diff --git a/go.sum b/go.sum index 7d55759..3ac920c 100644 --- a/go.sum +++ b/go.sum @@ -61,6 +61,8 @@ github.com/gcla/gowid v1.3.1-0.20220530181752-072f0882aae0 h1:myaHMntGEyzp1nWI8Q github.com/gcla/gowid v1.3.1-0.20220530181752-072f0882aae0/go.mod h1:7T4Xzfznq31XvQyAOX+SZzQjvF7RX16mjXDXGB7R/44= github.com/gcla/gowid v1.3.1-0.20220603022106-4d04cba8013a h1:8kh1ORv/P5ruPPoZBMrXAxw406+o9Uvg4fPblsMfcUo= github.com/gcla/gowid v1.3.1-0.20220603022106-4d04cba8013a/go.mod h1:7T4Xzfznq31XvQyAOX+SZzQjvF7RX16mjXDXGB7R/44= +github.com/gcla/gowid v1.3.1-0.20220626203558-a594805196f2 h1:lTVa5VHxePP+1aMijXK0+McQdHL6RFFciSFp6VZ+oEk= +github.com/gcla/gowid v1.3.1-0.20220626203558-a594805196f2/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-20220601234708-3e6af2ebff27 h1:OmzD2vZl1UeSblMmUo4mKjnrtsn+VLxhkkqnDOPHrXY= From 2fddcc45099856c5d6cf5b683b42e620f33a7794 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sun, 26 Jun 2022 16:42:35 -0400 Subject: [PATCH 2/2] Reduce use of legacy GOWID_TTY variable This variable was useful before tcell had the ability to construct a screen with a given tty. I used a fork of tcell that used this variable internally, and didn't modify any of the tcell APIs. Now tcell/v2 allows a tty to be specified; termshark now passed through its preferred tty to gowid, which will use tcell/v2's capability to adopt a tty. --- cmd/termshark/termshark.go | 7 +++---- tty/tty.go | 9 +-------- ui/ui.go | 3 ++- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 661a6a5..18b6300 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -307,7 +307,6 @@ func cmain() int { // using the gcla fork of tcell for another application). usetty = "/dev/tty" } - os.Setenv("GOWID_TTY", usetty) // Allow the user to override the shell's TERM variable this way. Perhaps the user runs // under screen/tmux, and the TERM variable doesn't reflect the fact their preferred @@ -837,7 +836,7 @@ func cmain() int { } }() - if app, err = ui.Build(); err != nil { + if app, err = ui.Build(usetty); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) // Tcell returns ExitError now because if its internal terminfo DB does not have // a matching entry, it tries to build one with infocmp. @@ -1184,7 +1183,7 @@ Loop: appRunner.Start() // Reinstate our terminal overrides that allow ctrl-z - if err := ctrlzLineDisc.Set(); err != nil { + if err := ctrlzLineDisc.Set(usetty); err != nil { ui.OpenError(fmt.Sprintf("Unexpected error setting Ctrl-z handler: %v\n", err), app) } @@ -1282,7 +1281,7 @@ Loop: appRunner.Start() // Reinstate our terminal overrides that allow ctrl-z - if err := ctrlzLineDisc.Set(); err != nil { + if err := ctrlzLineDisc.Set(usetty); err != nil { ui.OpenError(fmt.Sprintf("Unexpected error setting Ctrl-z handler: %v\n", err), app) } diff --git a/tty/tty.go b/tty/tty.go index ccb75dd..58ddd8e 100644 --- a/tty/tty.go +++ b/tty/tty.go @@ -37,18 +37,11 @@ func (t *TerminalSignals) Restore() { t.set = false } -func (t *TerminalSignals) Set() error { +func (t *TerminalSignals) Set(outtty string) error { var e error var newtios unix.Termios var fd uintptr - outtty := "/dev/tty" - - gwtty := os.Getenv("GOWID_TTY") - if gwtty != "" { - outtty = gwtty - } - if t.out, e = os.OpenFile(outtty, os.O_WRONLY, 0); e != nil { goto failed } diff --git a/ui/ui.go b/ui/ui.go index 187a01a..9cf185d 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -3215,7 +3215,7 @@ func (w *prefixKeyWidget) UserInput(ev interface{}, size gowid.IRenderSize, focu //====================================================================== -func Build() (*gowid.App, error) { +func Build(tty string) (*gowid.App, error) { var err error var app *gowid.App @@ -4260,6 +4260,7 @@ func Build() (*gowid.App, error) { Log: log.StandardLogger(), EnableBracketedPaste: true, DontActivate: true, + Tty: tty, }) if err != nil {