Skip to content

Commit 12acd69

Browse files
authored
Merge pull request #35294 from JuliaLang/tb/pkgeval_color
Revert "Enable color output whenever stdout is TTY (#34347)"
2 parents 02624ac + 9ab3fb2 commit 12acd69

File tree

9 files changed

+31
-43
lines changed

9 files changed

+31
-43
lines changed

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Language changes
6161
Now the result is "a\n b", since the space before `b` is no longer considered to occur
6262
at the start of a line. The old behavior is considered a bug ([#35001]).
6363

64-
* Color now defaults to on when stdout and stderr are TTYs ([#34347])
6564

6665
Multi-threading changes
6766
-----------------------

base/Base.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ include("filesystem.jl")
241241
using .Filesystem
242242
include("cmd.jl")
243243
include("process.jl")
244-
include("ttyhascolor.jl")
245244
include("grisu/grisu.jl")
246245
include("secretbuffer.jl")
247246

base/client.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## client.jl - frontend handling command line options, environment setup,
44
## and REPL
55

6-
have_color = nothing
6+
have_color = false
77
default_color_warn = :yellow
88
default_color_error = :light_red
99
default_color_info = :cyan
@@ -109,7 +109,6 @@ display_error(er, bt=nothing) = display_error(stderr, er, bt)
109109
function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
110110
errcount = 0
111111
lasterr = nothing
112-
have_color = get(stdout, :color, false)
113112
while true
114113
try
115114
if have_color
@@ -221,7 +220,7 @@ function exec_options(opts)
221220
startup = (opts.startupfile != 2)
222221
history_file = (opts.historyfile != 0)
223222
color_set = (opts.color != 0) # --color!=auto
224-
global have_color = color_set ? (opts.color == 1) : nothing # --color=on
223+
global have_color = (opts.color == 1) # --color=on
225224
global is_interactive = (opts.isinteractive != 0)
226225

227226
# pre-process command line argument list
@@ -493,7 +492,7 @@ function _start()
493492
invokelatest(display_error, catch_stack())
494493
exit(1)
495494
end
496-
if is_interactive && have_color === true
495+
if is_interactive && have_color
497496
print(color_normal)
498497
end
499498
end

base/loading.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,10 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
11691169
eval(Meta.parse(code))
11701170
end
11711171
"""
1172-
11731172
io = open(pipeline(`$(julia_cmd()) -O0
11741173
--output-ji $output --output-incremental=yes
11751174
--startup-file=no --history-file=no --warn-overwrite=yes
1176-
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
1175+
--color=$(have_color ? "yes" : "no")
11771176
--eval $code_object`, stderr=stderr),
11781177
"w", stdout)
11791178
in = io.in

base/stream.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ function displaysize(io::TTY)
485485
return h, w
486486
end
487487

488+
in(key_value::Pair{Symbol,Bool}, ::TTY) = key_value.first === :color && key_value.second === have_color
489+
haskey(::TTY, key::Symbol) = key === :color
490+
getindex(::TTY, key::Symbol) = key === :color ? have_color : throw(KeyError(key))
491+
get(::TTY, key::Symbol, default) = key === :color ? have_color : default
492+
488493
### Libuv callbacks ###
489494

490495
## BUFFER ##

base/ttyhascolor.jl

Lines changed: 0 additions & 25 deletions
This file was deleted.

stdlib/REPL/src/REPL.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ mutable struct BasicREPL <: AbstractREPL
302302
end
303303

304304
outstream(r::BasicREPL) = r.terminal
305-
hascolor(r::BasicREPL) = hascolor(r.terminal)
306305

307306
function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
308307
d = REPLDisplay(repl)
@@ -429,14 +428,13 @@ mutable struct LineEditREPL <: AbstractREPL
429428
interface::ModalInterface
430429
backendref::REPLBackendRef
431430
LineEditREPL(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,in_help,envcolors) =
432-
new(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
431+
new(t,true,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
433432
in_help,envcolors,false,nothing, Options(), nothing)
434433
end
435434
outstream(r::LineEditREPL) = r.t
436435
specialdisplay(r::LineEditREPL) = r.specialdisplay
437436
specialdisplay(r::AbstractREPL) = nothing
438437
terminal(r::LineEditREPL) = r.t
439-
hascolor(r::LineEditREPL) = r.hascolor
440438

441439
LineEditREPL(t::TextTerminal, hascolor::Bool, envcolors::Bool=false) =
442440
LineEditREPL(t, hascolor,
@@ -815,7 +813,7 @@ function respond(f, repl, main; pass_empty = false, suppress_on_semicolon = true
815813
response = (catch_stack(), true)
816814
end
817815
hide_output = suppress_on_semicolon && ends_with_semicolon(line)
818-
print_response(repl, response, !hide_output, hascolor(repl))
816+
print_response(repl, response, !hide_output, Base.have_color)
819817
end
820818
prepare_next(repl)
821819
reset_state(s)
@@ -957,7 +955,7 @@ function setup_interface(
957955
end
958956
hist_from_file(hp, f, hist_path)
959957
catch
960-
print_response(repl, (catch_stack(),true), true, hascolor(repl))
958+
print_response(repl, (catch_stack(),true), true, Base.have_color)
961959
println(outstream(repl))
962960
@info "Disabling history file for this session"
963961
repl.history_file = false
@@ -1157,7 +1155,6 @@ StreamREPL(stream::IO) = StreamREPL(stream, Base.text_colors[:green], Base.input
11571155
run_repl(stream::IO) = run_repl(StreamREPL(stream))
11581156

11591157
outstream(s::StreamREPL) = s.stream
1160-
hascolor(s::StreamREPL) = get(s.stream, :color, false)
11611158

11621159
answer_color(r::LineEditREPL) = r.envcolors ? Base.answer_color() : r.answer_color
11631160
answer_color(r::StreamREPL) = r.answer_color
@@ -1216,7 +1213,7 @@ function ends_with_semicolon(line::AbstractString)
12161213
end
12171214

12181215
function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
1219-
have_color = hascolor(repl)
1216+
have_color = Base.have_color
12201217
Base.banner(repl.stream)
12211218
d = REPLDisplay(repl)
12221219
dopushdisplay = !in(d,Base.Multimedia.displays)

stdlib/REPL/src/Terminals.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,22 @@ beep(t::UnixTerminal) = write(t.err_stream,"\x7")
152152

153153
Base.displaysize(t::UnixTerminal) = displaysize(t.out_stream)
154154

155-
hascolor(t::TTYTerminal) = Base.ttyhascolor(t.term_type)
155+
if Sys.iswindows()
156+
hascolor(t::TTYTerminal) = true
157+
else
158+
function hascolor(t::TTYTerminal)
159+
startswith(t.term_type, "xterm") && return true
160+
try
161+
@static if Sys.KERNEL === :FreeBSD
162+
return success(`tput AF 0`)
163+
else
164+
return success(`tput setaf 0`)
165+
end
166+
catch
167+
return false
168+
end
169+
end
170+
end
156171

157172
# use cached value of have_color
158173
Base.in(key_value::Pair, t::TTYTerminal) = in(key_value, pipe_writer(t))

stdlib/REPL/test/repl.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function fake_repl(@nospecialize(f); options::REPL.Options=REPL.Options(confirm_
4747
Base.link_pipe!(output, reader_supports_async=true, writer_supports_async=true)
4848
Base.link_pipe!(err, reader_supports_async=true, writer_supports_async=true)
4949

50-
repl = REPL.LineEditREPL(FakeTerminal(input.out, output.in, err.in, options.hascolor), options.hascolor)
50+
repl = REPL.LineEditREPL(FakeTerminal(input.out, output.in, err.in), true)
5151
repl.options = options
5252

5353
hard_kill = kill_timer(900) # Your debugging session starts now. You have 15 minutes. Go.
@@ -90,7 +90,7 @@ end
9090
# in the mix. If verification needs to be done, keep it to the bare minimum. Basically
9191
# this should make sure nothing crashes without depending on how exactly the control
9292
# characters are being used.
93-
fake_repl(options = REPL.Options(confirm_exit=false,hascolor=false)) do stdin_write, stdout_read, repl
93+
fake_repl() do stdin_write, stdout_read, repl
9494
repl.specialdisplay = REPL.REPLDisplay(repl)
9595
repl.history_file = false
9696

0 commit comments

Comments
 (0)