-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make print_with_color not default to bold take 2 #18628
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,40 @@ | |
## and REPL | ||
|
||
const text_colors = AnyDict( | ||
:black => "\033[1m\033[30m", | ||
:red => "\033[1m\033[31m", | ||
:green => "\033[1m\033[32m", | ||
:yellow => "\033[1m\033[33m", | ||
:blue => "\033[1m\033[34m", | ||
:magenta => "\033[1m\033[35m", | ||
:cyan => "\033[1m\033[36m", | ||
:white => "\033[1m\033[37m", | ||
:normal => "\033[0m", | ||
:bold => "\033[1m", | ||
:black => "\033[30m", | ||
:red => "\033[31m", | ||
:green => "\033[32m", | ||
:yellow => "\033[33m", | ||
:blue => "\033[34m", | ||
:magenta => "\033[35m", | ||
:cyan => "\033[36m", | ||
:white => "\033[37m", | ||
:light_black => "\033[90m", # gray | ||
:light_red => "\033[91m", | ||
:light_green => "\033[92m", | ||
:light_yellow => "\033[93m", | ||
:light_blue => "\033[94m", | ||
:light_magenta => "\033[95m", | ||
:light_cyan => "\033[96m", | ||
:normal => "\033[0m", | ||
:default => "\033[39m", | ||
:bold => "\033[1m", | ||
) | ||
|
||
const disable_text_style = AnyDict( | ||
:bold => "\033[22m", | ||
:normal => "", | ||
:default => "", | ||
) | ||
|
||
for i in 0:255 | ||
text_colors[i] = "\033[1m\033[38;5;$(i)m" | ||
text_colors[i] = "\033[38;5;$(i)m" | ||
end | ||
|
||
# Create a docstring with an automatically generated list | ||
# of colors. | ||
const possible_formatting_symbols = [:normal, :bold] | ||
available_text_colors = collect(Iterators.filter(x -> !isa(x, Integer), keys(text_colors))) | ||
const possible_formatting_symbols = [:normal, :bold, :default] | ||
available_text_colors = cat(1, | ||
sort(intersect(available_text_colors, possible_formatting_symbols), rev=true), | ||
sort(setdiff( available_text_colors, possible_formatting_symbols))) | ||
|
@@ -35,11 +49,15 @@ const available_text_colors_docstring = | |
"""Dictionary of color codes for the terminal. | ||
|
||
Available colors are: $available_text_colors_docstring as well as the integers 0 to 255 inclusive. | ||
|
||
The color `:default` will print text in the default color while the color `:normal` | ||
will print text with all text properties (like boldness) reset. | ||
""" | ||
text_colors | ||
|
||
have_color = false | ||
default_color_warn = :red | ||
default_color_warn = :light_red | ||
default_color_error = :light_red | ||
default_color_info = :cyan | ||
if is_windows() | ||
default_color_input = :normal | ||
|
@@ -57,10 +75,13 @@ function repl_color(key, default) | |
haskey(text_colors, c_conv) ? c_conv : default | ||
end | ||
|
||
warn_color() = repl_color("JULIA_WARN_COLOR", default_color_warn) | ||
info_color() = repl_color("JULIA_INFO_COLOR", default_color_info) | ||
input_color() = text_colors[repl_color("JULIA_INPUT_COLOR", default_color_input)] | ||
answer_color() = text_colors[repl_color("JULIA_ANSWER_COLOR", default_color_answer)] | ||
error_color() = repl_color("JULIA_ERROR_COLOR", default_color_error) | ||
warn_color() = repl_color("JULIA_WARN_COLOR" , default_color_warn) | ||
info_color() = repl_color("JULIA_INFO_COLOR" , default_color_info) | ||
|
||
# Print input and answer in bold. | ||
input_color() = text_colors[:bold] * text_colors[repl_color("JULIA_INPUT_COLOR", default_color_input)] | ||
answer_color() = text_colors[:bold] * text_colors[repl_color("JULIA_ANSWER_COLOR", default_color_answer)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we consider moving these functions to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps. On the other hand it makes sense to have all the ENV color stuff in the same place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how much of it is more general-purpose beyond REPL usage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IJulia uses colors for infos, errors and warnings now and thus indirectly uses the corresponding ENV vars. |
||
|
||
function repl_cmd(cmd, out) | ||
shell = shell_split(get(ENV,"JULIA_SHELL",get(ENV,"SHELL","/bin/sh"))) | ||
|
@@ -101,8 +122,8 @@ end | |
|
||
display_error(er) = display_error(er, []) | ||
function display_error(er, bt) | ||
with_output_color(:red, STDERR) do io | ||
print(io, "ERROR: ") | ||
print_with_color(Base.error_color(), STDERR, "ERROR: "; bold = true) | ||
with_output_color(Base.error_color(), STDERR) do io | ||
showerror(io, er, bt) | ||
println(io) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -527,7 +527,7 @@ function show_expr_type(io::IO, ty, emph) | |
end | ||
end | ||
|
||
emphasize(io, str::AbstractString) = have_color ? print_with_color(:red, io, str) : print(io, uppercase(str)) | ||
emphasize(io, str::AbstractString) = have_color ? print_with_color(Base.error_color(), io, str; bold = true) : print(io, uppercase(str)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the bold kwarg doesn't exist yet if this is the first commit, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I moved it to the second commit. |
||
|
||
show_linenumber(io::IO, line) = print(io," # line ",line,':') | ||
show_linenumber(io::IO, line, file) = print(io," # ", file,", line ",line,':') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ immutable Pass <: Result | |
value | ||
end | ||
function Base.show(io::IO, t::Pass) | ||
print_with_color(:green, io, "Test Passed\n") | ||
print_with_color(:green, io, "Test Passed\n"; bold = true) | ||
if !(t.orig_expr === nothing) | ||
print(io, " Expression: ", t.orig_expr) | ||
end | ||
|
@@ -70,7 +70,7 @@ type Fail <: Result | |
value | ||
end | ||
function Base.show(io::IO, t::Fail) | ||
print_with_color(:red, io, "Test Failed\n") | ||
print_with_color(Base.error_color(), io, "Test Failed\n"; bold = true) | ||
print(io, " Expression: ", t.orig_expr) | ||
if t.test_type == :test_throws_wrong | ||
# An exception was thrown, but it was of the wrong type | ||
|
@@ -102,7 +102,7 @@ type Error <: Result | |
backtrace | ||
end | ||
function Base.show(io::IO, t::Error) | ||
print_with_color(:red, io, "Error During Test\n") | ||
print_with_color(Base.error_color(), io, "Error During Test\n"; bold = true) | ||
if t.test_type == :test_nonbool | ||
println(io, " Expression evaluated to non-Boolean") | ||
println(io, " Expression: ", t.orig_expr) | ||
|
@@ -140,7 +140,7 @@ type Broken <: Result | |
orig_expr | ||
end | ||
function Base.show(io::IO, t::Broken) | ||
print_with_color(:yellow, io, "Test Broken\n") | ||
print_with_color(:yellow, io, "Test Broken\n"; bold = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the other PR that changes warnings to yellow should think about making these use the configurable warning color There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was that merged before this? lost track There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. answering my own question: not yet #18453 |
||
if t.test_type == :skipped && !(t.orig_expr === nothing) | ||
println(io, " Skipped: ", t.orig_expr) | ||
elseif !(t.orig_expr === nothing) | ||
|
@@ -478,21 +478,21 @@ function print_test_results(ts::DefaultTestSet, depth_pad=0) | |
# recursively walking the tree of test sets | ||
align = max(get_alignment(ts, 0), length("Test Summary:")) | ||
# Print the outer test set header once | ||
print_with_color(:white, rpad("Test Summary:",align," "), " | ") | ||
print_with_color(:white, rpad("Test Summary:",align," "), " | "; bold = true) | ||
if pass_width > 0 | ||
print_with_color(:green, lpad("Pass",pass_width," "), " ") | ||
print_with_color(:green, lpad("Pass",pass_width," "), " "; bold = true) | ||
end | ||
if fail_width > 0 | ||
print_with_color(:red, lpad("Fail",fail_width," "), " ") | ||
print_with_color(Base.error_color(), lpad("Fail",fail_width," "), " "; bold = true) | ||
end | ||
if error_width > 0 | ||
print_with_color(:red, lpad("Error",error_width," "), " ") | ||
print_with_color(Base.error_color(), lpad("Error",error_width," "), " "; bold = true) | ||
end | ||
if broken_width > 0 | ||
print_with_color(:yellow, lpad("Broken",broken_width," "), " ") | ||
print_with_color(:yellow, lpad("Broken",broken_width," "), " "; bold = true) | ||
end | ||
if total_width > 0 | ||
print_with_color(:blue, lpad("Total",total_width, " ")) | ||
print_with_color(Base.info_color(), lpad("Total",total_width, " "); bold = true) | ||
end | ||
println() | ||
# Recursively print a summary at every level | ||
|
@@ -603,15 +603,15 @@ function print_counts(ts::DefaultTestSet, depth, align, | |
|
||
nf = fails + c_fails | ||
if nf > 0 | ||
print_with_color(:red, lpad(string(nf), fail_width, " "), " ") | ||
print_with_color(Base.error_color(), lpad(string(nf), fail_width, " "), " ") | ||
elseif fail_width > 0 | ||
# No fails at this level, but some at another level | ||
print(lpad(" ", fail_width), " ") | ||
end | ||
|
||
ne = errors + c_errors | ||
if ne > 0 | ||
print_with_color(:red, lpad(string(ne), error_width, " "), " ") | ||
print_with_color(Base.error_color(), lpad(string(ne), error_width, " "), " ") | ||
elseif error_width > 0 | ||
# No errors at this level, but some at another level | ||
print(lpad(" ", error_width), " ") | ||
|
@@ -626,9 +626,9 @@ function print_counts(ts::DefaultTestSet, depth, align, | |
end | ||
|
||
if np == 0 && nf == 0 && ne == 0 && nb == 0 | ||
print_with_color(:blue, "No tests") | ||
print_with_color(Base.info_color(), "No tests") | ||
else | ||
print_with_color(:blue, lpad(string(subtotal), total_width, " ")) | ||
print_with_color(Base.info_color(), lpad(string(subtotal), total_width, " ")) | ||
end | ||
println() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did the pr always include this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see the second bullet in the first post for this PR.