icat: Nicer error when user specifies invalid screen geometry
This commit is contained in:
parent
d08a44ea4c
commit
a3d8be5e2f
2 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
return 1, fmt.Errorf("Invalid size specification: %s with error: %w", opts.UseWindowSize, err)
|
||||||
}
|
}
|
||||||
screen_size.Ypixel = uint16(t)
|
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 {
|
if opts.PrintWindowSize {
|
||||||
|
|
|
||||||
|
|
@ -210,8 +210,8 @@ func calculate_in_cell_x_offset(width, cell_width int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func place_cursor(imgd *image_data) {
|
func place_cursor(imgd *image_data) {
|
||||||
cw := int(screen_size.Xpixel) / int(screen_size.Col)
|
cw := max(int(screen_size.Xpixel)/int(screen_size.Col), 1)
|
||||||
ch := int(screen_size.Ypixel) / int(screen_size.Row)
|
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.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.width_cells = int(math.Ceil(float64(imgd.canvas_width) / float64(cw)))
|
||||||
imgd.height_cells = int(math.Ceil(float64(imgd.canvas_height) / float64(ch)))
|
imgd.height_cells = int(math.Ceil(float64(imgd.canvas_height) / float64(ch)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue