readme added
sophuwu sophie@skisiel.com
Sun, 14 Jul 2024 13:47:20 +0200
A
README.md
@@ -0,0 +1,35 @@
+## Sketch +This program allows you to view images in your terminal. + +### Features +- View images in your terminal +- Show as many images as you want at once +- Images always scale to fit the terminal size +- Supports png and jpg +- Adjustable scaling with flags + +### Usage +```bash +sketch </path/to/images> +# or for 60% size +sketch -6 </path/to/images> +# you can even change size in the middle of the images +sketch cat.png -4 dog.jpg +# will output cat.png with 100% scale and dog.jpg at 40% size +``` + +### Installation Instructions +1. clone it +```bash +git clone <url ^ that way> +cd sketch +``` +2. go build it +```bash +go build -o sketch -ldflags "-s -w" -trimpath . +``` +3. install it +```bash +chmod +x sketch +sudo install sketch /usr/local/bin/sketch +```
M
main.go
→
main.go
@@ -9,11 +9,12 @@ _ "image/jpeg"
_ "image/png" "math" "os" + "strings" ) func getTermSize() (int, int) { W, H, err := term.GetSize(int(os.Stdout.Fd())) - if err != nil { + if err != nil || !(W > 0 && H > 0) { fmt.Fprintln(os.Stderr, "fatal: could not get terminal size") os.Exit(1) }@@ -89,6 +90,13 @@ W, H := getTermSize()
var img Immg var err error for _, path := range os.Args[1:] { + if strings.HasPrefix(path, "-") && len(path) == 2 && '1' <= path[1] && path[1] <= '9' { + W *= (int(path[1]) - '0') + W /= 10 + H *= (int(path[1]) - '0') + H /= 10 + continue + } err = img.OpenImg(path) if err != nil { fmt.Fprintf(os.Stderr, "error opening image: %s\n", path)