Skip to content

Commit

Permalink
fix precompilation and init (#399)
Browse files Browse the repository at this point in the history
* fix precompilation

* lts compat

* fix
  • Loading branch information
t-bltg authored Nov 10, 2024
1 parent f9184cf commit 389a27b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/UnicodePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,15 @@ include("interface/polarplot.jl")
include("interface/imageplot.jl")

function __init__()
if (terminal_24bit() || forced_24bit()) && !forced_8bit()
truecolors!()
USE_LUT[] ? brightcolors!() : faintcolors!()
else
colors256!()
faintcolors!()
end
forced_24bit() && return init_24bit()
forced_8bit() && return init_8bit()
get_have_truecolor() ? init_24bit() : init_8bit()
nothing
end

# COV_EXCL_START
function precompile_workload(io::IO = IOContext(devnull, :color => Base.get_have_color()))
__init__()
surf(x, y) = sinc((x^2 + y^2))
for T in ( # most common types
Float64,
Expand Down
21 changes: 19 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,25 @@ end
brightcolors!() = COLOR_CYCLE[] = COLOR_CYCLE_BRIGHT
faintcolors!() = COLOR_CYCLE[] = COLOR_CYCLE_FAINT

# see gist.github.com/XVilka/8346728#checking-for-colorterm
terminal_24bit() = lowercase(get(ENV, "COLORTERM", "")) ("24bit", "truecolor")
function init_24bit()
truecolors!()
USE_LUT[] ? brightcolors!() : faintcolors!()
nothing
end

function init_8bit()
colors256!()
faintcolors!()
nothing
end

get_have_truecolor() =
if isdefined(Base, :get_have_truecolor)
Base.get_have_truecolor()
else
# see gist.github.com/XVilka/8346728#checking-for-colorterm
lowercase(get(ENV, "COLORTERM", "")) ("24bit", "truecolor")
end

# specific to UnicodePlots
forced_24bit() = lowercase(get(ENV, "UP_COLORMODE", "")) ("24", "24bit", "truecolor")
Expand Down

0 comments on commit 389a27b

Please sign in to comment.