@@ -12,9 +12,19 @@ import (
12
12
"golang.org/x/crypto/ssh/terminal"
13
13
)
14
14
15
+ var ecsi = "\033 ]"
16
+ var st = "\007 "
17
+
18
+ func init () {
19
+ if os .Getenv ("TERM" ) == "screen" {
20
+ ecsi = "\033 Ptmux;\033 " + ecsi
21
+ st += "\033 \\ "
22
+ }
23
+ }
24
+
15
25
// ClearScrollback clears iTerm2 scrollback.
16
26
func ClearScrollback () {
17
- print (" \033 ] 1337;ClearScrollback\007 " )
27
+ print (ecsi + " 1337;ClearScrollback" + st )
18
28
}
19
29
20
30
// TermSize contains sizing information of the terminal.
@@ -37,7 +47,7 @@ func Size() (size TermSize, err error) {
37
47
}
38
48
defer terminal .Restore (1 , s )
39
49
var cellWidth , cellHeight float64
40
- fmt .Fprint (os .Stdout , " \033 ] 1337;ReportCellSize\033 \\ " )
50
+ fmt .Fprint (os .Stdout , ecsi + " 1337;ReportCellSize" + st )
41
51
fileSetReadDeadline (os .Stdout , time .Now ().Add (time .Second ))
42
52
defer fileSetReadDeadline (os .Stdout , time.Time {})
43
53
_ , 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) {
67
77
68
78
func (w * ImageWriter ) Close () error {
69
79
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 )
71
81
return w .b66enc .Close ()
72
82
}
0 commit comments