summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-05-15 00:15:29 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-05-15 00:15:29 +0900
commitc4cc7891b48067d69510e3356c71cecbe6cd4c5b (patch)
tree60228b75792fe93ea3276ff963e02a207734b3a5 /src/tui
parent218843b9f1466e179555fca668c93c7e81e88a71 (diff)
Revert "Close handles to /dev/tty", instead reuse handles
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/light_unix.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go
index f153978e..e59c72ea 100644
--- a/src/tui/light_unix.go
+++ b/src/tui/light_unix.go
@@ -14,7 +14,11 @@ import (
"golang.org/x/term"
)
-var tty string
+var (
+ tty string
+ ttyin *os.File
+ ttyout *os.File
+)
func IsLightRendererSupported() bool {
return true
@@ -47,8 +51,7 @@ func (r *LightRenderer) initPlatform() error {
}
func (r *LightRenderer) closePlatform() {
- r.ttyin.Close()
- r.ttyout.Close()
+ // NOOP
}
func openTty(mode int) (*os.File, error) {
@@ -68,11 +71,25 @@ func openTty(mode int) (*os.File, error) {
}
func openTtyIn() (*os.File, error) {
- return openTty(syscall.O_RDONLY)
+ if ttyin != nil {
+ return ttyin, nil
+ }
+ in, err := openTty(syscall.O_RDONLY)
+ if err == nil {
+ ttyin = in
+ }
+ return in, err
}
func openTtyOut() (*os.File, error) {
- return openTty(syscall.O_WRONLY)
+ if ttyout != nil {
+ return ttyout, nil
+ }
+ out, err := openTty(syscall.O_WRONLY)
+ if err == nil {
+ ttyout = out
+ }
+ return out, err
}
func (r *LightRenderer) setupTerminal() {