Skip to content
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

Markdown formatting for AbstractString log messages #23

Merged
merged 2 commits into from
Feb 29, 2020
Merged

Conversation

c42f
Copy link
Member

@c42f c42f commented Feb 28, 2020

Fixes #16.

As suggested there, I'm now using show(io, MIME"text/plain"(), message) by default (except for strings, which go through Markdown.parse() first. With that in mind it might be sensible to tweak the API requirements for message again, revisiting whether show or string are used.

@c42f c42f mentioned this pull request Feb 28, 2020
test/TerminalLogger.jl Outdated Show resolved Hide resolved
src/TerminalLogger.jl Outdated Show resolved Hide resolved
@tkf
Copy link
Collaborator

tkf commented Feb 29, 2020

It's unfortunate that multi-line highlighting does not work...

image

I guess an easy solution may be to tweak Markdown.jl so that it prints ANSI escape code for each line?:

julia> sprint(
           show,
           "text/plain",
           Markdown.parse("`" * "aaa "^20 * "`"),
           context = IOContext(stdout, :displaysize => (30, 30)),
       )
"  \e[36maaa aaa aaa aaa aaa aaa\n  aaa aaa aaa aaa aaa aaa\n  aaa aaa aaa aaa aaa aaa\n  aaa aaa\e[39m"

It looks like printstyled is doing this:

julia> sprint(io -> printstyled(io, " AAA \n BBB \n CCC", color = :red), context = :color => true)
"\e[31m AAA \e[39m\n\e[31m BBB \e[39m\n\e[31m CCC\e[39m"

So it's probably that Markdown.jl is not using printstyled?

Copy link
Collaborator

@tkf tkf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a quirk with multi-line highlighting but I'm inclined to say it's an upstream problem.

@c42f
Copy link
Member Author

c42f commented Feb 29, 2020

It's unfortunate that multi-line highlighting does not work

Yes this sure is annoying. Working around it seems to require ANSI code parsing and having a model of the terminal's internal color state. At that point it might be better to give up and fix upstream + vendor Markdown.term() though.

Thanks for the review!

@c42f c42f merged commit a7ee26e into master Feb 29, 2020
@c42f c42f deleted the cjf/markdown branch February 29, 2020 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Taking markdown messages seriously
2 participants