Skip to content

Commit

Permalink
Show pixel dimensions too in image viewer info, and show info at exit…
Browse files Browse the repository at this point in the history
… even for solo image (#36)

* Show pixel dimensions too and show at exit even for solo image

* linter
  • Loading branch information
ldemailly authored Sep 24, 2024
1 parent 43f4880 commit 2318c6f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ansipixels/fps/fps.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var fpsJpg []byte
//go:embed fps_colors.jpg
var fpsColorsJpg []byte

func imagesViewer(ap *ansipixels.AnsiPixels, imageFiles []string) int {
func imagesViewer(ap *ansipixels.AnsiPixels, imageFiles []string) int { //nolint:gocognit // yeah well...
ap.ClearScreen()
ap.HideCursor()
ap.Data = make([]byte, 3)
Expand All @@ -102,6 +102,11 @@ func imagesViewer(ap *ansipixels.AnsiPixels, imageFiles []string) int {
}
imageFile := imageFiles[i]
img, format, err := ap.ReadImage(imageFile)
extra := ""
if l > 1 {
extra = fmt.Sprintf(", %d/%d", i+1, l)
}
info := fmt.Sprintf("%s (%dx%d %s%s)", imageFile, img.Bounds().Dx(), img.Bounds().Dy(), format, extra)
if err != nil {
return log.FErrf("Error reading image %s: %v", imageFile, err)
}
Expand All @@ -110,7 +115,7 @@ func imagesViewer(ap *ansipixels.AnsiPixels, imageFiles []string) int {
return log.FErrf("Error showing image: %v", err)
}
if showInfo {
ap.WriteRight(ap.H-1, "%s (%s, %d/%d)", imageFile, format, i+1, l)
ap.WriteRight(ap.H-1, "%s", info)
ap.Out.Flush()
}
wait:
Expand All @@ -131,6 +136,7 @@ func imagesViewer(ap *ansipixels.AnsiPixels, imageFiles []string) int {
}
}
if n != 0 {
ap.WriteRight(ap.H-1, "%s", info)
break
}
}
Expand Down Expand Up @@ -212,7 +218,7 @@ func Main() int { //nolint:funlen,gocognit // color and mode if/else are a bit l
}
defer func() {
ap.ShowCursor()
ap.MoveCursor(0, ap.H-2)
ap.MoveCursor(0, ap.H-1)
ap.Out.Flush()
ap.Restore()
}()
Expand Down

0 comments on commit 2318c6f

Please sign in to comment.