The stupid term package is not EINTR safe

This commit is contained in:
Kovid Goyal 2022-08-21 11:45:58 +05:30
parent 15e1f376a4
commit e599a2c87f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 4 deletions

View File

@ -897,6 +897,8 @@ def update_go_generated_files(args: Options, kitty_exe: str) -> None:
def build_kitty_tool(args: Options, launcher_dir: str, for_freeze: bool = False) -> None: def build_kitty_tool(args: Options, launcher_dir: str, for_freeze: bool = False) -> None:
sys.stdout.flush()
sys.stderr.flush()
go = shutil.which('go') go = shutil.which('go')
if not go: if not go:
raise SystemExit('The go tool was not found on this system. Install Go') raise SystemExit('The go tool was not found on this system. Install Go')

View File

@ -14,7 +14,7 @@ import (
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"golang.org/x/term" "golang.org/x/sys/unix"
"kitty" "kitty"
"kitty/tools/utils" "kitty/tools/utils"
@ -328,9 +328,16 @@ func full_command_name(cmd *cobra.Command) string {
func show_usage(cmd *cobra.Command, use_pager bool) error { func show_usage(cmd *cobra.Command, use_pager bool) error {
screen_width := 80 screen_width := 80
if stdout_is_terminal { if stdout_is_terminal {
screen_width, _, tty_size_err := term.GetSize(int(os.Stdout.Fd())) var sz *unix.Winsize
if tty_size_err != nil || screen_width > 80 { var tty_size_err error
screen_width = 80 for {
sz, tty_size_err = unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ)
if tty_size_err != unix.EINTR {
break
}
}
if tty_size_err == nil && sz.Col < 80 {
screen_width = int(sz.Col)
} }
} }
var output strings.Builder var output strings.Builder