summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortheimpostor <sahirhoda@gmail.com>2024-08-25 11:47:02 -0500
committertheimpostor <sahirhoda@gmail.com>2024-08-25 11:47:02 -0500
commitd25625eca21453f67c89b0cf2d3fdeb7968d62ce (patch)
tree7c9b2c96ac2f687ba0fb9462326f740818f8f7f1
parent9c05a6d0210bf1751b274c733a3c4393b78c01db (diff)
use /dev/tty with screen always
-rw-r--r--main.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/main.go b/main.go
index 4980b0c..b051aa2 100644
--- a/main.go
+++ b/main.go
@@ -53,7 +53,9 @@ func encode(fname string, encoder io.WriteCloser) {
}
func opentty() (tty tcell.Tty, err error) {
- tty, err = tcell.NewDevTtyFromDev(deviceFlag)
+ device := ttyDevice()
+ debugLog.Println("Using tty device:", device)
+ tty, err = tcell.NewDevTtyFromDev(device)
if err == nil {
err = tty.Start()
}
@@ -395,18 +397,22 @@ var rootCmd = &cobra.Command{
Long: `Reads or writes the system clipboard using the ANSI OSC52 escape sequence.`,
}
-func defaultDevice() string {
- sshtty := os.Getenv("SSH_TTY")
- if sshtty != "" {
+func ttyDevice() string {
+ if deviceFlag != "" {
+ return deviceFlag
+ } else if isScreen {
+ return "/dev/tty"
+ } else if sshtty := os.Getenv("SSH_TTY"); sshtty != "" {
return sshtty
+ } else {
+ return "/dev/tty"
}
- return "/dev/tty"
}
func init() {
rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "verbose logging")
rootCmd.PersistentFlags().StringVarP(&logfileFlag, "log", "l", "", "write logs to file")
- rootCmd.PersistentFlags().StringVarP(&deviceFlag, "device", "d", defaultDevice(), "select device")
+ rootCmd.PersistentFlags().StringVarP(&deviceFlag, "device", "d", "", "use specific tty device")
rootCmd.PersistentFlags().Float64VarP(&timeoutFlag, "timeout", "t", 5, "tty read timeout in seconds")
rootCmd.AddCommand(copyCmd)