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

Can we have print_color and println_color? #10327

Closed
IainNZ opened this issue Feb 25, 2015 · 11 comments · Fixed by #13825
Closed

Can we have print_color and println_color? #10327

IainNZ opened this issue Feb 25, 2015 · 11 comments · Fixed by #13825
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia

Comments

@IainNZ
Copy link
Member

IainNZ commented Feb 25, 2015

Title says it all really. We currently have just print_with_color which is verbose and almost every time I've used it I've wanted to have a new line. Hence my "request". I will even invest the 10 hours required myself to make the PR ;)

@dpsanders
Copy link
Contributor

How about a color=true keyword argument for the print and println functions? Or is that a bad idea performance-wise?

@dpsanders
Copy link
Contributor

Sorry, ignore my uninformed comment...

@JeffBezanson
Copy link
Sponsor Member

It seems like a perfectly reasonable comment to me! (am I missing something?)

Generally underscores are unsatisfying. print_color should ideally be separated into two concepts: print and color. A keyword argument would be one way to do that.

@IainNZ
Copy link
Member Author

IainNZ commented Feb 25, 2015

Keyword argument sounds good too. I'll make a PR in that style

@dpsanders
Copy link
Contributor

Great. Rather than color=true, I guess it would be rather color=:blue

Any chance we could also allow the spelling colour...? ;)

@ivarne
Copy link
Sponsor Member

ivarne commented Feb 26, 2015

@dpsanders What would happen if you specify both?

@IainNZ IainNZ added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Mar 23, 2015
@ihnorton ihnorton added good first issue Indicates a good issue for first-time contributors to Julia and removed status:help wanted Indicates that a maintainer wants help on an issue or pull request labels May 8, 2015
@TotalVerb
Copy link
Contributor

Base.println_with_color exists and just needs to be exported. I see there is some concern with underscore names though, so perhaps this is not desired?

@TotalVerb
Copy link
Contributor

I don't think that a keyword argument would be practical. Since there's no dispatch on keyword arguments, every reimplementation of print would need to accept this keyword argument (correct me if I'm mistaken). Also, print is used often in functions like string, where this additional complexity isn't needed at all. What about these other kinds of syntax?

println(with_color(:blue, "Hello World!))

(with_color constructs an object that overloads print)

with_color(println, :blue, "Hello World!")

(with_color calls the given IO function, consistent with sprint and similar, and with function first so that do can be used—this one already basically exists and just needs to be exported)

This second syntax allows do blocks, which can be useful syntax. Something like this already works:

Base.with_output_color(:blue, STDOUT) do io
     println(io, "Hello World")
end

@IainNZ
Copy link
Member Author

IainNZ commented Dec 9, 2015

@TotalVerb I like your thinking there! @vtjnash has been thinking about passing that type of information with higher-level IO types as well, I can't find the PR though

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 9, 2015

yep. this is another issue that #13825 would solve (and is very similar to what @TotalVerb described)

@vtjnash vtjnash reopened this Dec 31, 2015
@kshyatt kshyatt added the domain:display and printing Aesthetics and correctness of printed representations of objects. label Jan 25, 2017
@JeffBezanson
Copy link
Sponsor Member

Now Implemented as printstyled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants