Skip to content

Commit ad32b08

Browse files
KenoKristofferC
authored andcommitted
Make current_terminfo a OncePerProcess (#58854)
There seems to be no reason to always load this unconditionally - especially since it's in the critical startup path. If we never print colored output or our IO is not a TTY, we don't need to load this at all. While we're at it, remove the `term_type` argument to `ttyhascolor`, which didn't work as advertised anyway, since it still looked at the current_terminfo. If clients want to do a full TermInfo check, they can do that explicitly. (Written by Claude Code) (cherry picked from commit 72e2c45)
1 parent 644f40e commit ad32b08

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

base/client.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ function exec_options(opts)
267267
interactiveinput = (repl || is_interactive::Bool) && isa(stdin, TTY)
268268
is_interactive::Bool |= interactiveinput
269269

270-
# load terminfo in for styled printing
271-
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
272-
global current_terminfo = load_terminfo(term_env)
273-
274270
# load ~/.julia/config/startup.jl file
275271
if startup
276272
try

base/terminfo.jl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,24 @@ end
303303
"""
304304
The terminfo of the current terminal.
305305
"""
306-
current_terminfo::TermInfo = TermInfo()
306+
const current_terminfo = OncePerProcess{TermInfo}() do
307+
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
308+
terminfo = load_terminfo(term_env)
309+
# Ensure setaf is set for xterm terminals
310+
if !haskey(terminfo, :setaf) && startswith(term_env, "xterm")
311+
# For xterm-like terminals without setaf, add a reasonable default
312+
terminfo.strings[:setaf] = "\e[3%p1%dm"
313+
end
314+
return terminfo
315+
end
307316

308317
# Legacy/TTY methods and the `:color` parameter
309318

310319
if Sys.iswindows()
311-
ttyhascolor(term_type = nothing) = true
320+
ttyhascolor() = true
312321
else
313-
function ttyhascolor(term_type = get(ENV, "TERM", ""))
314-
startswith(term_type, "xterm") ||
315-
haskey(current_terminfo, :setaf)
322+
function ttyhascolor()
323+
haskey(current_terminfo(), :setaf)
316324
end
317325
end
318326

@@ -352,9 +360,9 @@ Multiple conditions are taken as signifying truecolor support, specifically any
352360
function ttyhastruecolor()
353361
# Lasciate ogne speranza, voi ch'intrate
354362
get(ENV, "COLORTERM", "") ("truecolor", "24bit") ||
355-
get(current_terminfo, :RGB, false) || get(current_terminfo, :Tc, false) ||
356-
(haskey(current_terminfo, :setrgbf) && haskey(current_terminfo, :setrgbb)) ||
357-
@static if Sys.isunix() get(current_terminfo, :colors, 0) > 256 else false end ||
363+
get(current_terminfo(), :RGB, false) || get(current_terminfo(), :Tc, false) ||
364+
(haskey(current_terminfo(), :setrgbf) && haskey(current_terminfo(), :setrgbb)) ||
365+
@static if Sys.isunix() get(current_terminfo(), :colors, 0) > 256 else false end ||
358366
(Sys.iswindows() && Sys.windows_version() v"10.0.14931") || # See <https://devblogs.microsoft.com/commandline/24-bit-color-in-the-windows-console/>
359367
something(tryparse(Int, get(ENV, "VTE_VERSION", "")), 0) >= 3600 || # Per GNOME bug #685759 <https://bugzilla.gnome.org/show_bug.cgi?id=685759>
360368
haskey(ENV, "XTERM_VERSION") ||

deps/checksums/StyledStrings-3fe829fcf611b5fefaefb64df7e61f2ae82db117.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/StyledStrings-3fe829fcf611b5fefaefb64df7e61f2ae82db117.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)