From c423ae65575a984a4c1ca1af51ab8c1f3ceac7d9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Wed, 8 Oct 2025 17:34:23 -0700 Subject: Update import path --- icat.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'icat.go') diff --git a/icat.go b/icat.go index 56ab95a..8faf85f 100644 --- a/icat.go +++ b/icat.go @@ -1,3 +1,4 @@ +// The icat command displays an image to the terminal using block characters. package main import ( @@ -18,6 +19,11 @@ import ( "golang.org/x/term" ) +var ( + x = flag.Int("x", 0, "set image width in columns") + y = flag.Int("y", 0, "set image height in rows") +) + func load(filename string) (image.Image, error) { file := os.Stdin if filename != "-" { @@ -39,7 +45,7 @@ func load(filename string) (image.Image, error) { func printImg(img image.Image, cols, lines int) error { // Try not to stretch the image. - if img.Bounds().Dy()*cols <= img.Bounds().Dx()*lines*5/2 { + if lines == 0 || cols != 0 && img.Bounds().Dy()*cols <= img.Bounds().Dx()*lines*5/2 { lines = img.Bounds().Dy() * cols / (img.Bounds().Dx() * 5 / 2) } else { cols = img.Bounds().Dx() * lines * 5 / 2 / img.Bounds().Dy() @@ -73,11 +79,16 @@ func icat(args []string) error { } file := args[0] - cols, lines, err := term.GetSize(1) - if err != nil { - return fmt.Errorf("terminal size: %s", err) + cols := *x + lines := *y + if cols == 0 && lines == 0 { + var err error + cols, lines, err = term.GetSize(1) + if err != nil { + return fmt.Errorf("terminal size: %s", err) + } + lines-- // Leave a line for the status bar. } - lines-- // Leave a line for the status bar. img, err := load(file) if err != nil { -- cgit v1.3.1