Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load user-customisations lazily #79

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tecosaur marked this conversation as resolved.
Show resolved Hide resolved
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
Loading