diff --git a/Project.toml b/Project.toml index 496f56e..7f4962f 100644 --- a/Project.toml +++ b/Project.toml @@ -4,11 +4,13 @@ authors = ["TEC "] version = "1.0.2" [deps] +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [compat] # 1.0 - 1.10, but the range version isn't supported till 1.4 # In 1.11+ precompilation fails due to method overwriting. +PrecompileTools = "1.2" julia = "~1.0, ~1.1, ~1.2, ~1.3, ~1.4, ~1.5, ~1.6, ~1.7, ~1.8, ~1.9, ~1.10" [extras] diff --git a/src/StyledStrings.jl b/src/StyledStrings.jl index 959d920..816450b 100644 --- a/src/StyledStrings.jl +++ b/src/StyledStrings.jl @@ -2,6 +2,7 @@ module StyledStrings + export @styled_str include("compat.jl") @@ -54,8 +55,6 @@ function __init__() load_customisations!() end -if generating_output() - include("precompile.jl") -end +include("precompile.jl") end diff --git a/src/precompile.jl b/src/precompile.jl index 8406f9a..17b69a3 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -1,41 +1,50 @@ -colorio = IOContext(IOBuffer(), :color => true) - -print(colorio, styled"just a string") -Base.escape_string(colorio, styled"just a string") -print(colorio, styled"{red:with color}") -print(colorio, styled"{face=$(Face(foreground=:red)):with color}") -print(colorio, styled"{(foreground=red):with color}") -show(colorio, MIME("text/plain"), styled"{red:with color}") -show(colorio, MIME("text/html"), styled"{red:with color}") -print(colorio, styled"{red:with color}"[1]) -print(colorio, styled"{underline=(blue,curly):more styling}") - -convert(StyledStrings.SimpleColor, (r = 0x01, g = 0x02, b = 0x03)) -convert(StyledStrings.SimpleColor, 0x010203) -convert(StyledStrings.SimpleColor, :namedcolor) -tryparse(StyledStrings.SimpleColor, "blue") -parse(StyledStrings.SimpleColor, "#010203") - -StyledStrings.Face(nothing, nothing, nothing, nothing, nothing, - nothing, nothing, nothing, nothing, [:default]) -StyledStrings.Face(height=2) -merge(StyledStrings.Face(inherit=:blue), StyledStrings.Face(foreground=:white)) -StyledStrings.Face(height=2) == StyledStrings.Face(height=3) - -show(colorio, MIME("text/plain"), StyledStrings.Face(foreground=:green)) -show(colorio, StyledStrings.Face(foreground=:green)) - -StyledStrings.getface() -StyledStrings.getface(:red) -StyledStrings.getface(styled"{red:red}", 1) - -StyledStrings.addface!(:_precompile => Face(font="precompile")) -StyledStrings.loadface!(:_precompile => Face(inverse=true)) -StyledStrings.loaduserfaces!(Dict{String, Any}("_precompile" => - Dict{String, Any}("strikethough" => true))) -StyledStrings.resetfaces!(:_precompile) -StyledStrings.resetfaces!() - -StyledStrings.withfaces(:yellow => StyledStrings.Face(foreground=:red), :green => :blue) do - println(colorio, styled"{yellow:red} and {green:blue} mixed make {magenta:purple}") +using PrecompileTools: @compile_workload, @setup_workload + +@setup_workload begin + @compile_workload begin + colorio = IOContext(IOBuffer(), :color => true) + + print(colorio, styled"just a string") + Base.escape_string(colorio, styled"just a string") + print(colorio, styled"{red:with color}") + print(colorio, styled"{face=$(Face(foreground=:red)):with color}") + print(colorio, styled"{(foreground=red):with color}") + show(colorio, MIME("text/plain"), styled"{red:with color}") + show(colorio, MIME("text/html"), styled"{red:with color}") + print(colorio, styled"{red:with color}"[1]) + print(colorio, styled"{underline=(blue,curly):more styling}") + + convert(StyledStrings.SimpleColor, (r = 0x01, g = 0x02, b = 0x03)) + convert(StyledStrings.SimpleColor, 0x010203) + convert(StyledStrings.SimpleColor, :namedcolor) + tryparse(StyledStrings.SimpleColor, "blue") + parse(StyledStrings.SimpleColor, "#010203") + + StyledStrings.Face(nothing, nothing, nothing, nothing, nothing, + nothing, nothing, nothing, nothing, [:default]) + StyledStrings.Face(height=2) + merge(StyledStrings.Face(inherit=:blue), StyledStrings.Face(foreground=:white)) + StyledStrings.Face(height=2) == StyledStrings.Face(height=3) + + show(colorio, MIME("text/plain"), StyledStrings.Face(foreground=:green)) + show(colorio, StyledStrings.Face(foreground=:green)) + + StyledStrings.getface() + StyledStrings.getface(:red) + StyledStrings.getface(styled"{red:red}", 1) + + StyledStrings.addface!(:_precompile => Face(font="precompile")) + StyledStrings.loadface!(:_precompile => Face(inverse=true)) + StyledStrings.loaduserfaces!(Dict{String, Any}("_precompile" => + Dict{String, Any}("strikethough" => true))) + StyledStrings.resetfaces!(:_precompile) + StyledStrings.resetfaces!() + + StyledStrings.withfaces(:yellow => StyledStrings.Face(foreground=:red), :green => :blue) do + println(colorio, styled"{yellow:red} and {green:blue} mixed make {magenta:purple}") + end + + __init__() + end + StyledStrings.FACES.current[] = copy(StyledStrings.FACES.default) end