Skip to content

Commit

Permalink
[WIP] Add support for ANSI colors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kimikage committed Oct 29, 2020
1 parent d06fa07 commit 2eb7443
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
with:
version: '1.5'
- name: Install dependencies
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
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();'
- name: Build and check documentation
run: julia --color=yes --project=docs/ docs/make.jl
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ branches:
- /^release-.*$/
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/

script:
- | # FIXME: use default script
julia --project -e '
using Pkg
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
Pkg.instantiate()
Pkg.test(; coverage=true)
'
after_success:
- if [ -f test/quietly.log ]; then cat test/quietly.log; fi
- if [[ $TRAVIS_JULIA_VERSION = 1.1 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then
Expand All @@ -29,13 +37,14 @@ jobs:
include:
- stage: "Additional tests"
script:
- julia --project=test/themes -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
- 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()))'
- julia --project=test/themes test/themes/themes.jl
name: "Themes"
- script:
- |
julia --project=test/examples -e '
using Pkg
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
Pkg.instantiate()
Pkg.develop(PackageSpec(path=pwd()))
Pkg.add(["IOCapture", "DocumenterMarkdown"])
Expand All @@ -44,12 +53,12 @@ jobs:
name: "PDF/LaTeX backend"
- stage: "Documentation"
script:
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- 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()'
- julia --project=docs/ docs/make.jl skiplinks
name: "HTML"
after_success: skip
- script:
- julia --project=docs/pdf/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- 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()'
- julia --project=docs/pdf/ docs/pdf/make.jl
name: "PDF"
after_success: skip
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.25.3"

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

[compat]
AnsiColoredPrinters = "0.1"
DocStringExtensions = "0.4, 0.5, 0.6, 0.7, 0.8"
IOCapture = "0.1"
IOCapture = "0.1.1"
JSON = "0.19, 0.20, 0.21"
julia = "1"

Expand Down
2 changes: 2 additions & 0 deletions assets/html/scss/documenter-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ html.theme--#{$themename} {
// }
// }

@import "documenter/ansicolors";

// FIXME: Hack to get a proper theme for highlight.js in the Darkly theme
@import "highlightjs/a11y-dark";
// Also, a11y-dark does not highlight string interpolation properly.
Expand Down
2 changes: 2 additions & 0 deletions assets/html/scss/documenter-light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@import "documenter/patches";
@import "documenter/layout/all";

@import "documenter/ansicolors";

// Workaround to compile in highlightjs theme, so that we could have different
// themes for both
@import "highlightjs/default"
181 changes: 181 additions & 0 deletions assets/html/scss/documenter/_ansicolors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@

$ansi-black: #111 !default;
$ansi-red: #944 !default;
$ansi-green: #073 !default;
$ansi-yellow: #870 !default;
$ansi-blue: #15a !default;
$ansi-magenta:#94a !default;
$ansi-cyan: #08a !default;
$ansi-white: #ddd !default;

$ansi-light-black: #888 !default;
$ansi-light-red: #d57 !default;
$ansi-light-green: #2a5 !default;
$ansi-light-yellow: #d94 !default;
$ansi-light-blue: #08d !default;
$ansi-light-magenta:#b8d !default;
$ansi-light-cyan: #0bc !default;
$ansi-light-white: #eee !default;

span {
&.sgr1 {
font-weight: bolder;
}

&.sgr2 {
font-weight: lighter;
}

&.sgr3 {
font-style: italic;
}

&.sgr4 {
text-decoration: underline;
}

&.sgr7 {
color: $body-background-color;
background-color: $text;
}

&.sgr8 {
color: transparent;

span {
color: transparent;
}
}

&.sgr9 {
text-decoration: line-through;
}

&.sgr30 {
color: $ansi-black
}

&.sgr31 {
color: $ansi-red
}

&.sgr32 {
color: $ansi-green
}

&.sgr33 {
color: $ansi-yellow;
}

&.sgr34 {
color: $ansi-blue;
}

&.sgr35 {
color: $ansi-magenta;
}

&.sgr36 {
color: $ansi-cyan;
}

&.sgr37 {
color: $ansi-white;
}

&.sgr40 {
background-color: $ansi-black;
}

&.sgr41 {
background-color: $ansi-red;
}

&.sgr42 {
background-color: $ansi-green;
}

&.sgr43 {
background-color: $ansi-yellow;
}

&.sgr44 {
background-color: $ansi-blue;
}

&.sgr45 {
background-color: $ansi-magenta;
}

&.sgr46 {
background-color: $ansi-cyan;
}

&.sgr47 {
background-color: $ansi-white;
}

&.sgr90 {
color: $ansi-light-black;
}

&.sgr91 {
color: $ansi-light-red;
}

&.sgr92 {
color: $ansi-light-green;
}

&.sgr93 {
color: $ansi-light-yellow;
}

&.sgr94 {
color: $ansi-light-blue;
}

&.sgr95 {
color: $ansi-light-magenta;
}

&.sgr96 {
color: $ansi-light-cyan
}

&.sgr97 {
color: $ansi-light-white;
}

&.sgr100 {
background-color: $ansi-light-black;
}

&.sgr101 {
background-color: $ansi-light-red;
}

&.sgr102 {
background-color: $ansi-light-green;
}

&.sgr103 {
background-color: $ansi-light-yellow;
}

&.sgr104 {
background-color: $ansi-light-blue;
}

&.sgr105 {
background-color: $ansi-light-magenta;
}

&.sgr106 {
background-color: $ansi-light-cyan;
}

&.sgr107 {
background-color: $ansi-light-white;
}
}
81 changes: 81 additions & 0 deletions assets/html/themes/documenter-dark.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2eb7443

Please sign in to comment.