-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
add :color attribute to IOContext, prefer get(io,:color,false) to Base.have_color #25067
Conversation
I wonder if it should be possible to distinguish between supporting 16, 256, 24bit colors. Just a random thought, just ignore if this is off topic. |
@test length(methods(method_c1)) <= 3 # because of '...' in candidate printing | ||
test_have_color(buf, | ||
"\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, \e[1m\e[31m::AbstractString...\e[0m)$cfile$c1line\e[0m", |
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.
might be nice to keep (some of?) these, now that we can actually test both code path properly:
Base.show_method_candidates(IOContext(buf, :color => true), Base.MethodError(method_c1,(1, 1, "")))
@test String(take!(buf)) == "\e[0m\nClosest candidates are:\n method_c1(\e[1m\e[31m::Float64\e[0m, \e[1m\e[31m::AbstractString...\e[0m)$cfile$c1line\e[0m"
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.
I think color codes in warnings are tested elsewhere....
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.
But sure, I'll add a few back in with color enabled.
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.
Interestingly enough, the have_color
testcase was totally wrong, since at least Julia 0.6. It seems that this hasn't been tested in a long while.
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.
I've added a test.
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.
Proving once again that bitrot is inevitable for code that doesn't actually run!
base/show.jl
Outdated
|
||
Return `true` if `io` supports/expects ANSI color codes. | ||
|
||
(This is determined when Julia is started for terminals, and can be |
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.
parens don't seem necessary to me.
@@ -67,6 +67,9 @@ The following properties are in common use: | |||
can be avoided (e.g. `[Float16(0)]` can be shown as "Float16[0.0]" instead | |||
of "Float16[Float16(0.0)]" : while displaying the elements of the array, the `:typeinfo` | |||
property will be set to `Float16`). | |||
- `:color`: Boolean specifying whether ANSI color/escape codes are supported/expected. |
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.
Longer term, I think we may want to try to distinguish between policy ("wants color") and mechanism ("ansi", "xterm256", "html"). But this PR is already strictly better than what we have now, so I think we should merge this and then consider iterating (as needed).
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.
We can add new IO context attributes that Base understand in the future as long as the behavior of the existing ones remains the same.
Note that with this PR, a (In general, there is a lot of stuff in the documentation system that hooks into the display system a little oddly, e.g. using side-effects … this required some crude hacks in IJulia to get a "clean" docstring out of a help request.) |
Error in docs:
|
Yes, the text/plain output has changed. If you just do |
Looks like it needs a rebase after #24913 to fix the new deprecation. |
I'm getting
I guess someone flipped a switch to turn deprecations into errors so that now everything is breaking? (I'm confused.) |
We now had standard logging infrastructure in Base: #24490. Among other changes, |
These test deprecated functionality - the new system is tested separately in |
Oh, now I see the |
Yeah it's a bit nasty I'm afraid - this is why I want to remove |
I would just delete the deprecated functionality tests. After all, we’re going to delete the in 1.0 anyway. |
…ing the Base.have_color global
…ut color), distinct from text/markdown
To capture messages from Base, users should install a logger instead, for example, using `with_logger()`.
ci/circleci seems to be an unrelated libgit2 "Error deserializing a remote exception" distributed-test failure. |
Fixes #19682 by making the use of ANSI color/formatting codes specific to the
io
device. Instead of accessing theBase.have_color
global, you should callBase.hascolor(io)
(not exported)get(io, :color, false)
. By default this usesBase.have_color
for TTY devices, but can be overridden by the:color => {true,false}
property ofIOContext
.Also fixes a problem noted on discourse where Markdown was overriding
display
to do terminal output. Now it overridesshow
and useshascolor(io)
to decide in a device-specific way whether to output formatting codes.