Less layering
This commit is contained in:
parent
10d11bc749
commit
4ab5456ead
@ -555,7 +555,10 @@ def gen_wcwidth() -> None:
|
||||
|
||||
p('\t\tdefault:\n\t\t\treturn 1;')
|
||||
p('\t}')
|
||||
p('\treturn 1;\n}')
|
||||
if for_go:
|
||||
p('\t}')
|
||||
else:
|
||||
p('\treturn 1;\n}')
|
||||
|
||||
with create_header('kitty/wcwidth-std.h') as p, open('tools/tui/wcwidth-std.go', 'w') as gof:
|
||||
gop = partial(print, file=gof)
|
||||
|
||||
@ -8,9 +8,33 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
func read_ignoring_eintr(fd int, buf []byte) (int, error) {
|
||||
n, err := unix.Read(fd, buf)
|
||||
if err == unix.EINTR {
|
||||
return 0, nil
|
||||
}
|
||||
if n == 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func write_ignoring_eintr(fd int, buf []byte) (int, error) {
|
||||
n, err := unix.Write(fd, buf)
|
||||
if err == unix.EINTR {
|
||||
return 0, nil
|
||||
}
|
||||
if n == 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
type Loop struct {
|
||||
controlling_term *tty.Term
|
||||
terminal_options TerminalStateOptions
|
||||
@ -228,16 +252,15 @@ func (self *Loop) Run() (err error) {
|
||||
}
|
||||
if selector.IsReadyToRead(tty_fd) {
|
||||
read_buf = read_buf[:cap(read_buf)]
|
||||
num_read, err := self.controlling_term.Read(read_buf)
|
||||
num_read, err := read_ignoring_eintr(tty_fd, read_buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if num_read == 0 {
|
||||
return io.EOF
|
||||
}
|
||||
err = self.escape_code_parser.Parse(read_buf[:num_read])
|
||||
if err != nil {
|
||||
return err
|
||||
if num_read > 0 {
|
||||
err = self.escape_code_parser.Parse(read_buf[:num_read])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if selector.IsReadyToRead(int(signal_read_file.Fd())) {
|
||||
@ -277,12 +300,12 @@ func (self *Loop) write_to_tty() error {
|
||||
if len(self.write_buf) == 0 || self.controlling_term == nil {
|
||||
return nil
|
||||
}
|
||||
n, err := self.controlling_term.Write(self.write_buf)
|
||||
n, err := write_ignoring_eintr(self.controlling_term.Fd(), self.write_buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return io.EOF
|
||||
if n <= 0 {
|
||||
return nil
|
||||
}
|
||||
remainder := self.write_buf[n:]
|
||||
if len(remainder) > 0 {
|
||||
|
||||
1
tools/tui/wcwidth-std.go
generated
1
tools/tui/wcwidth-std.go
generated
@ -2892,7 +2892,6 @@ func Wcwidth(code rune) int {
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
func IsEmojiPresentationBase(code rune) bool {
|
||||
switch code {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user