Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
faa1ea8
fixes to bright color generation
echuber2 Mar 14, 2021
15f0ad0
remove *2 on osx dull palette
echuber2 Mar 14, 2021
90e5f6e
not sure why linting failed, prompting CI test run
echuber2 Aug 31, 2021
41032ef
Merge branch 'main' into get-styles-fixes
ssbarnea Sep 1, 2021
8edc716
Merge branch 'main' into get-styles-fixes
ssbarnea Sep 1, 2021
2cef97f
lint fixes
echuber2 Sep 2, 2021
0a33f18
Merge branch 'main' into get-styles-fixes
echuber2 Sep 2, 2021
7af32b2
Merge branch 'main' into get-styles-fixes
ssbarnea Jan 27, 2022
aa7c241
Merge branch 'main' into get-styles-fixes
echuber2 Jan 31, 2022
851ff61
Merge branch 'main' into get-styles-fixes
echuber2 Feb 16, 2022
b863a1a
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 16, 2022
cf998e1
Incorporating changes suggested by Sebastian Pipping
echuber2 Feb 16, 2022
2eba9fa
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 16, 2022
f57b5c2
moving auto darken feature to unused function
echuber2 Feb 16, 2022
f5948d5
darken_bright_colors: fixing potential typos regarding indexing
echuber2 Feb 16, 2022
4eaf2ed
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 16, 2022
a90296f
update osx palette to macOS terminal basic color scheme
echuber2 Feb 16, 2022
97c3090
add osx-brighter scheme based on mac solid colors scheme
echuber2 Feb 16, 2022
9df483b
add legacy osx palette, rename alternatives
echuber2 Feb 17, 2022
d0ffa29
comments on osx palettes
echuber2 Feb 17, 2022
7174e9f
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 17, 2022
78e3b5f
encode palette hex literals in lowercase for consistency
echuber2 Feb 17, 2022
eb444cf
Revert "encode palette hex literals in lowercase for consistency"
echuber2 Feb 17, 2022
2b4c0c7
begin fixing unit tests
echuber2 Feb 17, 2022
f426465
add type signature
echuber2 Feb 17, 2022
9f3a80d
use raise from to please linter
echuber2 Feb 17, 2022
0c2d62e
remove unused darken_bright_colors function
echuber2 Feb 17, 2022
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
79 changes: 66 additions & 13 deletions ansi2html/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def index2(grey: int) -> str:
"#00ffff",
"#ffffff",
),
# Based on the "osx" palette in previous versions of ansi2html.
"osx": (
"#000000",
"#c23621",
Expand All @@ -123,8 +124,54 @@ def index2(grey: int) -> str:
"#d338d3",
"#33bbc8",
"#cbcccd",
)
* 2,
"#404040",
"#ff7661",
"#65fc64",
"#eded67",
"#896eff",
"#ff78ff",
"#73fbff",
"#ffffff",
),
# Based on the "Basic" palette in macOS Terminal.
"osx-basic": (
"#000000",
"#800000",
"#008000",
"#808000",
"#000080",
"#800080",
"#008080",
"#808080",
"#666666",
"#e60000",
"#00d900",
"#e6e600",
"#0000ff",
"#e600e6",
"#00e6e6",
"#e6e6e6",
),
# Based on the "Solid Colors" palette in macOS Terminal.
# The colors are brighter than osx-basic.
"osx-solid-colors": (
"#000000",
"#990000",
"#00a600",
"#999900",
"#0000b3",
"#b300b3",
"#00a6b3",
"#bfbfbf",
"#666666",
"#e60000",
"#00d900",
"#e6e600",
"#0000ff",
"#e600e6",
"#00e6e6",
"#e6e6e6",
),
# http://ethanschoonover.com/solarized
"solarized": (
"#262626",
Expand Down Expand Up @@ -194,7 +241,9 @@ def intensify(color: str, dark_bg: bool, amount: int = 64) -> str:


def get_styles(
dark_bg: bool = True, line_wrap: bool = True, scheme: str = "ansi2html"
dark_bg: bool = True,
line_wrap: bool = True,
scheme: str = "ansi2html",
) -> List[Rule]:
css = [
Rule(
Expand Down Expand Up @@ -224,11 +273,20 @@ def get_styles(
Rule(".ansi9", text_decoration="line-through"),
]

try:
pal = SCHEME[scheme]
except KeyError as e:
raise ValueError(f"Unsupported color scheme {scheme!r}") from e

if len(pal) < 16:
raise Exception(
f"Color scheme {scheme!r} specifies fewer than 16 colors. 16 colors are required."
)

# This is 8x2 palette of 3/4-bit color mode described at
# https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
# .ansi{30..37} is foreground
# .ansi{40..47} is background
pal = SCHEME[scheme]
for _index in range(8):
css.append(Rule(".ansi3%s" % _index, color=pal[_index]))
css.append(Rule(".inv3%s" % _index, background_color=pal[_index]))
Expand All @@ -241,19 +299,14 @@ def get_styles(
# .ansi{90..97} is foreground
# .ansi{100..107} is background
for _index in range(8):
css.append(Rule(".ansi9%s" % _index, color=intensify(pal[_index], dark_bg)))
css.append(
Rule(".inv9%s" % _index, background_color=intensify(pal[_index], dark_bg))
)
css.append(Rule(".ansi9%s" % _index, color=pal[_index + 8]))
css.append(Rule(".inv9%s" % _index, background_color=pal[_index + 8]))
for _index in range(8):
css.append(
Rule(".ansi10%s" % _index, background_color=intensify(pal[_index], dark_bg))
)
css.append(Rule(".inv10%s" % _index, color=intensify(pal[_index], dark_bg)))
css.append(Rule(".ansi10%s" % _index, background_color=pal[_index + 8]))
css.append(Rule(".inv10%s" % _index, color=pal[_index + 8]))

# This is the first 16 palette slots of 8-bit color mode described at
# https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
pal = SCHEME[scheme]
for _index in range(len(pal)):
css.append(Rule(".ansi38-%s" % _index, color=pal[_index]))
css.append(Rule(".inv38-%s" % _index, background_color=pal[_index]))
Expand Down
56 changes: 28 additions & 28 deletions tests/produce_headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,36 @@
.inv46 { color: #00aaaa; }
.ansi47 { background-color: #F5F1DE; }
.inv47 { color: #F5F1DE; }
.ansi90 { color: #404356; }
.inv90 { background-color: #404356; }
.ansi91 { color: #ea4040; }
.inv91 { background-color: #ea4040; }
.ansi92 { color: #40ea40; }
.inv92 { background-color: #40ea40; }
.ansi93 { color: #ea9540; }
.inv93 { background-color: #ea9540; }
.ansi94 { color: #4040ea; }
.inv94 { background-color: #4040ea; }
.ansi95 { color: #ff90e8; }
.inv95 { background-color: #ff90e8; }
.ansi96 { color: #40eaea; }
.inv96 { background-color: #40eaea; }
.ansi90 { color: #7f7f7f; }
.inv90 { background-color: #7f7f7f; }
.ansi91 { color: #ff0000; }
.inv91 { background-color: #ff0000; }
.ansi92 { color: #00ff00; }
.inv92 { background-color: #00ff00; }
.ansi93 { color: #ffff00; }
.inv93 { background-color: #ffff00; }
.ansi94 { color: #5c5cff; }
.inv94 { background-color: #5c5cff; }
.ansi95 { color: #ff00ff; }
.inv95 { background-color: #ff00ff; }
.ansi96 { color: #00ffff; }
.inv96 { background-color: #00ffff; }
.ansi97 { color: #ffffff; }
.inv97 { background-color: #ffffff; }
.ansi100 { background-color: #404356; }
.inv100 { color: #404356; }
.ansi101 { background-color: #ea4040; }
.inv101 { color: #ea4040; }
.ansi102 { background-color: #40ea40; }
.inv102 { color: #40ea40; }
.ansi103 { background-color: #ea9540; }
.inv103 { color: #ea9540; }
.ansi104 { background-color: #4040ea; }
.inv104 { color: #4040ea; }
.ansi105 { background-color: #ff90e8; }
.inv105 { color: #ff90e8; }
.ansi106 { background-color: #40eaea; }
.inv106 { color: #40eaea; }
.ansi100 { background-color: #7f7f7f; }
.inv100 { color: #7f7f7f; }
.ansi101 { background-color: #ff0000; }
.inv101 { color: #ff0000; }
.ansi102 { background-color: #00ff00; }
.inv102 { color: #00ff00; }
.ansi103 { background-color: #ffff00; }
.inv103 { color: #ffff00; }
.ansi104 { background-color: #5c5cff; }
.inv104 { color: #5c5cff; }
.ansi105 { background-color: #ff00ff; }
.inv105 { color: #ff00ff; }
.ansi106 { background-color: #00ffff; }
.inv106 { color: #00ffff; }
.ansi107 { background-color: #ffffff; }
.inv107 { color: #ffffff; }
.ansi38-0 { color: #000316; }
Expand Down