Skip to content

Commit 42de50c

Browse files
committed
Use PrecompileTools for reduced latency
1 parent 91e63fb commit 42de50c

File tree

3 files changed

+53
-43
lines changed

3 files changed

+53
-43
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ authors = ["TEC <[email protected]>"]
44
version = "1.0.2"
55

66
[deps]
7+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
78
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
89

910
[compat]
1011
# 1.0 - 1.10, but the range version isn't supported till 1.4
1112
# In 1.11+ precompilation fails due to method overwriting.
13+
PrecompileTools = "1.2"
1214
julia = "~1.0, ~1.1, ~1.2, ~1.3, ~1.4, ~1.5, ~1.6, ~1.7, ~1.8, ~1.9, ~1.10"
1315

1416
[extras]

src/StyledStrings.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module StyledStrings
44

5+
56
export @styled_str
67

78
include("compat.jl")
@@ -54,8 +55,6 @@ function __init__()
5455
load_customisations!()
5556
end
5657

57-
if generating_output()
58-
include("precompile.jl")
59-
end
58+
include("precompile.jl")
6059

6160
end

src/precompile.jl

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
1-
colorio = IOContext(IOBuffer(), :color => true)
2-
3-
print(colorio, styled"just a string")
4-
Base.escape_string(colorio, styled"just a string")
5-
print(colorio, styled"{red:with color}")
6-
print(colorio, styled"{face=$(Face(foreground=:red)):with color}")
7-
print(colorio, styled"{(foreground=red):with color}")
8-
show(colorio, MIME("text/plain"), styled"{red:with color}")
9-
show(colorio, MIME("text/html"), styled"{red:with color}")
10-
print(colorio, styled"{red:with color}"[1])
11-
print(colorio, styled"{underline=(blue,curly):more styling}")
12-
13-
convert(StyledStrings.SimpleColor, (r = 0x01, g = 0x02, b = 0x03))
14-
convert(StyledStrings.SimpleColor, 0x010203)
15-
convert(StyledStrings.SimpleColor, :namedcolor)
16-
tryparse(StyledStrings.SimpleColor, "blue")
17-
parse(StyledStrings.SimpleColor, "#010203")
18-
19-
StyledStrings.Face(nothing, nothing, nothing, nothing, nothing,
20-
nothing, nothing, nothing, nothing, [:default])
21-
StyledStrings.Face(height=2)
22-
merge(StyledStrings.Face(inherit=:blue), StyledStrings.Face(foreground=:white))
23-
StyledStrings.Face(height=2) == StyledStrings.Face(height=3)
24-
25-
show(colorio, MIME("text/plain"), StyledStrings.Face(foreground=:green))
26-
show(colorio, StyledStrings.Face(foreground=:green))
27-
28-
StyledStrings.getface()
29-
StyledStrings.getface(:red)
30-
StyledStrings.getface(styled"{red:red}", 1)
31-
32-
StyledStrings.addface!(:_precompile => Face(font="precompile"))
33-
StyledStrings.loadface!(:_precompile => Face(inverse=true))
34-
StyledStrings.loaduserfaces!(Dict{String, Any}("_precompile" =>
35-
Dict{String, Any}("strikethough" => true)))
36-
StyledStrings.resetfaces!(:_precompile)
37-
StyledStrings.resetfaces!()
38-
39-
StyledStrings.withfaces(:yellow => StyledStrings.Face(foreground=:red), :green => :blue) do
40-
println(colorio, styled"{yellow:red} and {green:blue} mixed make {magenta:purple}")
1+
using PrecompileTools: @compile_workload, @setup_workload
2+
3+
@setup_workload begin
4+
@compile_workload begin
5+
colorio = IOContext(IOBuffer(), :color => true)
6+
7+
print(colorio, styled"just a string")
8+
Base.escape_string(colorio, styled"just a string")
9+
print(colorio, styled"{red:with color}")
10+
print(colorio, styled"{face=$(Face(foreground=:red)):with color}")
11+
print(colorio, styled"{(foreground=red):with color}")
12+
show(colorio, MIME("text/plain"), styled"{red:with color}")
13+
show(colorio, MIME("text/html"), styled"{red:with color}")
14+
print(colorio, styled"{red:with color}"[1])
15+
print(colorio, styled"{underline=(blue,curly):more styling}")
16+
17+
convert(StyledStrings.SimpleColor, (r = 0x01, g = 0x02, b = 0x03))
18+
convert(StyledStrings.SimpleColor, 0x010203)
19+
convert(StyledStrings.SimpleColor, :namedcolor)
20+
tryparse(StyledStrings.SimpleColor, "blue")
21+
parse(StyledStrings.SimpleColor, "#010203")
22+
23+
StyledStrings.Face(nothing, nothing, nothing, nothing, nothing,
24+
nothing, nothing, nothing, nothing, [:default])
25+
StyledStrings.Face(height=2)
26+
merge(StyledStrings.Face(inherit=:blue), StyledStrings.Face(foreground=:white))
27+
StyledStrings.Face(height=2) == StyledStrings.Face(height=3)
28+
29+
show(colorio, MIME("text/plain"), StyledStrings.Face(foreground=:green))
30+
show(colorio, StyledStrings.Face(foreground=:green))
31+
32+
StyledStrings.getface()
33+
StyledStrings.getface(:red)
34+
StyledStrings.getface(styled"{red:red}", 1)
35+
36+
StyledStrings.addface!(:_precompile => Face(font="precompile"))
37+
StyledStrings.loadface!(:_precompile => Face(inverse=true))
38+
StyledStrings.loaduserfaces!(Dict{String, Any}("_precompile" =>
39+
Dict{String, Any}("strikethough" => true)))
40+
StyledStrings.resetfaces!(:_precompile)
41+
StyledStrings.resetfaces!()
42+
43+
StyledStrings.withfaces(:yellow => StyledStrings.Face(foreground=:red), :green => :blue) do
44+
println(colorio, styled"{yellow:red} and {green:blue} mixed make {magenta:purple}")
45+
end
46+
47+
__init__()
48+
end
49+
StyledStrings.FACES.current[] = copy(StyledStrings.FACES.default)
4150
end

0 commit comments

Comments
 (0)