-
-
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
IOColor (IOContext part 2?) #27430
IOColor (IOContext part 2?) #27430
Conversation
base/formatio.jl
Outdated
pipe_writer(io::IOFormatBuffer) = io.buf | ||
pipe_reader(io::IOFormatBuffer) = error("IOFormatBuffer not readable") | ||
|
||
function with_output_color(f::Function, color::Union{Int, Symbol}, io::IO, args...; bold::Bool = false) |
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.
Perhaps a good opportunity to rename with_output_color
to something less ugly?
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 had some recollection that we'd already renamed it to styled
or something like that?
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 changed print_with_color
to printstyled
, but left with_output_color
unchanged, I forget why.
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.
Maybe withstyle(f, io, color=..., bold=...)
?
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.
Or perhaps just styled(f, io, color=, bold=)
?
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.
bold
being some arbitrary special kwarg should probably be deprecated
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.
Why's that? In printstyled
we have color
and bold
keyword arguments and that seems to work quite nicely.
Anyone seen this error before?
|
…from type hierarchy
And handle the attribute more consistently. Also, ensure that `Terminals.supports_color` asks `tput` the right question, and checks for getting back the required answer.
fully support nesting of ANSI color and format codes, and provide a scaffold which could be used for supporting more complex formatting (or other rich side information).
This is a port of `_truncate_at_width_or_chars` to any IO object.
While building complex output, it is sometimes useful to be able to stage content in a separate buffer, then append it to the final output. Support that, by deferring the final render when simply transfering content between IOFormatBuffers with write
Also some move some code to more preferred locations
be2cfa7
to
da14d3c
Compare
The call `with_format(io) do io; end` is very beneficial for mono-morphizing IO code (enabling it to be precompiled) and buffering it (potentially making it faster and reducing interleaving of output) And try to improve some IO code to utilize it more / better
I think this can be closed since my guess is that this will be incompatible with the styled strings stuff. |
It is mostly all compatible, as they have similar designs, but a lot of work possibly to filter through here and pick up any fixes that didn't already get separately put in master |
While working on the original IOContext PR, I had created a PoC of fully handling nested color. Here, I'm working on finally reviving and finishing that, building on all of the other new work towards better color handling.
Some color / format nesting in action:
There's also some demo code in here of how that output could also be turned into html (ref #5239), which was probably the real purpose behind this work (although not actually finished or enabled here).