Less layering

This commit is contained in:
Kovid Goyal 2022-08-24 19:55:46 +05:30
parent 10d11bc749
commit 4ab5456ead
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 37 additions and 12 deletions

View File

@ -555,7 +555,10 @@ def gen_wcwidth() -> None:
p('\t\tdefault:\n\t\t\treturn 1;') p('\t\tdefault:\n\t\t\treturn 1;')
p('\t}') 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: with create_header('kitty/wcwidth-std.h') as p, open('tools/tui/wcwidth-std.go', 'w') as gof:
gop = partial(print, file=gof) gop = partial(print, file=gof)

View File

@ -8,9 +8,33 @@ import (
"syscall" "syscall"
"time" "time"
"golang.org/x/sys/unix"
"kitty/tools/utils" "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 { type Loop struct {
controlling_term *tty.Term controlling_term *tty.Term
terminal_options TerminalStateOptions terminal_options TerminalStateOptions
@ -228,16 +252,15 @@ func (self *Loop) Run() (err error) {
} }
if selector.IsReadyToRead(tty_fd) { if selector.IsReadyToRead(tty_fd) {
read_buf = read_buf[:cap(read_buf)] 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 { if err != nil {
return err return err
} }
if num_read == 0 { if num_read > 0 {
return io.EOF err = self.escape_code_parser.Parse(read_buf[:num_read])
} if err != nil {
err = self.escape_code_parser.Parse(read_buf[:num_read]) return err
if err != nil { }
return err
} }
} }
if selector.IsReadyToRead(int(signal_read_file.Fd())) { 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 { if len(self.write_buf) == 0 || self.controlling_term == nil {
return 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 { if err != nil {
return err return err
} }
if n == 0 { if n <= 0 {
return io.EOF return nil
} }
remainder := self.write_buf[n:] remainder := self.write_buf[n:]
if len(remainder) > 0 { if len(remainder) > 0 {

View File

@ -2892,7 +2892,6 @@ func Wcwidth(code rune) int {
default: default:
return 1 return 1
} }
return 1
} }
func IsEmojiPresentationBase(code rune) bool { func IsEmojiPresentationBase(code rune) bool {
switch code { switch code {