diff --git a/termios_bsd.go b/termios_bsd.go new file mode 100644 index 00000000..cc716e58 --- /dev/null +++ b/termios_bsd.go @@ -0,0 +1,13 @@ +//go:build dragonfly || freebsd +// +build dragonfly freebsd + +package tea + +import ( + "github.com/charmbracelet/x/term" + "golang.org/x/sys/unix" +) + +func (p *Program) checkOptimizedMovements(s *term.State) { + p.useHardTabs = s.Oflag&unix.TABDLY == unix.TAB0 +} diff --git a/termios_other.go b/termios_other.go new file mode 100644 index 00000000..d62c012c --- /dev/null +++ b/termios_other.go @@ -0,0 +1,8 @@ +//go:build !darwin && !dragonfly && !freebsd && !linux && !solaris && !aix +// +build !darwin,!dragonfly,!freebsd,!linux,!solaris,!aix + +package tea + +import "github.com/charmbracelet/x/term" + +func (*Program) checkOptimizedMovements(*term.State) {} diff --git a/termios_unix.go b/termios_unix.go new file mode 100644 index 00000000..3ee0e994 --- /dev/null +++ b/termios_unix.go @@ -0,0 +1,14 @@ +//go:build darwin || linux || solaris || aix +// +build darwin linux solaris aix + +package tea + +import ( + "github.com/charmbracelet/x/term" + "golang.org/x/sys/unix" +) + +func (p *Program) checkOptimizedMovements(s *term.State) { + p.useHardTabs = s.Oflag&unix.TABDLY == unix.TAB0 + p.useBackspace = s.Lflag&unix.BSDLY == unix.BS0 +} diff --git a/tty_unix.go b/tty_unix.go index 93a53fcc..7cc2a5a9 100644 --- a/tty_unix.go +++ b/tty_unix.go @@ -10,7 +10,6 @@ import ( "syscall" "github.com/charmbracelet/x/term" - "golang.org/x/sys/unix" ) func (p *Program) initInput() (err error) { @@ -22,10 +21,10 @@ func (p *Program) initInput() (err error) { return fmt.Errorf("error entering raw mode: %w", err) } - // OPTIM: We can use hard tabs to optimize cursor movements if the - // terminal doesn't have tab expansion enabled. - p.useHardTabs = p.previousTtyInputState.Oflag&unix.TABDLY == unix.TAB0 - p.useBackspace = p.previousTtyInputState.Lflag&unix.BSDLY == unix.BS0 + // OPTIM: We can use hard tabs and backspaces to optimize cursor + // movements. This is based on termios settings support and whether + // they exist and enabled. + p.checkOptimizedMovements(p.previousTtyInputState) } if f, ok := p.output.Writer().(term.File); ok && term.IsTerminal(f.Fd()) {