Skip to content

Commit

Permalink
Fix iTerm 3.1.6+ compat (fixes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Jun 23, 2018
1 parent 3b60ff4 commit a377a0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ func render(dash graph.Dash, rows int) {
rows = size.Row
}
// Use iTerm2 image display feature.
term := &osc.ImageWriter{}
term := &osc.ImageWriter{
Width: width,
Height: height,
}
defer term.Close()
if err := dash.Render(term, width, height); err != nil {
fatal(fmt.Sprintf("cannot render graph: %v", err.Error()))
Expand Down
6 changes: 4 additions & 2 deletions osc/iterm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func Rows() (rows int, err error) {
// ImageWriter is a writer that write into iTerm2 terminal the PNG data written
// to it.
type ImageWriter struct {
Name string
Name string
Width int
Height int

once sync.Once
b66enc io.WriteCloser
Expand All @@ -95,6 +97,6 @@ func (w *ImageWriter) Write(p []byte) (n int, err error) {
// Close flushes the image to the terminal and close the writer.
func (w *ImageWriter) Close() error {
w.once.Do(w.init)
fmt.Printf("%s1337;File=preserveAspectRatio=1;inline=1:%s%s", ecsi, w.buf.Bytes(), st)
fmt.Printf("%s1337;File=preserveAspectRatio=1;width=%dpx;height=%dpx;inline=1:%s%s", ecsi, w.Width, w.Height, w.buf.Bytes(), st)
return w.b66enc.Close()
}

0 comments on commit a377a0d

Please sign in to comment.