diff --git a/gen-wcwidth.py b/gen-wcwidth.py index a0b906f15..60c84c133 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -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) diff --git a/tools/tui/loop.go b/tools/tui/loop.go index 4a111a7cf..e709c7f6b 100644 --- a/tools/tui/loop.go +++ b/tools/tui/loop.go @@ -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 { diff --git a/tools/tui/wcwidth-std.go b/tools/tui/wcwidth-std.go index f23f9a2e0..df6e5b1c2 100644 --- a/tools/tui/wcwidth-std.go +++ b/tools/tui/wcwidth-std.go @@ -2892,7 +2892,6 @@ func Wcwidth(code rune) int { default: return 1 } - return 1 } func IsEmojiPresentationBase(code rune) bool { switch code {