Skip to content

Commit 72e2c45

Browse files
authored
Make current_terminfo a OncePerProcess (JuliaLang#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)
1 parent 41613c2 commit 72e2c45

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

base/client.jl

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

273-
# load terminfo in for styled printing
274-
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
275-
global current_terminfo = load_terminfo(term_env)
276-
277273
# load ~/.julia/config/startup.jl file
278274
if startup
279275
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") ||
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1762267d32633457c7c64067c1c9d871
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
72ca1b52b8f0c4e3d3ca58526cd34a3f1486c4fe373930bf513570f056700cddc65a4666d5b7767305b115ec0352639c4caaf03b9378911d596f6add3cbb762b

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.

stdlib/StyledStrings.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
STYLEDSTRINGS_BRANCH = main
2-
STYLEDSTRINGS_SHA1 = 3fe829fcf611b5fefaefb64df7e61f2ae82db117
2+
STYLEDSTRINGS_SHA1 = 1aafc2f3abb6a977ee36a87206f9ce6446a8ae86
33
STYLEDSTRINGS_GIT_URL := https://github.com/JuliaLang/StyledStrings.jl.git
44
STYLEDSTRINGS_TAR_URL = https://api.github.com/repos/JuliaLang/StyledStrings.jl/tarball/$1

0 commit comments

Comments
 (0)