Skip to content

Commit

Permalink
Remove DCS-based TTY truecolor test
Browse files Browse the repository at this point in the history
The idea is still sound, but the REPL stdlib is not available in Base,
and REPL.Terminals.raw! is non-trivial. Since this is the final
fallback, and it's also been a bit flakey on various terminal emulators,
we'll just remove it for now.
  • Loading branch information
tecosaur committed Aug 8, 2023
1 parent 3068818 commit 15801b5
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions base/terminfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,36 +274,12 @@ is set to either `"truecolor"` or `"24bit"`.
As a fallback, first on unix systems the `colors` terminal capability is checked
— should more than 256 colors be reported, this is taken to signify 24-bit
support. Lastly, the color is attempted to be set to `#010203` and then the
current color queried via the DCS (Device Control String) sequence `\$qm`. If
the output contains `":1:2:3"` this is taken to signify 24-bit support.
If the fallbacks are used, the `"COLORTERM"` entry in `ENV` is updated according
to the result. This ensures that frequent calls will only potentially be slow
the first time.
support.
"""
function ttyhastruecolor()
function test24bitcolor_dcs()
REPL.Terminals.raw!(REPL.TerminalMenus.terminal, true)
print(stdout, "\e[48;2;1;2;3m\eP\$qm\e\\\e[m")
flush(stdout)
# Some terminals are bad and haven't got DCS sequence support,
# if we don't see a response from stdin we need to abort.
output = @task readuntil(stdin, 'm')
schedule(output)
Timer(0.1) do _
istaskdone(output) || Base.throwto(output, InterruptException())
end
color::String = try
fetch(output)
catch _ "" end
REPL.Terminals.raw!(REPL.TerminalMenus.terminal, false)
occursin(":1:2:3", color)
end
get(ENV, "COLORTERM", "") ("truecolor", "24bit") ||
@static if Sys.isunix()
get(current_terminfo, :colors, 0) > 256 ||
isinteractive() && test24bitcolor_dcs()
get(current_terminfo, :colors, 0) > 256
else
false
end
Expand Down

0 comments on commit 15801b5

Please sign in to comment.