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 10, 2024
1 parent 9802b6c commit 35a3cdf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ StyledStrings.resetfaces!
StyledStrings.termcolor
StyledStrings.termcolor24bit
StyledStrings.termcolor8bit
StyledStrings.load_customisations!
```

## Styled Markup parsing
Expand Down
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 35a3cdf

Please sign in to comment.