From a3d8be5e2f82fa36e128171a914cd25054b40c9f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Mar 2024 10:49:47 +0530 Subject: [PATCH] icat: Nicer error when user specifies invalid screen geometry --- kittens/icat/main.go | 6 ++++++ kittens/icat/transmit.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kittens/icat/main.go b/kittens/icat/main.go index 265281c9d..85ead219b 100644 --- a/kittens/icat/main.go +++ b/kittens/icat/main.go @@ -182,6 +182,12 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) { return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err) } screen_size.Ypixel = uint16(t) + if screen_size.Xpixel < screen_size.Col { + return 1, fmt.Errorf("Invalid size specification: %s with error: The pixel width is smaller than the number of columns", opts.UseWindowSize) + } + if screen_size.Ypixel < screen_size.Row { + return 1, fmt.Errorf("Invalid size specification: %s with error: The pixel height is smaller than the number of rows", opts.UseWindowSize) + } } if opts.PrintWindowSize { diff --git a/kittens/icat/transmit.go b/kittens/icat/transmit.go index 7c2fde022..c847458d0 100644 --- a/kittens/icat/transmit.go +++ b/kittens/icat/transmit.go @@ -210,8 +210,8 @@ func calculate_in_cell_x_offset(width, cell_width int) int { } func place_cursor(imgd *image_data) { - cw := int(screen_size.Xpixel) / int(screen_size.Col) - ch := int(screen_size.Ypixel) / int(screen_size.Row) + cw := max(int(screen_size.Xpixel)/int(screen_size.Col), 1) + ch := max(int(screen_size.Ypixel)/int(screen_size.Row), 1) imgd.cell_x_offset = calculate_in_cell_x_offset(imgd.canvas_width, cw) imgd.width_cells = int(math.Ceil(float64(imgd.canvas_width) / float64(cw))) imgd.height_cells = int(math.Ceil(float64(imgd.canvas_height) / float64(ch)))