Skip to content

Commit 35a3cdf

Browse files
committed
Load user-customisations lazily
This is primarily motivated by reducing the amount of work that trimming is unable to remove.
1 parent 9802b6c commit 35a3cdf

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/src/internals.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ StyledStrings.resetfaces!
2525
StyledStrings.termcolor
2626
StyledStrings.termcolor24bit
2727
StyledStrings.termcolor8bit
28+
StyledStrings.load_customisations!
2829
```
2930

3031
## Styled Markup parsing

src/StyledStrings.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,29 @@ include("legacy.jl")
1616

1717
using .StyledMarkup
1818

19-
function __init__()
19+
const HAVE_LOADED_CUSTOMISATIONS = Base.Threads.Atomic{Bool}(false)
20+
21+
"""
22+
load_customisations!(; force::Bool=false)
23+
24+
Load customisations from the user's `faces.toml` file, if it exists as well as
25+
the current environment.
26+
27+
This function should be called before producing any output in situations where
28+
the user's customisations should be considered.
29+
30+
Unless `force` is set, customisations are only applied when this function is
31+
called for the first time, and subsequent calls are a no-op.
32+
"""
33+
function load_customisations!(; force::Bool=false)
34+
!force && HAVE_LOADED_CUSTOMISATIONS[] && return
2035
if !isempty(DEPOT_PATH)
2136
userfaces = joinpath(first(DEPOT_PATH), "config", "faces.toml")
2237
isfile(userfaces) && loaduserfaces!(userfaces)
2338
end
2439
Legacy.load_env_colors!()
40+
HAVE_LOADED_CUSTOMISATIONS[] = true
41+
nothing
2542
end
2643

2744
if Base.generating_output()

0 commit comments

Comments
 (0)