term: add term.colorize/2, use it in the tests. Support ConEmuANSI = ON too.
parent
75af639721
commit
3ee78dc961
|
@ -77,7 +77,7 @@ fn (mut cmd Command) run() {
|
||||||
sw := time.new_stopwatch({})
|
sw := time.new_stopwatch({})
|
||||||
cmd.ecode = os.system(cmd.line)
|
cmd.ecode = os.system(cmd.line)
|
||||||
spent := sw.elapsed().milliseconds()
|
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('')
|
println('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +90,16 @@ fn (commands []Command) summary() {
|
||||||
oks := commands.filter(it.ecode == 0)
|
oks := commands.filter(it.ecode == 0)
|
||||||
fails := commands.filter(it.ecode != 0)
|
fails := commands.filter(it.ecode != 0)
|
||||||
println('')
|
println('')
|
||||||
println(term.header(term.yellow(term.bold('Summary of `v test-all`:')), '-'))
|
println(term.header(term.colorize(term.yellow, term.colorize(term.bold, 'Summary of `v test-all`:')),
|
||||||
println(term.yellow('Total runtime: $spent ms'))
|
'-'))
|
||||||
|
println(term.colorize(term.yellow, 'Total runtime: $spent ms'))
|
||||||
for ocmd in oks {
|
for ocmd in oks {
|
||||||
msg := if ocmd.okmsg != '' { ocmd.okmsg } else { ocmd.line }
|
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 {
|
for fcmd in fails {
|
||||||
msg := if fcmd.errmsg != '' { fcmd.errmsg } else { fcmd.line }
|
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 {
|
if fails.len > 0 {
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import v.pref
|
||||||
|
|
||||||
const (
|
const (
|
||||||
skip_with_fsanitize_memory = [
|
skip_with_fsanitize_memory = [
|
||||||
'vlib/x/websocket/websocket_test.v',
|
|
||||||
'vlib/encoding/csv/reader_test.v',
|
'vlib/encoding/csv/reader_test.v',
|
||||||
'vlib/net/tcp_test.v',
|
'vlib/net/tcp_test.v',
|
||||||
'vlib/net/tcp_simple_client_server_test.v',
|
'vlib/net/tcp_simple_client_server_test.v',
|
||||||
|
@ -17,8 +16,8 @@ const (
|
||||||
'vlib/orm/orm_test.v',
|
'vlib/orm/orm_test.v',
|
||||||
'vlib/sqlite/sqlite_test.v',
|
'vlib/sqlite/sqlite_test.v',
|
||||||
'vlib/vweb/tests/vweb_test.v',
|
'vlib/vweb/tests/vweb_test.v',
|
||||||
'vlib/x/websocket/websocket_test.v',
|
|
||||||
'vlib/v/tests/unsafe_test.v',
|
'vlib/v/tests/unsafe_test.v',
|
||||||
|
'vlib/x/websocket/websocket_test.v',
|
||||||
'vlib/net/http/http_httpbin_test.v',
|
'vlib/net/http/http_httpbin_test.v',
|
||||||
]
|
]
|
||||||
skip_with_fsanitize_address = [
|
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.
|
// total_message returns a string with total summary of the benchmark run.
|
||||||
pub fn (b &Benchmark) total_message(msg string) string {
|
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 {
|
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 {
|
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 {
|
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'
|
1000} ms.\n'
|
||||||
tmsg += term.gray(msg)
|
tmsg += term.colorize(term.gray, msg)
|
||||||
return tmsg
|
return tmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,7 @@ pub fn can_show_color_on_stderr() bool {
|
||||||
// If colors are not allowed, returns a given string.
|
// If colors are not allowed, returns a given string.
|
||||||
pub fn ok_message(s string) string {
|
pub fn ok_message(s string) string {
|
||||||
return if can_show_color_on_stdout() {
|
return if can_show_color_on_stdout() {
|
||||||
msg := ' $s '
|
green(' $s ')
|
||||||
green(msg)
|
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
@ -41,8 +40,7 @@ pub fn ok_message(s string) string {
|
||||||
// If colors are not allowed, returns a given string.
|
// If colors are not allowed, returns a given string.
|
||||||
pub fn fail_message(s string) string {
|
pub fn fail_message(s string) string {
|
||||||
return if can_show_color_on_stdout() {
|
return if can_show_color_on_stdout() {
|
||||||
msg := ' $s '
|
inverse(bg_white(bold(red(' $s '))))
|
||||||
inverse(bg_white(bold(red(msg))))
|
|
||||||
} else {
|
} else {
|
||||||
s
|
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,
|
// h_divider returns a horizontal divider line with a dynamic width,
|
||||||
// that depends on the current terminal settings.
|
// that depends on the current terminal settings.
|
||||||
// If an empty string is passed in, print enough spaces to make a new line
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
$if windows {
|
$if windows {
|
||||||
|
if os.getenv('ConEmuANSI') == 'ON' {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// 4 is enable_virtual_terminal_processing
|
// 4 is enable_virtual_terminal_processing
|
||||||
return (is_atty(fd) & 0x0004) > 0
|
return (is_atty(fd) & 0x0004) > 0
|
||||||
} $else {
|
} $else {
|
||||||
|
|
Loading…
Reference in New Issue