oldv: use green color for tracing/diagnostic lines

pull/6063/head
Delyan Angelov 2020-08-04 11:22:37 +03:00
parent 60c642f42d
commit 9511d086bd
2 changed files with 20 additions and 9 deletions

View File

@ -1,6 +1,11 @@
module scripting module scripting
import os import os
import term
const (
term_colors = term.can_show_color_on_stdout()
)
pub fn set_verbose(on bool) { pub fn set_verbose(on bool) {
// setting a global here would be the obvious solution, // setting a global here would be the obvious solution,
@ -13,24 +18,30 @@ pub fn set_verbose(on bool) {
} }
} }
pub fn cprintln(message string) {
mut omessage := message
omessage = if term_colors { term.green(omessage) } else { omessage }
println(omessage)
}
pub fn verbose_trace(label string, message string) { pub fn verbose_trace(label string, message string) {
if os.getenv('VERBOSE').len > 0 { if os.getenv('VERBOSE').len > 0 {
slabel := 'scripting.${label}' slabel := 'scripting.${label}'
println('# ${slabel:-25s} : $message') cprintln('# ${slabel:-25s} : $message')
} }
} }
pub fn verbose_trace_exec_result(x os.Result) { pub fn verbose_trace_exec_result(x os.Result) {
if os.getenv('VERBOSE').len > 0 { if os.getenv('VERBOSE').len > 0 {
println('# cmd.exit_code : ${x.exit_code.str():-4s} cmd.output:') cprintln('# cmd.exit_code : ${x.exit_code.str():-4s} cmd.output:')
println('# ----------------------------------- #') cprintln('# ----------------------------------- #')
mut lnum := 1 mut lnum := 1
lines := x.output.split_into_lines() lines := x.output.split_into_lines()
for line in lines { for line in lines {
println('# ${lnum:3d}: $line') cprintln('# ${lnum:3d}: $line')
lnum++ lnum++
} }
println('# ----------------------------------- #') cprintln('# ----------------------------------- #')
} }
} }

View File

@ -79,7 +79,7 @@ fn main() {
} else { } else {
context.commit_v = scripting.run('git rev-list -n1 HEAD') context.commit_v = scripting.run('git rev-list -n1 HEAD')
} }
println('################# context.commit_v: $context.commit_v #####################') scripting.cprintln('################# context.commit_v: $context.commit_v #####################')
context.path_v = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_v) context.path_v = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_v)
context.path_vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc') context.path_vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
if !os.is_dir(context.vgo.workdir) { if !os.is_dir(context.vgo.workdir) {
@ -98,13 +98,13 @@ fn main() {
context.compile_oldv_if_needed() context.compile_oldv_if_needed()
scripting.chdir(context.path_v) scripting.chdir(context.path_v)
println('# v commit hash: $context.commit_v_hash') scripting.cprintln('# v commit hash: $context.commit_v_hash')
println('# checkout folder: $context.path_v') scripting.cprintln('# checkout folder: $context.path_v')
if context.cmd_to_run.len > 0 { if context.cmd_to_run.len > 0 {
cmdres := os.exec(context.cmd_to_run) or { cmdres := os.exec(context.cmd_to_run) or {
panic(err) panic(err)
} }
println('# command: ${context.cmd_to_run:-34s} exit code: ${cmdres.exit_code:-4d} result:') scripting.cprintln('# command: ${context.cmd_to_run:-34s} exit code: ${cmdres.exit_code:-4d} result:')
println(cmdres.output) println(cmdres.output)
exit(cmdres.exit_code) exit(cmdres.exit_code)
} }