diff options
Diffstat (limited to 'vendor/github.com/gdamore/tcell')
9 files changed, 272 insertions, 6 deletions
diff --git a/vendor/github.com/gdamore/tcell/v2/README.adoc b/vendor/github.com/gdamore/tcell/v2/README.adoc index 93af9fdcb..b9d650b48 100644 --- a/vendor/github.com/gdamore/tcell/v2/README.adoc +++ b/vendor/github.com/gdamore/tcell/v2/README.adoc @@ -54,6 +54,7 @@ Version 1.x remains available using the import `github.com/gdamore/tcell`. * https://github.com/noborus/ov[ov] - Terminal pager * https://github.com/gcla/tmux-wormhole[tmux-wormhole] - A tmux plugin to transfer files with magic wormhole * https://github.com/anaseto/gruid-tcell[gruid-tcell] - A tcell driver for the grid based UI and game framework gruid. +* https://github.com/aretext/aretext[aretext] - Minimalist text editor with vim key bindings. == Pure Go Terminfo Database diff --git a/vendor/github.com/gdamore/tcell/v2/go.sum b/vendor/github.com/gdamore/tcell/v2/go.sum index 54d4bee63..068fabd98 100644 --- a/vendor/github.com/gdamore/tcell/v2/go.sum +++ b/vendor/github.com/gdamore/tcell/v2/go.sum @@ -6,8 +6,6 @@ github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRR github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= -golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= diff --git a/vendor/github.com/gdamore/tcell/v2/nonblock_bsd.go b/vendor/github.com/gdamore/tcell/v2/nonblock_bsd.go index ffe5caf85..28fd4644c 100644 --- a/vendor/github.com/gdamore/tcell/v2/nonblock_bsd.go +++ b/vendor/github.com/gdamore/tcell/v2/nonblock_bsd.go @@ -26,6 +26,7 @@ import ( // tcSetBufParams is used by the tty driver on UNIX systems to configure the // buffering parameters (minimum character count and minimum wait time in msec.) +// This also waits for output to drain first. func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { _ = syscall.SetNonblock(fd, true) tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA) @@ -34,7 +35,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { } tio.Cc[unix.VMIN] = vMin tio.Cc[unix.VTIME] = vTime - if err = unix.IoctlSetTermios(fd, unix.TIOCSETA, tio); err != nil { + if err = unix.IoctlSetTermios(fd, unix.TIOCSETAW, tio); err != nil { return err } return nil diff --git a/vendor/github.com/gdamore/tcell/v2/nonblock_unix.go b/vendor/github.com/gdamore/tcell/v2/nonblock_unix.go index 768128d7a..fe31844cf 100644 --- a/vendor/github.com/gdamore/tcell/v2/nonblock_unix.go +++ b/vendor/github.com/gdamore/tcell/v2/nonblock_unix.go @@ -24,6 +24,7 @@ import ( // tcSetBufParams is used by the tty driver on UNIX systems to configure the // buffering parameters (minimum character count and minimum wait time in msec.) +// This also waits for output to drain first. func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { _ = syscall.SetNonblock(fd, true) tio, err := unix.IoctlGetTermios(fd, unix.TCGETS) @@ -32,7 +33,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { } tio.Cc[unix.VMIN] = vMin tio.Cc[unix.VTIME] = vTime - if err = unix.IoctlSetTermios(fd, unix.TCSETS, tio); err != nil { + if err = unix.IoctlSetTermios(fd, unix.TCSETSW, tio); err != nil { return err } return nil diff --git a/vendor/github.com/gdamore/tcell/v2/stdin_unix.go b/vendor/github.com/gdamore/tcell/v2/stdin_unix.go new file mode 100644 index 000000000..e3d32e9fd --- /dev/null +++ b/vendor/github.com/gdamore/tcell/v2/stdin_unix.go @@ -0,0 +1,177 @@ +// Copyright 2021 The TCell Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use file except in compliance with the License. +// You may obtain a copy of the license at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos + +package tcell + +import ( + "errors" + "fmt" + "os" + "os/signal" + "strconv" + "sync" + "syscall" + "time" + + "golang.org/x/term" +) + +// stdIoTty is an implementation of the Tty API based upon stdin/stdout. +type stdIoTty struct { + fd int + in *os.File + out *os.File + saved *term.State + sig chan os.Signal + cb func() + stopQ chan struct{} + dev string + wg sync.WaitGroup + l sync.Mutex +} + +func (tty *stdIoTty) Read(b []byte) (int, error) { + return tty.in.Read(b) +} + +func (tty *stdIoTty) Write(b []byte) (int, error) { + return tty.out.Write(b) +} + +func (tty *stdIoTty) Close() error { + return nil +} + +func (tty *stdIoTty) Start() error { + tty.l.Lock() + defer tty.l.Unlock() + + // We open another copy of /dev/tty. This is a workaround for unusual behavior + // observed in macOS, apparently caused when a subshell (for example) closes our + // own tty device (when it exits for example). Getting a fresh new one seems to + // resolve the problem. (We believe this is a bug in the macOS tty driver that + // fails to account for dup() references to the same file before applying close() + // related behaviors to the tty.) We're also holding the original copy we opened + // since closing that might have deleterious effects as well. The upshot is that + // we will have up to two separate file handles open on /dev/tty. (Note that when + // using stdin/stdout instead of /dev/tty this problem is not observed.) + var err error + tty.in = os.Stdin + tty.out = os.Stdout + tty.fd = int(tty.in.Fd()) + + if !term.IsTerminal(tty.fd) { + return errors.New("device is not a terminal") + } + + _ = tty.in.SetReadDeadline(time.Time{}) + saved, err := term.MakeRaw(tty.fd) // also sets vMin and vTime + if err != nil { + return err + } + tty.saved = saved + + tty.stopQ = make(chan struct{}) + tty.wg.Add(1) + go func(stopQ chan struct{}) { + defer tty.wg.Done() + for { + select { + case <-tty.sig: + tty.l.Lock() + cb := tty.cb + tty.l.Unlock() + if cb != nil { + cb() + } + case <-stopQ: + return + } + } + }(tty.stopQ) + + signal.Notify(tty.sig, syscall.SIGWINCH) + return nil +} + +func (tty *stdIoTty) Drain() error { + _ = tty.in.SetReadDeadline(time.Now()) + if err := tcSetBufParams(tty.fd, 0, 0); err != nil { + return err + } + return nil +} + +func (tty *stdIoTty) Stop() error { + tty.l.Lock() + if err := term.Restore(tty.fd, tty.saved); err != nil { + tty.l.Unlock() + return err + } + _ = tty.in.SetReadDeadline(time.Now()) + + signal.Stop(tty.sig) + close(tty.stopQ) + tty.l.Unlock() + + tty.wg.Wait() + + return nil +} + +func (tty *stdIoTty) WindowSize() (int, int, error) { + w, h, err := term.GetSize(tty.fd) + if err != nil { + return 0, 0, err + } + if w == 0 { + w, _ = strconv.Atoi(os.Getenv("COLUMNS")) + } + if w == 0 { + w = 80 // default + } + if h == 0 { + h, _ = strconv.Atoi(os.Getenv("LINES")) + } + if h == 0 { + h = 25 // default + } + return w, h, nil +} + +func (tty *stdIoTty) NotifyResize(cb func()) { + tty.l.Lock() + tty.cb = cb + tty.l.Unlock() +} + +// NewStdioTty opens a tty using standard input/output. +func NewStdIoTty() (Tty, error) { + tty := &stdIoTty{ + sig: make(chan os.Signal), + in: os.Stdin, + out: os.Stdout, + } + var err error + tty.fd = int(tty.in.Fd()) + if !term.IsTerminal(tty.fd) { + return nil, errors.New("not a terminal") + } + if tty.saved, err = term.GetState(tty.fd); err != nil { + return nil, fmt.Errorf("failed to get state: %w", err) + } + return tty, nil +} diff --git a/vendor/github.com/gdamore/tcell/v2/terminfo/extended/extended.go b/vendor/github.com/gdamore/tcell/v2/terminfo/extended/extended.go index 14e6bf10a..c69bef13d 100644 --- a/vendor/github.com/gdamore/tcell/v2/terminfo/extended/extended.go +++ b/vendor/github.com/gdamore/tcell/v2/terminfo/extended/extended.go @@ -28,6 +28,7 @@ import ( _ "github.com/gdamore/tcell/v2/terminfo/c/cygwin" _ "github.com/gdamore/tcell/v2/terminfo/d/dtterm" _ "github.com/gdamore/tcell/v2/terminfo/e/emacs" + _ "github.com/gdamore/tcell/v2/terminfo/f/foot" _ "github.com/gdamore/tcell/v2/terminfo/g/gnome" _ "github.com/gdamore/tcell/v2/terminfo/h/hpterm" _ "github.com/gdamore/tcell/v2/terminfo/k/konsole" diff --git a/vendor/github.com/gdamore/tcell/v2/terminfo/f/foot/foot.go b/vendor/github.com/gdamore/tcell/v2/terminfo/f/foot/foot.go new file mode 100644 index 000000000..fb734cbdc --- /dev/null +++ b/vendor/github.com/gdamore/tcell/v2/terminfo/f/foot/foot.go @@ -0,0 +1,69 @@ +// Generated automatically. DO NOT HAND-EDIT. + +package foot + +import "github.com/gdamore/tcell/v2/terminfo" + +func init() { + + // foot terminal emulator + terminfo.AddTerminfo(&terminfo.Terminfo{ + Name: "foot", + Columns: 80, + Lines: 24, + Colors: 256, + Bell: "\a", + Clear: "\x1b[H\x1b[2J", + EnterCA: "\x1b[?1049h\x1b[22;0;0t", + ExitCA: "\x1b[?1049l\x1b[23;0;0t", + ShowCursor: "\x1b[?12l\x1b[?25h", + HideCursor: "\x1b[?25l", + AttrOff: "\x1b(B\x1b[m", + Underline: "\x1b[4m", + Bold: "\x1b[1m", + Dim: "\x1b[2m", + Italic: "\x1b[3m", + Blink: "\x1b[5m", + Reverse: "\x1b[7m", + EnterKeypad: "\x1b[?1h\x1b=", + ExitKeypad: "\x1b[?1l\x1b>", + SetFg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38:5:%p1%d%;m", + SetBg: "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48:5:%p1%d%;m", + SetFgBg: "\x1b[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38:5:%p1%d%;;%?%p2%{8}%<%t4%p2%d%e%p2%{16}%<%t10%p2%{8}%-%d%e48:5:%p2%d%;m", + ResetFgBg: "\x1b[39;49m", + AltChars: "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~", + EnterAcs: "\x1b(0", + ExitAcs: "\x1b(B", + StrikeThrough: "\x1b[9m", + Mouse: "\x1b[M", + SetCursor: "\x1b[%i%p1%d;%p2%dH", + CursorBack1: "\b", + CursorUp1: "\x1b[A", + KeyUp: "\x1bOA", + KeyDown: "\x1bOB", + KeyRight: "\x1bOC", + KeyLeft: "\x1bOD", + KeyInsert: "\x1b[2~", + KeyDelete: "\x1b[3~", + KeyBackspace: "\u007f", + KeyHome: "\x1bOH", + KeyEnd: "\x1bOF", + KeyPgUp: "\x1b[5~", + KeyPgDn: "\x1b[6~", + KeyF1: "\x1bOP", + KeyF2: "\x1bOQ", + KeyF3: "\x1bOR", + KeyF4: "\x1bOS", + KeyF5: "\x1b[15~", + KeyF6: "\x1b[17~", + KeyF7: "\x1b[18~", + KeyF8: "\x1b[19~", + KeyF9: "\x1b[20~", + KeyF10: "\x1b[21~", + KeyF11: "\x1b[23~", + KeyF12: "\x1b[24~", + KeyBacktab: "\x1b[Z", + Modifiers: 1, + AutoMargin: true, + }) +} diff --git a/vendor/github.com/gdamore/tcell/v2/tscreen.go b/vendor/github.com/gdamore/tcell/v2/tscreen.go index de2338cc9..49aacf14c 100644 --- a/vendor/github.com/gdamore/tcell/v2/tscreen.go +++ b/vendor/github.com/gdamore/tcell/v2/tscreen.go @@ -1682,6 +1682,7 @@ func (t *tScreen) disengage() { ti := t.ti t.cells.Resize(0, 0) t.TPuts(ti.ShowCursor) + t.TPuts(ti.ResetFgBg) t.TPuts(ti.AttrOff) t.TPuts(ti.Clear) t.TPuts(ti.ExitCA) diff --git a/vendor/github.com/gdamore/tcell/v2/tty_unix.go b/vendor/github.com/gdamore/tcell/v2/tty_unix.go index a48b2e6da..0c6ea7849 100644 --- a/vendor/github.com/gdamore/tcell/v2/tty_unix.go +++ b/vendor/github.com/gdamore/tcell/v2/tty_unix.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "os/signal" + "strconv" "sync" "syscall" "time" @@ -51,7 +52,7 @@ func (tty *devTty) Write(b []byte) (int, error) { } func (tty *devTty) Close() error { - return nil + return tty.f.Close() } func (tty *devTty) Start() error { @@ -136,7 +137,23 @@ func (tty *devTty) Stop() error { } func (tty *devTty) WindowSize() (int, int, error) { - return term.GetSize(tty.fd) + w, h, err := term.GetSize(tty.fd) + if err != nil { + return 0, 0, err + } + if w == 0 { + w, _ = strconv.Atoi(os.Getenv("COLUMNS")) + } + if w == 0 { + w = 80 // default + } + if h == 0 { + h, _ = strconv.Atoi(os.Getenv("LINES")) + } + if h == 0 { + h = 25 // default + } + return w, h, nil } func (tty *devTty) NotifyResize(cb func()) { |