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 --- go.mod | 10 +++++----- go.sum | 18 ++++++------------ icat.go | 21 ++++++++++++++++----- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index fdcae13..3ed9d4d 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ -module github.com/rhogenson/icat +module roseh.moe/cmd/icat -go 1.23.0 +go 1.24.0 toolchain go1.24.1 require ( - golang.org/x/image v0.26.0 - golang.org/x/term v0.31.0 + golang.org/x/image v0.32.0 + golang.org/x/term v0.36.0 ) -require golang.org/x/sys v0.32.0 // indirect +require golang.org/x/sys v0.37.0 // indirect diff --git a/go.sum b/go.sum index c68db5e..e9c590b 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,6 @@ -golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ= -golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs= -golang.org/x/image v0.26.0 h1:4XjIFEZWQmCZi6Wv8BoxsDhRU3RVnLX04dToTDAEPlY= -golang.org/x/image v0.26.0/go.mod h1:lcxbMFAovzpnJxzXS3nyL83K27tmqtKzIJpctK8YO5c= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= -golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= -golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= -golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= +golang.org/x/image v0.32.0 h1:6lZQWq75h7L5IWNk0r+SCpUJ6tUVd3v4ZHnbRKLkUDQ= +golang.org/x/image v0.32.0/go.mod h1:/R37rrQmKXtO6tYXAjtDLwQgFLHmhW+V6ayXlxzP2Pc= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= +golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= 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