Skip to content

Commit 89759f4

Browse files
Kenoclaude
andcommitted
Adapt to current_terminfo becoming a OncePerProcess
Julia base has changed current_terminfo from a simple global variable to a OncePerProcess type. This commit updates all usage sites to call current_terminfo() as a function instead of accessing it directly. For tests, we need to directly manipulate the OncePerProcess internal value field, which is unsafe but necessary for testing different terminal configurations without restarting the process. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 527a985 commit 89759f4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/io.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
171171
print(io, if face.weight (:medium, :semibold, :bold, :extrabold, :black)
172172
ANSI_STYLE_CODES.bold_weight
173173
elseif face.weight (:semilight, :light, :extralight, :thin)
174-
get(Base.current_terminfo, :dim, "")
174+
get(Base.current_terminfo(), :dim, "")
175175
else # :normal
176176
ANSI_STYLE_CODES.normal_weight
177177
end)
178178
end
179179
face.slant == lastface.slant ||
180-
if haskey(Base.current_terminfo, :enter_italics_mode)
180+
if haskey(Base.current_terminfo(), :enter_italics_mode)
181181
print(io, ifelse(face.slant (:italic, :oblique),
182182
ANSI_STYLE_CODES.start_italics,
183183
ANSI_STYLE_CODES.end_italics))
@@ -189,8 +189,8 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
189189
# Kitty fancy underlines, see <https://sw.kovidgoyal.net/kitty/underlines>
190190
# Supported in Kitty, VTE, iTerm2, Alacritty, and Wezterm.
191191
face.underline == lastface.underline ||
192-
if haskey(Base.current_terminfo, :set_underline_style) ||
193-
get(Base.current_terminfo, :can_style_underline, false)
192+
if haskey(Base.current_terminfo(), :set_underline_style) ||
193+
get(Base.current_terminfo(), :can_style_underline, false)
194194
if face.underline isa Tuple # Color and style
195195
color, style = face.underline
196196
print(io, "\e[4:",
@@ -219,11 +219,11 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
219219
ANSI_STYLE_CODES.start_underline,
220220
ANSI_STYLE_CODES.end_underline))
221221
end
222-
face.strikethrough == lastface.strikethrough || !haskey(Base.current_terminfo, :smxx) ||
222+
face.strikethrough == lastface.strikethrough || !haskey(Base.current_terminfo(), :smxx) ||
223223
print(io, ifelse(face.strikethrough === true,
224224
ANSI_STYLE_CODES.start_strikethrough,
225225
ANSI_STYLE_CODES.end_strikethrough))
226-
face.inverse == lastface.inverse || !haskey(Base.current_terminfo, :enter_reverse_mode) ||
226+
face.inverse == lastface.inverse || !haskey(Base.current_terminfo(), :enter_reverse_mode) ||
227227
print(io, ifelse(face.inverse === true,
228228
ANSI_STYLE_CODES.start_reverse,
229229
ANSI_STYLE_CODES.end_reverse))

test/runtests.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ const vt100 = Base.TermInfo(read(joinpath(@__DIR__, "terminfos", "vt100"), Base.
2020
const fancy_term = Base.TermInfo(read(joinpath(@__DIR__, "terminfos", "fancy"), Base.TermInfoRaw))
2121

2222
function with_terminfo(fn::Function, tinfo::Base.TermInfo)
23-
prev_terminfo = getglobal(Base, :current_terminfo)
23+
# WARNING: Directly modifying the value inside OncePerProcess is EXTREMELY UNSAFE
24+
# and should NEVER be done in production code. This is ONLY valid for this specific
25+
# test scenario where we need to temporarily override terminfo for testing purposes.
26+
# The proper way would be to use environment variables and restart the process.
27+
prev_terminfo = Base.current_terminfo()
2428
prev_truecolor = getglobal(Base, :have_truecolor)
2529
try
26-
setglobal!(Base, :current_terminfo, tinfo)
30+
# UNSAFE: Direct modification of OncePerProcess internals
31+
Base.current_terminfo.value = tinfo
2732
setglobal!(Base, :have_truecolor, haskey(tinfo, :setrgbf))
2833
fn()
2934
finally
30-
setglobal!(Base, :current_terminfo, prev_terminfo)
35+
# UNSAFE: Restore the original value
36+
Base.current_terminfo.value = prev_terminfo
3137
setglobal!(Base, :have_truecolor, prev_truecolor)
3238
end
3339
end

0 commit comments

Comments
 (0)