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
12 changes: 6 additions & 6 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
print(io, if face.weight ∈ (:medium, :semibold, :bold, :extrabold, :black)
ANSI_STYLE_CODES.bold_weight
elseif face.weight ∈ (:semilight, :light, :extralight, :thin)
get(Base.current_terminfo, :dim, "")
get(Base.current_terminfo(), :dim, "")
else # :normal
ANSI_STYLE_CODES.normal_weight
end)
end
face.slant == lastface.slant ||
if haskey(Base.current_terminfo, :enter_italics_mode)
if haskey(Base.current_terminfo(), :enter_italics_mode)
print(io, ifelse(face.slant ∈ (:italic, :oblique),
ANSI_STYLE_CODES.start_italics,
ANSI_STYLE_CODES.end_italics))
Expand All @@ -189,8 +189,8 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
# Kitty fancy underlines, see <https://sw.kovidgoyal.net/kitty/underlines>
# Supported in Kitty, VTE, iTerm2, Alacritty, and Wezterm.
face.underline == lastface.underline ||
if haskey(Base.current_terminfo, :set_underline_style) ||
get(Base.current_terminfo, :can_style_underline, false)
if haskey(Base.current_terminfo(), :set_underline_style) ||
get(Base.current_terminfo(), :can_style_underline, false)
if face.underline isa Tuple # Color and style
color, style = face.underline
print(io, "\e[4:",
Expand Down Expand Up @@ -219,11 +219,11 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
ANSI_STYLE_CODES.start_underline,
ANSI_STYLE_CODES.end_underline))
end
face.strikethrough == lastface.strikethrough || !haskey(Base.current_terminfo, :smxx) ||
face.strikethrough == lastface.strikethrough || !haskey(Base.current_terminfo(), :smxx) ||
print(io, ifelse(face.strikethrough === true,
ANSI_STYLE_CODES.start_strikethrough,
ANSI_STYLE_CODES.end_strikethrough))
face.inverse == lastface.inverse || !haskey(Base.current_terminfo, :enter_reverse_mode) ||
face.inverse == lastface.inverse || !haskey(Base.current_terminfo(), :enter_reverse_mode) ||
print(io, ifelse(face.inverse === true,
ANSI_STYLE_CODES.start_reverse,
ANSI_STYLE_CODES.end_reverse))
Expand Down
17 changes: 11 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ const vt100 = Base.TermInfo(read(joinpath(@__DIR__, "terminfos", "vt100"), Base.
const fancy_term = Base.TermInfo(read(joinpath(@__DIR__, "terminfos", "fancy"), Base.TermInfoRaw))

function with_terminfo(fn::Function, tinfo::Base.TermInfo)
prev_terminfo = getglobal(Base, :current_terminfo)
# HACK: Directly modifying the value inside `Base.current_terminfo`
# (a `OncePerProcess`) as we do here relies on private implementation
# details, which is ill-advised outside of low-stakes testing scenarios.
# This is a fragile shortcut to avoid modifying the environment and
# starting a process.
prev_terminfo = Base.current_terminfo()
prev_truecolor = getglobal(Base, :have_truecolor)
try
setglobal!(Base, :current_terminfo, tinfo)
setglobal!(Base, :have_truecolor, haskey(tinfo, :setrgbf))
@lock Base.current_terminfo.lock try
Base.current_terminfo.value = tinfo
setglobal!(Base, :have_truecolor, haskey(tinfo, :setrgbf))
fn()
finally
setglobal!(Base, :current_terminfo, prev_terminfo)
setglobal!(Base, :have_truecolor, prev_truecolor)
Base.current_terminfo.value = prev_terminfo
setglobal!(Base, :have_truecolor, prev_truecolor)
end
end

Expand Down
Loading