1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: support for -color/-nocolor option overrides

This commit is contained in:
Delyan Angelov
2020-05-20 20:33:29 +03:00
parent 80070516fd
commit 9d4fe88d09
4 changed files with 30 additions and 1 deletions

View File

@@ -34,6 +34,12 @@ pub fn new_builder(pref &pref.Preferences) Builder {
rdir := os.real_path(pref.path)
compiled_dir := if os.is_dir(rdir) { rdir } else { os.dir(rdir) }
table := table.new_table()
if pref.use_color == .always {
util.emanager.set_support_color(true)
}
if pref.use_color == .never {
util.emanager.set_support_color(false)
}
return Builder{
pref: pref
table: table

View File

@@ -20,6 +20,12 @@ pub enum OutputMode {
silent
}
pub enum ColorOutput {
auto
always
never
}
pub enum Backend {
c // The (default) C backend
js // The JavaScript backend
@@ -101,6 +107,7 @@ pub mut:
print_v_files bool // when true, just print the list of all parsed .v files then stop.
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
skip_warnings bool // like C's "-w"
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
}
pub fn parse_args(args []string) (&Preferences, string) {
@@ -166,6 +173,12 @@ pub fn parse_args(args []string) (&Preferences, string) {
'-translated' {
res.translated = true
}
'-color' {
res.use_color=.always
}
'-nocolor' {
res.use_color=.never
}
'-showcc' {
res.show_cc = true
}

View File

@@ -30,7 +30,7 @@ pub const (
)
pub struct EManager {
pub mut:
mut:
support_color bool
}
@@ -40,6 +40,10 @@ pub fn new_error_manager() &EManager {
}
}
pub fn (e &EManager) set_support_color(b bool) {
e.support_color = b
}
fn bold(msg string) string {
if !emanager.support_color {
return msg