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:
parent
ca000292f1
commit
6adafbb6ea
@ -80,10 +80,22 @@ pub fn get_cursor_position() !Coord {
|
|||||||
return Coord{x, y}
|
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 {
|
pub fn set_terminal_title(title string) bool {
|
||||||
if os.is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
|
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('\033]30;')
|
||||||
print(title)
|
print(title)
|
||||||
@ -93,8 +105,12 @@ pub fn set_terminal_title(title string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clear clears current terminal screen.
|
// 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[2J')
|
||||||
print('\x1b[H')
|
print('\x1b[H')
|
||||||
flush_stdout()
|
flush_stdout()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,19 @@ fn test_set_terminal_title() {
|
|||||||
if os.getenv('CI') != 'true' {
|
if os.getenv('CI') != 'true' {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
title_change := term.set_terminal_title('v is awesome!')
|
term.set_terminal_title('v is awesome!')
|
||||||
assert title_change == true
|
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() {
|
fn test_strip_ansi() {
|
||||||
|
Loading…
Reference in New Issue
Block a user