Skip to content

Commit ac70dc6

Browse files
committed
8 bit workaround
1 parent 375388d commit ac70dc6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/common.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,26 +537,26 @@ function to_256_colors(color)
537537
r6, g6, b6 = map(c -> c < 48 ? 0 : (c < 114 ? 1 : trunc(Int, (c - 35) / 40)), rgb)
538538
16 + 36r6 + 6g6 + b6 # cube 6x6x6
539539
end
540-
return UInt8(ansi)
540+
UInt8(ansi)
541541
end
542542

543-
ansi_color(col::StyledStrings.SimpleColor) = let c = col.value
543+
ansi_color(color::StyledStrings.SimpleColor)::ColorType = let c = color.value
544544
if COLORMODE[] COLORMODE_24BIT
545545
if c isa Symbol
546-
c4 = get(StyledStrings.ANSI_4BIT_COLORS, c, nothing)
546+
c4 = StyledStrings.ANSI_4BIT_COLORS[c]
547547
c8 = ansi_4bit_to_8bit(UInt8(c4))
548548
return USE_LUT[] ? LUT_8BIT[c8 + 1] : THRESHOLD + c8
549549
elseif c isa StyledStrings.RGBTuple
550550
return r32(c.r) + g32(c.g) + b32(c.b)
551551
end::ColorType
552552
else # 0-255 ansi stored in a UInt32
553553
return THRESHOLD + if c isa Symbol
554-
c4 = get(StyledStrings.ANSI_4BIT_COLORS, c, nothing)
554+
c4 = StyledStrings.ANSI_4BIT_COLORS[c]
555555
ansi_4bit_to_8bit(UInt8(c4))
556556
elseif c isa StyledStrings.RGBTuple
557557
to_256_colors(c)
558558
end::UInt8
559-
end::ColorType
559+
end
560560
end
561561

562562
complement(color::UserColorType)::ColorType = complement(ansi_color(color))

src/show.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ end
145145
Base.show(io::IO, p::Plot) = _show(io, print, print_color, p)
146146

147147
function _show(end_io::IO, print_nocol, print_color, p::Plot)
148+
_have_truecolor = Base.have_truecolor
149+
Base.have_truecolor = colormode() == 24
150+
148151
buf = Base.AnnotatedIOBuffer() # buffering, for performance
149152
io_color = get(end_io, :color, false)
150153
io = IOContext(buf, :color => io_color, :displaysize => displaysize(end_io))
@@ -387,6 +390,8 @@ function _show(end_io::IO, print_nocol, print_color, p::Plot)
387390
# delayed print (buffering)
388391
print(end_io, read(seekstart(buf), Base.AnnotatedString))
389392

393+
Base.have_truecolor = _have_truecolor
394+
390395
# return the approximate image size
391396
(
392397
h_ttl + 1 + nr + 1 + h_lbl, # +1 for borders

0 commit comments

Comments
 (0)