Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Language changes
Now the result is "a\n b", since the space before `b` is no longer considered to occur
at the start of a line. The old behavior is considered a bug ([#35001]).

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

Multi-threading changes
-----------------------
Expand Down
1 change: 0 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ include("filesystem.jl")
using .Filesystem
include("cmd.jl")
include("process.jl")
include("ttyhascolor.jl")
include("grisu/grisu.jl")
include("secretbuffer.jl")

Expand Down
7 changes: 3 additions & 4 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## client.jl - frontend handling command line options, environment setup,
## and REPL

have_color = nothing
have_color = false
default_color_warn = :yellow
default_color_error = :light_red
default_color_info = :cyan
Expand Down Expand Up @@ -109,7 +109,6 @@ display_error(er, bt=nothing) = display_error(stderr, er, bt)
function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
errcount = 0
lasterr = nothing
have_color = get(stdout, :color, false)
while true
try
if have_color
Expand Down Expand Up @@ -221,7 +220,7 @@ function exec_options(opts)
startup = (opts.startupfile != 2)
history_file = (opts.historyfile != 0)
color_set = (opts.color != 0) # --color!=auto
global have_color = color_set ? (opts.color == 1) : nothing # --color=on
global have_color = (opts.color == 1) # --color=on
global is_interactive = (opts.isinteractive != 0)

# pre-process command line argument list
Expand Down Expand Up @@ -493,7 +492,7 @@ function _start()
invokelatest(display_error, catch_stack())
exit(1)
end
if is_interactive && have_color === true
if is_interactive && have_color
print(color_normal)
end
end
3 changes: 1 addition & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1169,11 +1169,10 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
eval(Meta.parse(code))
end
"""

io = open(pipeline(`$(julia_cmd()) -O0
--output-ji $output --output-incremental=yes
--startup-file=no --history-file=no --warn-overwrite=yes
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
--color=$(have_color ? "yes" : "no")
--eval $code_object`, stderr=stderr),
"w", stdout)
in = io.in
Expand Down
5 changes: 5 additions & 0 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ function displaysize(io::TTY)
return h, w
end

in(key_value::Pair{Symbol,Bool}, ::TTY) = key_value.first === :color && key_value.second === have_color
haskey(::TTY, key::Symbol) = key === :color
getindex(::TTY, key::Symbol) = key === :color ? have_color : throw(KeyError(key))
get(::TTY, key::Symbol, default) = key === :color ? have_color : default

### Libuv callbacks ###

## BUFFER ##
Expand Down
25 changes: 0 additions & 25 deletions base/ttyhascolor.jl

This file was deleted.

11 changes: 4 additions & 7 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ mutable struct BasicREPL <: AbstractREPL
end

outstream(r::BasicREPL) = r.terminal
hascolor(r::BasicREPL) = hascolor(r.terminal)

function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
d = REPLDisplay(repl)
Expand Down Expand Up @@ -429,14 +428,13 @@ mutable struct LineEditREPL <: AbstractREPL
interface::ModalInterface
backendref::REPLBackendRef
LineEditREPL(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,in_help,envcolors) =
new(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
new(t,true,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
in_help,envcolors,false,nothing, Options(), nothing)
end
outstream(r::LineEditREPL) = r.t
specialdisplay(r::LineEditREPL) = r.specialdisplay
specialdisplay(r::AbstractREPL) = nothing
terminal(r::LineEditREPL) = r.t
hascolor(r::LineEditREPL) = r.hascolor

LineEditREPL(t::TextTerminal, hascolor::Bool, envcolors::Bool=false) =
LineEditREPL(t, hascolor,
Expand Down Expand Up @@ -815,7 +813,7 @@ function respond(f, repl, main; pass_empty = false, suppress_on_semicolon = true
response = (catch_stack(), true)
end
hide_output = suppress_on_semicolon && ends_with_semicolon(line)
print_response(repl, response, !hide_output, hascolor(repl))
print_response(repl, response, !hide_output, Base.have_color)
end
prepare_next(repl)
reset_state(s)
Expand Down Expand Up @@ -957,7 +955,7 @@ function setup_interface(
end
hist_from_file(hp, f, hist_path)
catch
print_response(repl, (catch_stack(),true), true, hascolor(repl))
print_response(repl, (catch_stack(),true), true, Base.have_color)
println(outstream(repl))
@info "Disabling history file for this session"
repl.history_file = false
Expand Down Expand Up @@ -1157,7 +1155,6 @@ StreamREPL(stream::IO) = StreamREPL(stream, Base.text_colors[:green], Base.input
run_repl(stream::IO) = run_repl(StreamREPL(stream))

outstream(s::StreamREPL) = s.stream
hascolor(s::StreamREPL) = get(s.stream, :color, false)

answer_color(r::LineEditREPL) = r.envcolors ? Base.answer_color() : r.answer_color
answer_color(r::StreamREPL) = r.answer_color
Expand Down Expand Up @@ -1216,7 +1213,7 @@ function ends_with_semicolon(line::AbstractString)
end

function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
have_color = hascolor(repl)
have_color = Base.have_color
Base.banner(repl.stream)
d = REPLDisplay(repl)
dopushdisplay = !in(d,Base.Multimedia.displays)
Expand Down
17 changes: 16 additions & 1 deletion stdlib/REPL/src/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,22 @@ beep(t::UnixTerminal) = write(t.err_stream,"\x7")

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

hascolor(t::TTYTerminal) = Base.ttyhascolor(t.term_type)
if Sys.iswindows()
hascolor(t::TTYTerminal) = true
else
function hascolor(t::TTYTerminal)
startswith(t.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
end

# use cached value of have_color
Base.in(key_value::Pair, t::TTYTerminal) = in(key_value, pipe_writer(t))
Expand Down
4 changes: 2 additions & 2 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function fake_repl(@nospecialize(f); options::REPL.Options=REPL.Options(confirm_
Base.link_pipe!(output, reader_supports_async=true, writer_supports_async=true)
Base.link_pipe!(err, reader_supports_async=true, writer_supports_async=true)

repl = REPL.LineEditREPL(FakeTerminal(input.out, output.in, err.in, options.hascolor), options.hascolor)
repl = REPL.LineEditREPL(FakeTerminal(input.out, output.in, err.in), true)
repl.options = options

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

Expand Down