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 | |
| parent | 923290a1bf8a6129075465891d14deaaeb96318f (diff) | |
| download | imgutil-c423ae65575a984a4c1ca1af51ab8c1f3ceac7d9.tar.zst | |
Update import path
| -rw-r--r-- | go.mod | 10 | ||||
| -rw-r--r-- | go.sum | 18 | ||||
| -rw-r--r-- | icat.go | 21 |
3 files changed, 27 insertions, 22 deletions
@@ -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 @@ -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= @@ -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 { |
