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,6 +555,9 @@ def gen_wcwidth() -> None:
p('\t\tdefault:\n\t\t\treturn 1;')
p('\t}')
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:

View File

@ -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,18 +252,17 @@ 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
}
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())) {
signal_buf = signal_buf[:cap(signal_buf)]
err = self.read_signals(signal_read_file, signal_buf)
@ -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 {

View File

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