Skip to content

Commit fe6526b

Browse files
committed
Partial tmux support
1 parent 03cd9be commit fe6526b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

osc/iterm2.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ import (
1212
"golang.org/x/crypto/ssh/terminal"
1313
)
1414

15+
var ecsi = "\033]"
16+
var st = "\007"
17+
18+
func init() {
19+
if os.Getenv("TERM") == "screen" {
20+
ecsi = "\033Ptmux;\033" + ecsi
21+
st += "\033\\"
22+
}
23+
}
24+
1525
// ClearScrollback clears iTerm2 scrollback.
1626
func ClearScrollback() {
17-
print("\033]1337;ClearScrollback\007")
27+
print(ecsi + "1337;ClearScrollback" + st)
1828
}
1929

2030
// TermSize contains sizing information of the terminal.
@@ -37,7 +47,7 @@ func Size() (size TermSize, err error) {
3747
}
3848
defer terminal.Restore(1, s)
3949
var cellWidth, cellHeight float64
40-
fmt.Fprint(os.Stdout, "\033]1337;ReportCellSize\033\\")
50+
fmt.Fprint(os.Stdout, ecsi+"1337;ReportCellSize"+st)
4151
fileSetReadDeadline(os.Stdout, time.Now().Add(time.Second))
4252
defer fileSetReadDeadline(os.Stdout, time.Time{})
4353
_, err = fmt.Fscanf(os.Stdout, "\033]1337;ReportCellSize=%f;%f\033\\", &cellHeight, &cellWidth)
@@ -67,6 +77,6 @@ func (w *ImageWriter) Write(p []byte) (n int, err error) {
6777

6878
func (w *ImageWriter) Close() error {
6979
w.once.Do(w.init)
70-
fmt.Printf("\033]1337;File=preserveAspectRatio=1;inline=1:%s\007", w.buf.Bytes())
80+
fmt.Printf("%s1337;File=preserveAspectRatio=1;inline=1:%s%s", ecsi, w.buf.Bytes(), st)
7181
return w.b66enc.Close()
7282
}

0 commit comments

Comments
 (0)