compiler: print warnings in magenta

pull/4666/head
eyelash 2020-05-01 12:44:15 +02:00 committed by GitHub
parent 0106eb1cf6
commit 6b08cbcb7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -70,14 +70,14 @@ pub fn formatted_error(kind, emsg, filepath string, pos token.Position) string {
} }
column := imax(0, pos.pos - p - 1) column := imax(0, pos.pos - p - 1)
position := '${path}:${pos.line_nr+1}:${util.imax(1,column+1)}:' position := '${path}:${pos.line_nr+1}:${util.imax(1,column+1)}:'
scontext := source_context(source, column, pos).join('\n') scontext := source_context(kind, source, column, pos).join('\n')
final_position := if emanager.support_color { term.bold(position) } else { position } final_position := if emanager.support_color { term.bold(position) } else { position }
mut final_kind := kind mut final_kind := kind
if emanager.support_color { if emanager.support_color {
final_kind = if kind.contains('error') { final_kind = if kind.contains('error') {
term.bold(term.red(kind)) term.bold(term.red(kind))
} else { } else {
term.bold(term.bright_blue(kind)) term.bold(term.magenta(kind))
} }
} }
final_msg := emsg // if emanager.support_color { term.bold(emsg) } else { emsg } final_msg := emsg // if emanager.support_color { term.bold(emsg) } else { emsg }
@ -86,7 +86,7 @@ pub fn formatted_error(kind, emsg, filepath string, pos token.Position) string {
return '$final_position $final_kind $final_msg $final_context'.trim_space() return '$final_position $final_kind $final_msg $final_context'.trim_space()
} }
pub fn source_context(source string, column int, pos token.Position) []string { pub fn source_context(kind, source string, column int, pos token.Position) []string {
mut clines := []string{} mut clines := []string{}
if source.len == 0 { if source.len == 0 {
return clines return clines
@ -99,7 +99,11 @@ pub fn source_context(source string, column int, pos token.Position) []string {
sline := source_lines[iline] sline := source_lines[iline]
mut cline := '${iline+1:5d}| ' + sline.replace('\t', tab_spaces) mut cline := '${iline+1:5d}| ' + sline.replace('\t', tab_spaces)
if iline == pos.line_nr && emanager.support_color { if iline == pos.line_nr && emanager.support_color {
cline = term.red(cline) cline = if kind.contains('error') {
term.red(cline)
} else {
term.magenta(cline)
}
} }
clines << cline clines << cline
// //