summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go21
-rw-r--r--tty_notwindows.go18
-rw-r--r--tty_windows.go64
3 files changed, 90 insertions, 13 deletions
diff --git a/main.go b/main.go
index 5d80e79..f7d11ee 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
+ "runtime"
"strings"
"time"
@@ -52,19 +53,9 @@ func encode(fname string, encoder io.WriteCloser) {
}
}
-func opentty() (tty tcell.Tty, err error) {
- device := ttyDevice()
- debugLog.Println("Using tty device:", device)
- tty, err = tcell.NewDevTtyFromDev(device)
- if err == nil {
- err = tty.Start()
- }
- return
-}
-
func closetty(tty tcell.Tty) {
- tty.Drain()
- tty.Stop()
+ _ = tty.Drain()
+ _ = tty.Stop()
tty.Close()
}
@@ -111,7 +102,11 @@ func identifyTerm() {
if os.Getenv("TMUX") != "" {
isTmux = true
} else if ti, err := tcell.LookupTerminfo(os.Getenv("TERM")); err != nil {
- errorLog.Println("Failed to lookup terminfo:", err)
+ if runtime.GOOS != "windows" {
+ errorLog.Println("Failed to lookup terminfo:", err)
+ } else {
+ debugLog.Println("On Windows, failed to lookup terminfo:", err)
+ }
} else {
debugLog.Printf("term name: %s, aliases: %q", ti.Name, ti.Aliases)
if strings.HasPrefix(ti.Name, "screen") {
diff --git a/tty_notwindows.go b/tty_notwindows.go
new file mode 100644
index 0000000..77d4ef4
--- /dev/null
+++ b/tty_notwindows.go
@@ -0,0 +1,18 @@
+//go:build !windows
+// +build !windows
+
+package main
+
+import (
+ "github.com/gdamore/tcell/v2"
+)
+
+func opentty() (tty tcell.Tty, err error) {
+ device := ttyDevice()
+ debugLog.Println("Using tty device:", device)
+ tty, err = tcell.NewDevTtyFromDev(device)
+ if err == nil {
+ err = tty.Start()
+ }
+ return
+}
diff --git a/tty_windows.go b/tty_windows.go
new file mode 100644
index 0000000..78131e8
--- /dev/null
+++ b/tty_windows.go
@@ -0,0 +1,64 @@
+//go:build windows
+// +build windows
+
+package main
+
+import (
+ "fmt"
+ "github.com/gdamore/tcell/v2"
+ "os"
+)
+
+// stdIoTty is an implementation of the Tty API based upon stdin/stdout.
+type stdIoTty struct {
+ in *os.File
+ out *os.File
+}
+
+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.in = os.Stdin
+ tty.out = os.Stdout
+ return nil
+}
+
+func (tty *stdIoTty) Drain() error {
+ return nil
+}
+
+func (tty *stdIoTty) Stop() error {
+ return nil
+}
+
+func (tty *stdIoTty) WindowSize() (tcell.WindowSize, error) {
+ return tcell.WindowSize{}, fmt.Errorf("not implemented")
+}
+
+func (tty *stdIoTty) NotifyResize(cb func()) {
+}
+
+// NewStdioTty opens a tty using standard input/output.
+func NewStdIoTty() (tcell.Tty, error) {
+ tty := &stdIoTty{
+ in: os.Stdin,
+ out: os.Stdout,
+ }
+ return tty, nil
+}
+
+func opentty() (tty tcell.Tty, err error) {
+ debugLog.Println("Using stdio tty")
+ tty, err = NewStdIoTty()
+ return
+}