icat: Nicer error when user specifies invalid screen geometry

This commit is contained in:
Kovid Goyal 2024-03-05 10:49:47 +05:30
parent d08a44ea4c
commit a3d8be5e2f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 2 deletions

View File

@ -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 {

View File

@ -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)))