1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/term/can_show_color.v
2019-11-06 23:04:40 +03:00

38 lines
686 B
V

module term
import os
pub fn can_show_color_on_stdout() bool {
return supports_escape_sequences(1)
}
pub fn can_show_color_on_stderr() bool {
return supports_escape_sequences(2)
}
fn supports_escape_sequences(fd int) bool {
$if windows {
return (is_atty(fd) & 0x0004) > 0 && os.getenv('TERM') != 'dumb' // ENABLE_VIRTUAL_TERMINAL_PROCESSING
} $else {
return is_atty(fd) > 0 && os.getenv('TERM') != 'dumb'
}
}
//////////////////////////////////////////////
pub fn ok_message(s string) string {
return if can_show_color_on_stdout() {
green( s )
}else{
s
}
}
pub fn fail_message(s string) string {
return if can_show_color_on_stdout() {
red( s )
}else{
s
}
}