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

make print_with_color not default to bold take 2 #18628

Merged
merged 3 commits into from
Dec 15, 2016
Merged

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Sep 22, 2016

This is take 2 of #18480.

  • First commit introduces an ENV var for changing the color errors are printed in.
  • Second commit remove the default boldness in print_with_color. Instead a kwarg bold is added which determines if the result should be printed in bold. For backwards compatability, the :bold key is still left in the text_colors dict. This also sets the default color for errors and warnings to light_red instead of red because on most terminals this is the color it used to be when printing red + bold. This is also the reason for the first commit because for example Jupyter notebook does not support the light versions of the color so IJulia can if it wants set the ENV variable to just be red. Edit: However, 16 color support in notebook is merged, just not in release: Re-factor ANSI color handling jupyter/notebook#1230
  • Third commit hooks up the test framework to use corresponding ENV variables in a few places. The reason for this is that the blue used is not very visible on many terminals (same problem as with the previous info messages) and it is good to keep the users chosen "colorscheme".

Note, this is not meant to change any input color / boldness, output color / boldness, repl color / boldness etc and not change any of the possible settings that are available now.

image

@KristofferC KristofferC added this to the 0.6.0 milestone Sep 22, 2016
@KristofferC KristofferC added the REPL Julia's REPL (Read Eval Print Loop) label Sep 22, 2016
let
old_have_color = Base.have_color
try
eval(Base, :(have_color = true))
Copy link
Member Author

@KristofferC KristofferC Sep 22, 2016

Choose a reason for hiding this comment

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

Is this acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't something similar done in a withenv in a different test?

Copy link
Contributor

Choose a reason for hiding this comment

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

this was fine for now, better to test things. we can think about making color not a global elsewhere.

hopefully can restore these from reflog or old commits?


# 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)]
Copy link
Contributor

Choose a reason for hiding this comment

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

should we consider moving these functions to the REPL module instead of Base ?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

how much of it is more general-purpose beyond REPL usage?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

a keyword argument `bold::Bool` which determines whether to print in bold or not.
On some terminals, printing a color in non bold results in slightly darker colors being printed than when printing in bold.
Therefore, light versions of the colors are now supported.
For the available colors see the help entry on `print_with_color.
Copy link
Contributor

Choose a reason for hiding this comment

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

missing closing backtick

Copy link
Contributor

Choose a reason for hiding this comment

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

still missing

:magenta => "\033[35m",
:cyan => "\033[36m",
:white => "\033[37m",
:light_black => "\033[90m",
Copy link
Contributor

Choose a reason for hiding this comment

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

how does that work?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could either call it gray or keep the light_COLOR pattern like I did here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I've ever heard gray called light black, but I guess it works. throw a comment in?

@@ -138,7 +138,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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

Choose a reason for hiding this comment

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

was that merged before this? lost track

Copy link
Contributor

Choose a reason for hiding this comment

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

answering my own question: not yet #18453

change the colors for the help and shell prompts and input and answer text by setting the
appropriate field of ``repl`` in the ``customize_colors`` function above (respectively, ``help_color``, ``shell_color``,
``input_color``, and ``answer_color``). For the latter two, be sure that the ``envcolors`` field
is also set to false.

You can also customize the color used to render warning and informational messages by
You can also customize the color used to render error, warning and informational messages by
setting the appropriate environment variable. For instance, to render warning messages in yellow and
informational messages in cyan you can add the following to your ``juliarc.jl`` file::
Copy link
Contributor

Choose a reason for hiding this comment

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

... and error messages in magenta

@StefanKarpinski
Copy link
Member

This seems to just need a quick rebase and merge.

@KristofferC KristofferC force-pushed the kc/little_less_bold_2 branch 3 times, most recently from 4088cd8 to e16e7c1 Compare October 28, 2016 15:29
for (n,crc) in [(0,0x00000000),(1,0xa016d052),(2,0x03f89f52),(3,0xf130f21e),(4,0x29308cf4),(5,0x53518fab),(6,0x4f4dfbab),(7,0xbd3a64dc),(8,0x46891f81),(9,0x5a14b9f9),(10,0xb219db69),(11,0xd232a91f),(12,0x51a15563),(13,0x9f92de41),(14,0x4d8ae017),(15,0xc8b74611),(16,0xa0de6714),(17,0x672c992a),(18,0xe8206eb6),(19,0xc52fd285),(20,0x327b0397),(21,0x318263dd),(22,0x08485ccd),(23,0xea44d29e),(24,0xf6c0cb13),(25,0x3969bba2),(26,0x6a8810ec),(27,0x75b3d0df),(28,0x82d535b1),(29,0xbdf7fc12),(30,0x1f836b7d),(31,0xd29f33af),(32,0x8e4acb3e),(33,0x1cbee2d1),(34,0xb25f7132),(35,0xb0fa484c),(36,0xb9d262b4),(37,0x3207fe27),(38,0xa024d7ac),(39,0x49a2e7c5),(40,0x0e2c157f),(41,0x25f7427f),(42,0x368c6adc),(43,0x75efd4a5),(44,0xa84c5c31),(45,0x0fc817b2),(46,0x8d99a881),(47,0x5cc3c078),(48,0x9983d5e2),(49,0x9267c2db),(50,0xc96d4745),(51,0x058d8df3),(52,0x453f9cf3),(53,0xb714ade1),(54,0x55d3c2bc),(55,0x495710d0),(56,0x3bddf494),(57,0x4f2577d0),(58,0xdae0f604),(59,0x3c57c632),(60,0xfe39bbb0),(61,0x6f5d1d41),(62,0x7d996665),(63,0x68c738dc),(64,0x8dfea7ae)]
@test Base.crc32c(UInt8[1:n;]) == crc
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

bad rebase

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, git lied to me :P

Copy link
Contributor

Choose a reason for hiding this comment

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

@KristofferC KristofferC force-pushed the kc/little_less_bold_2 branch from e16e7c1 to 9ecb48a Compare October 28, 2016 16:02
@tkelman tkelman dismissed their stale review October 31, 2016 23:35

made minor edits to address my own review

@tkelman
Copy link
Contributor

tkelman commented Nov 1, 2016

wasn't this previously adding some new tests at the end of test/misc.jl? @KristofferC did you intend to remove those, or was it a rebase issue again?

@tkelman tkelman added the needs tests Unit tests are required for this change label Nov 5, 2016
@KristofferC KristofferC force-pushed the kc/little_less_bold_2 branch from 2cb5cc8 to 9329ab7 Compare December 10, 2016 17:01
@KristofferC
Copy link
Member Author

Rebased and added test

@tkelman tkelman removed the needs tests Unit tests are required for this change label Dec 10, 2016
@tkelman
Copy link
Contributor

tkelman commented Dec 10, 2016

Need to convert the doc additions to markdown

@KristofferC
Copy link
Member Author

KristofferC commented Dec 10, 2016

Thanks, forgot about that.

The available color keys in `Base.text_colors` are `:black`, `:red`, `:green`, `:yellow`, `:blue`,
`:magenta`, `:cyan`, `:white`, `:normal`, and `:bold` as well as the integers 0 to 255 for terminals
with 256 color support. Similarly, you can change the colors for the help and shell prompts and
The available color keys can be seen by typing ``Base.text_colors`` in the help mode of the REPL.
Copy link
Contributor

Choose a reason for hiding this comment

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

single backticks in markdown

@@ -324,4 +326,5 @@ messages in cyan you can add the following to your `juliarc.jl` file:
```julia
ENV["JULIA_WARN_COLOR"] = :yellow
ENV["JULIA_INFO_COLOR"] = :cyan
ENV["JULIA_ERROR_COLOR"] = :magenta
Copy link
Contributor

Choose a reason for hiding this comment

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

this undid 5a9b1d7

@KristofferC KristofferC force-pushed the kc/little_less_bold_2 branch from 866edcd to 6977a6d Compare December 10, 2016 19:36
@KristofferC
Copy link
Member Author

Apologies, hopefully fixed.

@KristofferC KristofferC force-pushed the kc/little_less_bold_2 branch 2 times, most recently from f12b7d9 to 6c8585d Compare December 11, 2016 12:04
@KristofferC
Copy link
Member Author

Squashed a bit and rebased.

default_color_warn = :red
default_color_error = :red
default_color_warn = :light_red
default_color_error = :light_red
Copy link
Contributor

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?

Copy link
Member Author

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.

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. I moved it to the second commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants