mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
term: add term.colorize/2, use it in the tests. Support ConEmuANSI = ON too.
This commit is contained in:
parent
75af639721
commit
3ee78dc961
@ -77,7 +77,7 @@ fn (mut cmd Command) run() {
|
||||
sw := time.new_stopwatch({})
|
||||
cmd.ecode = os.system(cmd.line)
|
||||
spent := sw.elapsed().milliseconds()
|
||||
println(term.yellow('> Running: "$cmd.line" took: $spent ms.'))
|
||||
println(term.colorize(term.yellow, '> Running: "$cmd.line" took: $spent ms.'))
|
||||
println('')
|
||||
}
|
||||
|
||||
@ -90,15 +90,16 @@ fn (commands []Command) summary() {
|
||||
oks := commands.filter(it.ecode == 0)
|
||||
fails := commands.filter(it.ecode != 0)
|
||||
println('')
|
||||
println(term.header(term.yellow(term.bold('Summary of `v test-all`:')), '-'))
|
||||
println(term.yellow('Total runtime: $spent ms'))
|
||||
println(term.header(term.colorize(term.yellow, term.colorize(term.bold, 'Summary of `v test-all`:')),
|
||||
'-'))
|
||||
println(term.colorize(term.yellow, 'Total runtime: $spent ms'))
|
||||
for ocmd in oks {
|
||||
msg := if ocmd.okmsg != '' { ocmd.okmsg } else { ocmd.line }
|
||||
println(term.green('> OK: $msg '))
|
||||
println(term.colorize(term.green, '> OK: $msg '))
|
||||
}
|
||||
for fcmd in fails {
|
||||
msg := if fcmd.errmsg != '' { fcmd.errmsg } else { fcmd.line }
|
||||
println(term.red('> Failed: $msg '))
|
||||
println(term.colorize(term.red, '> Failed: $msg '))
|
||||
}
|
||||
if fails.len > 0 {
|
||||
exit(1)
|
||||
|
@ -6,7 +6,6 @@ import v.pref
|
||||
|
||||
const (
|
||||
skip_with_fsanitize_memory = [
|
||||
'vlib/x/websocket/websocket_test.v',
|
||||
'vlib/encoding/csv/reader_test.v',
|
||||
'vlib/net/tcp_test.v',
|
||||
'vlib/net/tcp_simple_client_server_test.v',
|
||||
@ -17,8 +16,8 @@ const (
|
||||
'vlib/orm/orm_test.v',
|
||||
'vlib/sqlite/sqlite_test.v',
|
||||
'vlib/vweb/tests/vweb_test.v',
|
||||
'vlib/x/websocket/websocket_test.v',
|
||||
'vlib/v/tests/unsafe_test.v',
|
||||
'vlib/x/websocket/websocket_test.v',
|
||||
'vlib/net/http/http_httpbin_test.v',
|
||||
]
|
||||
skip_with_fsanitize_address = [
|
||||
|
@ -189,19 +189,19 @@ pub fn (b &Benchmark) step_message_skip(msg string) string {
|
||||
|
||||
// total_message returns a string with total summary of the benchmark run.
|
||||
pub fn (b &Benchmark) total_message(msg string) string {
|
||||
mut tmsg := '${term.bold('Summary:')} '
|
||||
mut tmsg := '${term.colorize(term.bold, 'Summary:')} '
|
||||
if b.nfail > 0 {
|
||||
tmsg += term.bold(term.red('$b.nfail failed')) + ', '
|
||||
tmsg += term.colorize(term.bold, term.colorize(term.red, '$b.nfail failed')) + ', '
|
||||
}
|
||||
if b.nok > 0 {
|
||||
tmsg += term.bold(term.green('$b.nok passed')) + ', '
|
||||
tmsg += term.colorize(term.bold, term.colorize(term.green, '$b.nok passed')) + ', '
|
||||
}
|
||||
if b.nskip > 0 {
|
||||
tmsg += term.bold(term.yellow('$b.nskip skipped')) + ', '
|
||||
tmsg += term.colorize(term.bold, term.colorize(term.yellow, '$b.nskip skipped')) + ', '
|
||||
}
|
||||
tmsg += '$b.ntotal total. ${term.bold('Runtime:')} ${b.bench_timer.elapsed().microseconds() /
|
||||
tmsg += '$b.ntotal total. ${term.colorize(term.bold, 'Runtime:')} ${b.bench_timer.elapsed().microseconds() /
|
||||
1000} ms.\n'
|
||||
tmsg += term.gray(msg)
|
||||
tmsg += term.colorize(term.gray, msg)
|
||||
return tmsg
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,7 @@ pub fn can_show_color_on_stderr() bool {
|
||||
// If colors are not allowed, returns a given string.
|
||||
pub fn ok_message(s string) string {
|
||||
return if can_show_color_on_stdout() {
|
||||
msg := ' $s '
|
||||
green(msg)
|
||||
green(' $s ')
|
||||
} else {
|
||||
s
|
||||
}
|
||||
@ -41,8 +40,7 @@ pub fn ok_message(s string) string {
|
||||
// If colors are not allowed, returns a given string.
|
||||
pub fn fail_message(s string) string {
|
||||
return if can_show_color_on_stdout() {
|
||||
msg := ' $s '
|
||||
inverse(bg_white(bold(red(msg))))
|
||||
inverse(bg_white(bold(red(' $s '))))
|
||||
} else {
|
||||
s
|
||||
}
|
||||
@ -58,6 +56,16 @@ pub fn warn_message(s string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// colorize returns a colored string by running the specified `cfn` over
|
||||
// the message `s`, only if colored output is supported by the terminal.
|
||||
// Example: term.colorize(term.yellow, 'the message')
|
||||
pub fn colorize(cfn fn (string) string, s string) string {
|
||||
if can_show_color_on_stdout() {
|
||||
return cfn(s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// h_divider returns a horizontal divider line with a dynamic width,
|
||||
// that depends on the current terminal settings.
|
||||
// If an empty string is passed in, print enough spaces to make a new line
|
||||
@ -109,6 +117,9 @@ fn supports_escape_sequences(fd int) bool {
|
||||
return false
|
||||
}
|
||||
$if windows {
|
||||
if os.getenv('ConEmuANSI') == 'ON' {
|
||||
return true
|
||||
}
|
||||
// 4 is enable_virtual_terminal_processing
|
||||
return (is_atty(fd) & 0x0004) > 0
|
||||
} $else {
|
||||
|
Loading…
Reference in New Issue
Block a user