Skip to content

Commit 04abf3e

Browse files
committed
Correct ANSI printing of alternating bold/dim
The way that bold/dim work in TTYs is a little weird. They're two channels of information (text can be bold and dim, just one, or either), but also sort of one channel of information (weight). Dim can also be a light font weight, which is how we frame/interpret it here. To avoid unexpected behaviour, we clear the bold/dim status before re-setting it when changing between the two.
1 parent 3fe829f commit 04abf3e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/io.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ termcolor(io::IO, ::Nothing, category::Char) =
147147

148148
const ANSI_STYLE_CODES = (
149149
bold_weight = "\e[1m",
150-
dim_weight = "\e[2m",
150+
dim_weight = "\e[2m", # Unused
151151
normal_weight = "\e[22m",
152152
start_italics = "\e[3m",
153153
end_italics = "\e[23m",
@@ -164,14 +164,18 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
164164
termcolor(io, face.foreground, '3')
165165
face.background == lastface.background ||
166166
termcolor(io, face.background, '4')
167-
face.weight == lastface.weight ||
167+
face.weight == lastface.weight || begin
168+
if lastface.weight != :normal && face.weight != :normal
169+
print(io, ANSI_STYLE_CODES.normal_weight) # Reset before changing
170+
end
168171
print(io, if face.weight (:medium, :semibold, :bold, :extrabold, :black)
169172
ANSI_STYLE_CODES.bold_weight
170173
elseif face.weight (:semilight, :light, :extralight, :thin)
171174
get(Base.current_terminfo, :dim, "")
172175
else # :normal
173176
ANSI_STYLE_CODES.normal_weight
174177
end)
178+
end
175179
face.slant == lastface.slant ||
176180
if haskey(Base.current_terminfo, :enter_italics_mode)
177181
print(io, ifelse(face.slant (:italic, :oblique),

0 commit comments

Comments
 (0)