1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

term: add a separate term.set_tab_title/1 API for controling the current tab title in emulators like Konsole, that support many tabs

This commit is contained in:
Delyan Angelov 2023-01-14 12:00:39 +02:00
parent ca000292f1
commit 6adafbb6ea
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 32 additions and 5 deletions

View File

@ -80,10 +80,22 @@ pub fn get_cursor_position() !Coord {
return Coord{x, y}
}
// set_terminal_title change the terminal title
// set_terminal_title change the terminal title (usually that is the containing terminal window title)
pub fn set_terminal_title(title string) bool {
if os.is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
return true
return false
}
print('\033]0;')
print(title)
print('\007')
flush_stdout()
return true
}
// set_tab_title changes the terminal *tab title*, for terminal emulators like Konsole, that support several tabs
pub fn set_tab_title(title string) bool {
if os.is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
return false
}
print('\033]30;')
print(title)
@ -93,8 +105,12 @@ pub fn set_terminal_title(title string) bool {
}
// clear clears current terminal screen.
pub fn clear() {
pub fn clear() bool {
if os.is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
return false
}
print('\x1b[2J')
print('\x1b[H')
flush_stdout()
return true
}

View File

@ -97,8 +97,19 @@ fn test_set_terminal_title() {
if os.getenv('CI') != 'true' {
return
}
title_change := term.set_terminal_title('v is awesome!')
assert title_change == true
term.set_terminal_title('v is awesome!')
dump(@FILE)
assert true
}
fn test_set_tab_title() {
// do not change the current terminal tab title outside of CI:
if os.getenv('CI') != 'true' {
return
}
term.set_tab_title('v is awesome!')
dump(@FILE)
assert true
}
fn test_strip_ansi() {