File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,22 @@ pub fn get_cursor_position() !Coord {
80
80
return Coord{x, y}
81
81
}
82
82
83
- // set_terminal_title change the terminal title
83
+ // set_terminal_title change the terminal title (usually that is the containing terminal window title)
84
84
pub fn set_terminal_title (title string ) bool {
85
85
if os.is_atty (1 ) < = 0 || os.getenv ('TERM' ) == 'dumb' {
86
- return true
86
+ return false
87
+ }
88
+ print ('\033 ]0;' )
89
+ print (title)
90
+ print ('\007 ' )
91
+ flush_stdout ()
92
+ return true
93
+ }
94
+
95
+ // set_tab_title changes the terminal *tab title*, for terminal emulators like Konsole, that support several tabs
96
+ pub fn set_tab_title (title string ) bool {
97
+ if os.is_atty (1 ) < = 0 || os.getenv ('TERM' ) == 'dumb' {
98
+ return false
87
99
}
88
100
print ('\033 ]30;' )
89
101
print (title)
@@ -93,8 +105,12 @@ pub fn set_terminal_title(title string) bool {
93
105
}
94
106
95
107
// clear clears current terminal screen.
96
- pub fn clear () {
108
+ pub fn clear () bool {
109
+ if os.is_atty (1 ) < = 0 || os.getenv ('TERM' ) == 'dumb' {
110
+ return false
111
+ }
97
112
print ('\x1b [2J' )
98
113
print ('\x1b [H' )
99
114
flush_stdout ()
115
+ return true
100
116
}
Original file line number Diff line number Diff line change @@ -97,8 +97,19 @@ fn test_set_terminal_title() {
97
97
if os.getenv ('CI' ) != 'true' {
98
98
return
99
99
}
100
- title_change := term.set_terminal_title ('v is awesome!' )
101
- assert title_change == true
100
+ term.set_terminal_title ('v is awesome!' )
101
+ dump (@FILE)
102
+ assert true
103
+ }
104
+
105
+ fn test_set_tab_title () {
106
+ // do not change the current terminal tab title outside of CI:
107
+ if os.getenv ('CI' ) != 'true' {
108
+ return
109
+ }
110
+ term.set_tab_title ('v is awesome!' )
111
+ dump (@FILE)
112
+ assert true
102
113
}
103
114
104
115
fn test_strip_ansi () {
You can’t perform that action at this time.
0 commit comments