Skip to content

Commit

Permalink
Load user-customisations lazily
Browse files Browse the repository at this point in the history
This is primarily motivated by reducing the amount of work that trimming
is unable to remove.
  • Loading branch information
tecosaur committed Aug 9, 2024
1 parent 9802b6c commit 6c7a8ba
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/StyledStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,29 @@ include("legacy.jl")

using .StyledMarkup

function __init__()
const HAVE_LOADED_CUSTOMISATIONS = Base.Threads.Atomic{Bool}(false)

"""
load_customisations!(; force::Bool=false)
Load customisations from the user's `faces.toml` file, if it exists as well as
the current environment.
This function should be called before producing any output in situations where
the user's customisations should be considered.
Unless `force` is set, customisations are only applied when this function is
called for the first time, and subsequent calls are a no-op.
"""
function load_customisations!(; force::Bool=false)
!force && HAVE_LOADED_CUSTOMISATIONS[] && return
if !isempty(DEPOT_PATH)
userfaces = joinpath(first(DEPOT_PATH), "config", "faces.toml")
isfile(userfaces) && loaduserfaces!(userfaces)
end
Legacy.load_env_colors!()
HAVE_LOADED_CUSTOMISATIONS[] = true
nothing
end

if Base.generating_output()
Expand Down

0 comments on commit 6c7a8ba

Please sign in to comment.