Skip to content

Commit

Permalink
Merge pull request #23 from yoichi/respect-terminal-width
Browse files Browse the repository at this point in the history
Scale to terminal width if possible
  • Loading branch information
mattn committed Oct 8, 2019
2 parents 5a450f2 + 48760b5 commit 6388459
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pixterm/pixterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"image"
"image/png"
"io"
"os"

"github.com/lucasb-eyer/go-colorful"
"golang.org/x/crypto/ssh/terminal"
"github.com/mattn/pixterm/ansimage"
)

Expand All @@ -24,6 +26,10 @@ func NewEncoder(w io.Writer) *Encoder {

func (e *Encoder) Encode(img image.Image) error {
width, height := img.Bounds().Dx(), img.Bounds().Dy()
tw, _, err := terminal.GetSize(int(os.Stdout.Fd()))
if err == nil && width > tw * ansimage.BlockSizeX {
width = tw * ansimage.BlockSizeX
}
if e.Width != 0 {
width = e.Width
}
Expand Down

0 comments on commit 6388459

Please sign in to comment.