add :color attribute to IOContext, prefer get(io,:color,false) to Base.have_color#25067
add :color attribute to IOContext, prefer get(io,:color,false) to Base.have_color#25067StefanKarpinski merged 15 commits intoJuliaLang:masterfrom
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 String(take!(buf)) == "\nClosest candidates are:\n method_c1(!Matched::Float64, !Matched::AbstractString...)$cfile$c1line" | ||
| @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.
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.
I think color codes in warnings are tested elsewhere....
There was a problem hiding this comment.
But sure, I'll add a few back in with color enabled.
There was a problem hiding this comment.
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.
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.
parens don't seem necessary to me.
| 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.
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.
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
iodevice. Instead of accessing theBase.have_colorglobal, you should callBase.hascolor(io)(not exported)get(io, :color, false). By default this usesBase.have_colorfor TTY devices, but can be overridden by the:color => {true,false}property ofIOContext.Also fixes a problem noted on discourse where Markdown was overriding
displayto do terminal output. Now it overridesshowand useshascolor(io)to decide in a device-specific way whether to output formatting codes.