-
-
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
Enable color output whenever stdout is TTY #34347
Conversation
43d74a0
to
ddc9e3c
Compare
Welcome, and thanks for working on this!
That's a good point. For now, the easy thing would be to only enable color if stdout and stderr are both TTYs. Looking at the code in more detail, we should really reduce use of the |
@JeffBezanson |
We have both because |
It looks to me like |
@JeffBezanson For now i have implemented code to enable color when stdout and stderr are both TTY's . What should be the next step ? |
e5b36d6
to
2c8fb62
Compare
@JeffBezanson Any updates on this one? |
This seems OK for now. @ararslan requested a NEWS entry, so just add a line to NEWS.md saying that color now defaults to on when stdout and stderr are TTYs. |
2c8fb62
to
aee8c9f
Compare
I have made an entry in News.md with the purpose of this pr |
NEWS.md
Outdated
@@ -32,6 +32,8 @@ Language changes | |||
(in addition to the one that enters the help mode) to see the full | |||
docstring. ([#25930]) | |||
|
|||
* Color nows defaults to on when stdout and stderr are TTYs ([#34347]) |
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.
* Color nows defaults to on when stdout and stderr are TTYs ([#34347]) | |
* Color now defaults to on when stdout and stderr are TTYs ([#34347]) |
aee8c9f
to
eb122dc
Compare
Thinking about it some more, this probably needs more discussion. In interactive mode, we try to check whether the terminal supports color. If checking is important, then it doesn't make much sense to skip the check in non-interactive mode. Before, we probably wanted to avoid the check to save startup time. I think there are 3 options:
|
Idea from discussion on triage: delay checking of the output stream (by calling tput, etc.) until we actually do something that would be different based on if there's color or not. So, for example, |
Could be done this way:
|
@JeffBezanson I have understood your point but while implementing , I am not sure how I can do this without |
Do you mean for a "quick fix"? It would be really nice if this is a per-instance property. I have multiple packages opening non-stdio TTYs and relying on a global state is rather ugly for such usages. |
I have the implementation to remove Dependency of function hascolor()
term_type = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
startswith(term_type, "xterm") && return true
try
@static if Sys.KERNEL === :FreeBSD
return success('tput AF 0')
else
return success('tput setaf 0')
end
catch
return false
end
end @JeffBezanson please verify. |
Yes looks OK to me. |
@mkitti yeah I think this is a concrete approach to settle the problem |
… mkitti-TTY-STDOUT-color
base/ttyhascolor.jl
Outdated
<<<<<<< HEAD | ||
|
||
|
||
======= | ||
>>>>>>> 59586ded0da55b383c01b5d6e3538cd9680d79a3 |
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.
Remove lines 26 - 30
<<<<<<< HEAD | |
======= | |
>>>>>>> 59586ded0da55b383c01b5d6e3538cd9680d79a3 | |
<<<<<<< HEAD | |
======= | |
>>>>>>> 59586ded0da55b383c01b5d6e3538cd9680d79a3 |
@karan0299 You still have some merge conflict marks at the end of |
2a01b79
to
2704faf
Compare
@@ -241,6 +241,7 @@ include("filesystem.jl") | |||
using .Filesystem | |||
include("cmd.jl") | |||
include("process.jl") | |||
include("ttyhascolor.jl") |
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.
Does this need to be its own file? Otherwise it seems like it makes sense to keep it with the implementation of TTY.
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 think ,we can shift this to stdlib/REPL/src/Terminal.jl
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.
@JeffBezanson The code in ttyhascolor.jl needs to come after process.jl due to the use of success
. stream.jl is included before process.jl, and we were getting compilation errors because of this.
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.
Ok, I figured it was something like that.
2704faf
to
7abf1a6
Compare
base/loading.jl
Outdated
io = open(pipeline(`$(julia_cmd()) -O0 | ||
--output-ji $output --output-incremental=yes | ||
--startup-file=no --history-file=no --warn-overwrite=yes | ||
--color=$(have_color ? "yes" : "no") | ||
--color=$(have_color === true ? "yes" : "no") |
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.
--color=$(have_color === true ? "yes" : "no") | |
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no") |
I'm not sure why the one test failed for building on Mac. Looks like some kind of stochastic error. Could someone restart that test to see? |
7abf1a6
to
2b8b583
Compare
All CI tests passed |
Thanks for your persistence on this one. Ended up being more complicated than I would have thought! Glad to have this finally merged :) |
Revert "Enable color output whenever stdout is TTY (#34347)"
Unrevert #34347 and bump Pkg to a version that is compatible with it
This reverts commit 8a39bc7.
This reverts commit 8a39bc7.
This reverts commit 8a39bc7.
This reverts commit 8a39bc7.
Fixes #34317 . Made a check if STDOUT is a TTY and color is not set explicitly by the user , then set global variable have_color to true.
In my opinion , there should be separate have_color variable for STDOUT and STDERR, since we can have separate TTY for STDOUT and STDERR