fix: use platform specific termios settings to determine optimized cursor movements
This commit is contained in:
parent
12f6445fb2
commit
28e82b66f2
4 changed files with 39 additions and 5 deletions
13
termios_bsd.go
Normal file
13
termios_bsd.go
Normal file
|
|
@ -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
|
||||
}
|
||||
8
termios_other.go
Normal file
8
termios_other.go
Normal file
|
|
@ -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) {}
|
||||
14
termios_unix.go
Normal file
14
termios_unix.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue