mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
icat kitten: Add a command line argument to override terminal window size detection
Fixes #7165 I had five minutes, so why not.
This commit is contained in:
@@ -146,17 +146,45 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) {
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
if tty.IsTerminal(os.Stdout.Fd()) {
|
||||
screen_size, err = tty.GetSize(int(os.Stdout.Fd()))
|
||||
} else {
|
||||
t, oerr := tty.OpenControllingTerm()
|
||||
if oerr != nil {
|
||||
return 1, fmt.Errorf("Failed to open controlling terminal with error: %w", oerr)
|
||||
if opts.UseWindowSize == "" {
|
||||
if tty.IsTerminal(os.Stdout.Fd()) {
|
||||
screen_size, err = tty.GetSize(int(os.Stdout.Fd()))
|
||||
} else {
|
||||
t, oerr := tty.OpenControllingTerm()
|
||||
if oerr != nil {
|
||||
return 1, fmt.Errorf("Failed to open controlling terminal with error: %w", oerr)
|
||||
}
|
||||
screen_size, err = t.GetSize()
|
||||
}
|
||||
if err != nil {
|
||||
return 1, fmt.Errorf("Failed to query terminal using TIOCGWINSZ with error: %w", err)
|
||||
}
|
||||
} else {
|
||||
parts := strings.SplitN(opts.UseWindowSize, ",", 4)
|
||||
if len(parts) != 4 {
|
||||
return 1, fmt.Errorf("Invalid size specification: " + opts.UseWindowSize)
|
||||
}
|
||||
screen_size = &unix.Winsize{}
|
||||
t := 0
|
||||
if t, err = strconv.Atoi(parts[0]); err != nil || t < 1 {
|
||||
return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err)
|
||||
}
|
||||
screen_size.Col = uint16(t)
|
||||
if t, err = strconv.Atoi(parts[1]); err != nil || t < 1 {
|
||||
return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err)
|
||||
}
|
||||
screen_size.Row = uint16(t)
|
||||
if t, err = strconv.Atoi(parts[2]); err != nil || t < 1 {
|
||||
return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err)
|
||||
}
|
||||
screen_size.Xpixel = uint16(t)
|
||||
if t, err = strconv.Atoi(parts[3]); err != nil || t < 1 {
|
||||
return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err)
|
||||
}
|
||||
screen_size.Ypixel = uint16(t)
|
||||
if screen_size.Xpixel == 0 || screen_size.Ypixel == 0 {
|
||||
return 1, fmt.Errorf("zero is not allowed for screen pixel size")
|
||||
}
|
||||
screen_size, err = t.GetSize()
|
||||
}
|
||||
if err != nil {
|
||||
return 1, fmt.Errorf("Failed to query terminal using TIOCGWINSZ with error: %w", err)
|
||||
}
|
||||
|
||||
if opts.PrintWindowSize {
|
||||
|
||||
@@ -72,6 +72,11 @@ The amount of time (in seconds) to wait for a response from the terminal, when
|
||||
detecting image display support.
|
||||
|
||||
|
||||
--use-window-size
|
||||
Instead of querying the terminal for the window size, use the specified size, which must
|
||||
be of the format: width_in_cells,height_in_cells,width_in_pixels,height_in_pixels
|
||||
|
||||
|
||||
--print-window-size
|
||||
type=bool-set
|
||||
Print out the window size as <:italic:`width`>x<:italic:`height`> (in pixels) and quit. This is a
|
||||
|
||||
Reference in New Issue
Block a user