diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-08 17:34:23 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-08 17:34:23 -0700 |
| commit | c423ae65575a984a4c1ca1af51ab8c1f3ceac7d9 (patch) | |
| tree | e068e7829f1cc3189b18d68835e5106dc35901e9 /icat.go | |
| parent | 923290a1bf8a6129075465891d14deaaeb96318f (diff) | |
| download | imgutil-c423ae65575a984a4c1ca1af51ab8c1f3ceac7d9.tar.zst | |
Update import path
Diffstat (limited to 'icat.go')
| -rw-r--r-- | icat.go | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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 { |
