diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2023-08-31 09:50:17 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2023-08-31 09:50:17 -0700 |
| commit | 2ef107aee0b4e88b3335b04418ec0e27ad8ebbfc (patch) | |
| tree | f1be40a1f2b246e56fc2ba0af9c24a367c55211d /icat.go | |
| parent | 3d875397ab4f21f06bc490982a62fdd62aa76a91 (diff) | |
| download | imgutil-2ef107aee0b4e88b3335b04418ec0e27ad8ebbfc.tar.zst | |
Use one stdout buffer for the whole program.
Diffstat (limited to 'icat.go')
| -rw-r--r-- | icat.go | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -11,6 +11,8 @@ import ( "os" ) +var stdout = bufio.NewWriter(os.Stdout) + func load(filename string) (image.Image, error) { file := os.Stdin if filename != "-" { @@ -46,14 +48,12 @@ func printImg(filename string, cols, lines int) error { dst := image.NewRGBA(image.Rect(0, 0, cols, lines)) draw.ApproxBiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) - buf := bufio.NewWriter(os.Stdout) - defer buf.Flush() for y := 0; y < lines; y++ { for x := 0; x < cols; x++ { r, g, b, _ := dst.At(x, y).RGBA() - fmt.Fprintf(buf, "\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) + fmt.Fprintf(stdout, "\033[48;2;%d;%d;%dm ", r>>8, g>>8, b>>8) } - fmt.Fprintln(buf, "\033[49m") + fmt.Fprintln(stdout, "\033[49m") } return nil } @@ -68,6 +68,8 @@ func icat(args []string) error { if len(args) == 0 { args = []string{"-"} } + + defer stdout.Flush() for _, f := range args { if err := printImg(f, cols, lines); err != nil { return err |
