Skip to content

Commit 56a1e81

Browse files
committed
[WIP] Add support for ANSI colors
This changes: - add support for a keyword argument `ansicolor` in the `@example`/`@repl` block - for per-block setting to overide the default setting - the default uses the `:color` property of `stdout` (determined by `--color`) - use the `ansicolor` option for the `:color` property of output - translate "text/plain" output with ANSI escape codes in `HTMLWriter` - add styles for ANSI colors to the default themes
1 parent d06fa07 commit 56a1e81

File tree

13 files changed

+567
-34
lines changed

13 files changed

+567
-34
lines changed

.github/workflows/linkcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ jobs:
2626
with:
2727
version: '1.5'
2828
- name: Install dependencies
29-
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
29+
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.add(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate();'
3030
- name: Build and check documentation
3131
run: julia --color=yes --project=docs/ docs/make.jl

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ branches:
1616
- /^release-.*$/
1717
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
1818

19+
script:
20+
- | # FIXME: use default script
21+
julia --project -e '
22+
using Pkg
23+
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
24+
Pkg.instantiate()
25+
Pkg.test(; coverage=true)
26+
'
1927
after_success:
2028
- if [ -f test/quietly.log ]; then cat test/quietly.log; fi
2129
- if [[ $TRAVIS_JULIA_VERSION = 1.1 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then
@@ -29,13 +37,14 @@ jobs:
2937
include:
3038
- stage: "Additional tests"
3139
script:
32-
- julia --project=test/themes -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
40+
- julia --project=test/themes -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
3341
- julia --project=test/themes test/themes/themes.jl
3442
name: "Themes"
3543
- script:
3644
- |
3745
julia --project=test/examples -e '
3846
using Pkg
47+
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
3948
Pkg.instantiate()
4049
Pkg.develop(PackageSpec(path=pwd()))
4150
Pkg.add(["IOCapture", "DocumenterMarkdown"])
@@ -44,12 +53,12 @@ jobs:
4453
name: "PDF/LaTeX backend"
4554
- stage: "Documentation"
4655
script:
47-
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
56+
- julia --project=docs/ -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
4857
- julia --project=docs/ docs/make.jl skiplinks
4958
name: "HTML"
5059
after_success: skip
5160
- script:
52-
- julia --project=docs/pdf/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
61+
- julia --project=docs/pdf/ -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
5362
- julia --project=docs/pdf/ docs/pdf/make.jl
5463
name: "PDF"
5564
after_success: skip

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
version = "0.25.3"
44

55
[deps]
6+
AnsiColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
67
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
78
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
89
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
@@ -17,8 +18,9 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1718
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1819

1920
[compat]
21+
AnsiColoredPrinters = "0.1"
2022
DocStringExtensions = "0.4, 0.5, 0.6, 0.7, 0.8"
21-
IOCapture = "0.1"
23+
IOCapture = "0.1.1"
2224
JSON = "0.19, 0.20, 0.21"
2325
julia = "1"
2426

assets/html/scss/documenter-dark.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ html.theme--#{$themename} {
9090
// }
9191
// }
9292

93+
@import "documenter/ansicolors";
94+
9395
// FIXME: Hack to get a proper theme for highlight.js in the Darkly theme
9496
@import "highlightjs/a11y-dark";
9597
// Also, a11y-dark does not highlight string interpolation properly.

assets/html/scss/documenter-light.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
@import "documenter/patches";
2020
@import "documenter/layout/all";
2121

22+
@import "documenter/ansicolors";
23+
2224
// Workaround to compile in highlightjs theme, so that we could have different
2325
// themes for both
2426
@import "highlightjs/default"
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
$ansi-black: $black-ter !default;
2+
$ansi-red: null !default;
3+
$ansi-green: null !default;
4+
$ansi-yellow: null !default;
5+
$ansi-blue: null !default;
6+
$ansi-magenta: null !default;
7+
$ansi-cyan: null !default;
8+
$ansi-white: $grey-lighter !default;
9+
10+
$ansi-light-black: null !default;
11+
$ansi-light-red: null !default;
12+
$ansi-light-green: null !default;
13+
$ansi-light-yellow: null !default;
14+
$ansi-light-blue: null !default;
15+
$ansi-light-magenta: null !default;
16+
$ansi-light-cyan: null !default;
17+
$ansi-light-white: $white-ter !default;
18+
19+
@if $documenter-is-dark-theme {
20+
$ansi-red: $red !default;
21+
$ansi-green: $green !default;
22+
$ansi-yellow: $yellow !default;
23+
$ansi-blue: $blue !default;
24+
$ansi-magenta: $purple !default;
25+
$ansi-cyan: $turquoise !default;
26+
27+
$ansi-light-black: $grey-light !default;
28+
29+
$ansi-light-red: lighten($ansi-red, 15) !default;
30+
$ansi-light-green: lighten($ansi-green, 15) !default;
31+
$ansi-light-yellow: lighten($ansi-yellow, 10) !default;
32+
$ansi-light-blue: lighten($ansi-blue, 15) !default;
33+
$ansi-light-magenta: lighten($ansi-magenta, 10) !default;
34+
$ansi-light-cyan: lighten($ansi-cyan, 15) !default;
35+
}
36+
37+
@else {
38+
$ansi-light-red: $red !default;
39+
$ansi-light-green: $green !default;
40+
$ansi-light-yellow: $yellow !default;
41+
$ansi-light-blue: $blue !default;
42+
$ansi-light-magenta: $purple !default;
43+
$ansi-light-cyan: $turquoise !default;
44+
45+
$ansi-light-black: $grey !default;
46+
47+
$ansi-red: darken($ansi-light-red, 10) !default;
48+
$ansi-green: darken($ansi-light-green, 10) !default;
49+
$ansi-yellow: darken($ansi-light-yellow, 18) !default;
50+
$ansi-blue: darken($ansi-light-blue, 10) !default;
51+
$ansi-magenta: darken($ansi-light-magenta, 15) !default;
52+
$ansi-cyan: darken($ansi-light-cyan, 10) !default;
53+
}
54+
55+
span {
56+
&.sgr1 {
57+
font-weight: bolder;
58+
}
59+
60+
&.sgr2 {
61+
font-weight: lighter;
62+
}
63+
64+
&.sgr3 {
65+
font-style: italic;
66+
}
67+
68+
&.sgr4 {
69+
text-decoration: underline;
70+
}
71+
72+
&.sgr7 {
73+
color: $body-background-color;
74+
background-color: $text;
75+
}
76+
77+
&.sgr8 {
78+
color: transparent;
79+
80+
span {
81+
color: transparent;
82+
}
83+
}
84+
85+
&.sgr9 {
86+
text-decoration: line-through;
87+
}
88+
89+
&.sgr30 {
90+
color: $ansi-black;
91+
}
92+
93+
&.sgr31 {
94+
color: $ansi-red;
95+
}
96+
97+
&.sgr32 {
98+
color: $ansi-green;
99+
}
100+
101+
&.sgr33 {
102+
color: $ansi-yellow;
103+
}
104+
105+
&.sgr34 {
106+
color: $ansi-blue;
107+
}
108+
109+
&.sgr35 {
110+
color: $ansi-magenta;
111+
}
112+
113+
&.sgr36 {
114+
color: $ansi-cyan;
115+
}
116+
117+
&.sgr37 {
118+
color: $ansi-white;
119+
}
120+
121+
&.sgr40 {
122+
background-color: $ansi-black;
123+
}
124+
125+
&.sgr41 {
126+
background-color: $ansi-red;
127+
}
128+
129+
&.sgr42 {
130+
background-color: $ansi-green;
131+
}
132+
133+
&.sgr43 {
134+
background-color: $ansi-yellow;
135+
}
136+
137+
&.sgr44 {
138+
background-color: $ansi-blue;
139+
}
140+
141+
&.sgr45 {
142+
background-color: $ansi-magenta;
143+
}
144+
145+
&.sgr46 {
146+
background-color: $ansi-cyan;
147+
}
148+
149+
&.sgr47 {
150+
background-color: $ansi-white;
151+
}
152+
153+
&.sgr90 {
154+
color: $ansi-light-black;
155+
}
156+
157+
&.sgr91 {
158+
color: $ansi-light-red;
159+
}
160+
161+
&.sgr92 {
162+
color: $ansi-light-green;
163+
}
164+
165+
&.sgr93 {
166+
color: $ansi-light-yellow;
167+
}
168+
169+
&.sgr94 {
170+
color: $ansi-light-blue;
171+
}
172+
173+
&.sgr95 {
174+
color: $ansi-light-magenta;
175+
}
176+
177+
&.sgr96 {
178+
color: $ansi-light-cyan;
179+
}
180+
181+
&.sgr97 {
182+
color: $ansi-light-white;
183+
}
184+
185+
&.sgr100 {
186+
background-color: $ansi-light-black;
187+
}
188+
189+
&.sgr101 {
190+
background-color: $ansi-light-red;
191+
}
192+
193+
&.sgr102 {
194+
background-color: $ansi-light-green;
195+
}
196+
197+
&.sgr103 {
198+
background-color: $ansi-light-yellow;
199+
}
200+
201+
&.sgr104 {
202+
background-color: $ansi-light-blue;
203+
}
204+
205+
&.sgr105 {
206+
background-color: $ansi-light-magenta;
207+
}
208+
209+
&.sgr106 {
210+
background-color: $ansi-light-cyan;
211+
}
212+
213+
&.sgr107 {
214+
background-color: $ansi-light-white;
215+
}
216+
}

assets/html/themes/documenter-dark.css

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)