on master help sign in
Add ansi theme to replace ansi-light and ansi-dark

This combines ansi-light and ansi-dark into a single theme that works with both light and dark backgrounds. Instead of specifying white/black, the ansi theme uses the terminal's default foreground/background color by setting alpha=01, i.e. #00000001. This is in addition to the alpha=00 encoding where red contains an ANSI color palette number. Now, `--theme ansi-light` and `--theme ansi-dark` will print a deprecation notice and use ansi instead (unless the user has a custom theme named ansi-light or ansi-dark, which would take precedence).

commit3099f51ba7a19596f084699eeb1b69305a88b9e4 authorMitchell Kember <mk12360@gmail.com> dateSun 29 Nov 2020, 17:16 (6 years ago) parent19e7763
7 files changed+63−615
CHANGELOG.md+2 README.md+3−4 assets/themes/ansi-light.tmTheme−504 assets/themes/ansi-dark.tmTheme → assets/themes/ansi.tmTheme+13−87 src/assets.rs+9 src/printer.rs+17−11 src/terminal.rs+19−9
CHANGELOG.md+2
@@ -18,6 +18,8 @@
1818
1919## New themes
2020
21+- `ansi` replaces `ansi-dark` and `ansi-light`, see #1104 and #1412 (@mk12)
22+
2123## `bat` as a library
2224
2325## Packaging
README.md+3−4
@@ -390,12 +390,11 @@ You can also use a custom theme by following the
390390
391391### 8-bit themes
392392
393−`bat` has four themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors),
393+`bat` has three themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors),
394394even when truecolor support is available:
395395
396−- `ansi-dark` looks decent on any terminal with a dark background. It uses 3-bit colors: black, red,
397− green, yellow, blue, magenta, cyan, and white.
398−- `ansi-light` is like `ansi-dark`, but for terminals with a light background.
396+- `ansi` looks decent on any terminal. It uses 3-bit colors: black, red, green,
397+ yellow, blue, magenta, cyan, and white.
399398- `base16` is designed for [base16](https://github.com/chriskempson/base16) terminal themes. It uses
400399 4-bit colors (3-bit colors plus bright variants) in accordance with the
401400 [base16 styling guidelines](https://github.com/chriskempson/base16/blob/master/styling.md).
assets/themes/ansi-light.tmThemedeleted−504
@@ -1,504 +0,0 @@
1−<?xml version="1.0" encoding="UTF-8"?>
2−<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3−<plist version="1.0">
4− <dict>
5− <!--
6− The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI
7− palette number from 00 to 0f, and AA is the special value 00 to indicate
8− that this encoding is being used.
9− -->
10− <key>author</key>
11− <string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
12− <key>name</key>
13− <string>ANSI Light</string>
14− <key>colorSpaceName</key>
15− <string>sRGB</string>
16− <key>settings</key>
17− <array>
18− <dict>
19− <key>settings</key>
20− <dict>
21− <key>background</key>
22− <string>#07000000</string>
23− <key>caret</key>
24− <string>#00000000</string>
25− <key>foreground</key>
26− <string>#00000000</string>
27− <key>invisibles</key>
28− <string>#00000000</string>
29− <key>lineHighlight</key>
30− <string>#00000000</string>
31− <key>selection</key>
32− <string>#00000000</string>
33− <key>gutter</key>
34− <string>#07000000</string>
35− <key>gutterForeground</key>
36− <string>#00000000</string>
37− </dict>
38− </dict>
39− <dict>
40− <key>name</key>
41− <string>Text</string>
42− <key>scope</key>
43− <string>variable.parameter.function</string>
44− <key>settings</key>
45− <dict>
46− <key>foreground</key>
47− <string>#00000000</string>
48− </dict>
49− </dict>
50− <dict>
51− <key>name</key>
52− <string>Comments</string>
53− <key>scope</key>
54− <string>comment, punctuation.definition.comment</string>
55− <key>settings</key>
56− <dict>
57− <key>foreground</key>
58− <string>#02000000</string>
59− </dict>
60− </dict>
61− <dict>
62− <key>name</key>
63− <string>Punctuation</string>
64− <key>scope</key>
65− <string>punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array</string>
66− <key>settings</key>
67− <dict>
68− <key>foreground</key>
69− <string>#00000000</string>
70− </dict>
71− </dict>
72− <dict>
73− <key>name</key>
74− <string>Delimiters</string>
75− <key>scope</key>
76− <string>none</string>
77− <key>settings</key>
78− <dict>
79− <key>foreground</key>
80− <string>#00000000</string>
81− </dict>
82− </dict>
83− <dict>
84− <key>name</key>
85− <string>Operators</string>
86− <key>scope</key>
87− <string>keyword.operator</string>
88− <key>settings</key>
89− <dict>
90− <key>foreground</key>
91− <string>#00000000</string>
92− </dict>
93− </dict>
94− <dict>
95− <key>name</key>
96− <string>Keywords</string>
97− <key>scope</key>
98− <string>keyword</string>
99− <key>settings</key>
100− <dict>
101− <key>foreground</key>
102− <string>#05000000</string>
103− </dict>
104− </dict>
105− <dict>
106− <key>name</key>
107− <string>Variables</string>
108− <key>scope</key>
109− <string>variable</string>
110− <key>settings</key>
111− <dict>
112− <key>foreground</key>
113− <string>#00000000</string>
114− </dict>
115− </dict>
116− <dict>
117− <key>name</key>
118− <string>Functions</string>
119− <key>scope</key>
120− <string>entity.name.function, meta.require, support.function.any-method</string>
121− <key>settings</key>
122− <dict>
123− <key>foreground</key>
124− <string>#04000000</string>
125− </dict>
126− </dict>
127− <dict>
128− <key>name</key>
129− <string>Labels</string>
130− <key>scope</key>
131− <string>entity.name.label</string>
132− <key>settings</key>
133− <dict>
134− <key>foreground</key>
135− <string>#06000000</string>
136− </dict>
137− </dict>
138− <dict>
139− <key>name</key>
140− <string>Classes</string>
141− <key>scope</key>
142− <string>support.class, entity.name.class, entity.name.type.class</string>
143− <key>settings</key>
144− <dict>
145− <key>foreground</key>
146− <string>#03000000</string>
147− </dict>
148− </dict>
149− <dict>
150− <key>name</key>
151− <string>Classes</string>
152− <key>scope</key>
153− <string>meta.class</string>
154− <key>settings</key>
155− <dict>
156− <key>foreground</key>
157− <string>#00000000</string>
158− </dict>
159− </dict>
160− <dict>
161− <key>name</key>
162− <string>Methods</string>
163− <key>scope</key>
164− <string>keyword.other.special-method</string>
165− <key>settings</key>
166− <dict>
167− <key>foreground</key>
168− <string>#04000000</string>
169− </dict>
170− </dict>
171− <dict>
172− <key>name</key>
173− <string>Storage</string>
174− <key>scope</key>
175− <string>storage</string>
176− <key>settings</key>
177− <dict>
178− <key>foreground</key>
179− <string>#05000000</string>
180− </dict>
181− </dict>
182− <dict>
183− <key>name</key>
184− <string>Support</string>
185− <key>scope</key>
186− <string>support.function</string>
187− <key>settings</key>
188− <dict>
189− <key>foreground</key>
190− <string>#06000000</string>
191− </dict>
192− </dict>
193− <dict>
194− <key>name</key>
195− <string>Strings, Inherited Class</string>
196− <key>scope</key>
197− <string>string, constant.other.symbol, entity.other.inherited-class</string>
198− <key>settings</key>
199− <dict>
200− <key>foreground</key>
201− <string>#02000000</string>
202− </dict>
203− </dict>
204− <dict>
205− <key>name</key>
206− <string>Integers</string>
207− <key>scope</key>
208− <string>constant.numeric</string>
209− <key>settings</key>
210− <dict>
211− <key>foreground</key>
212− <string>#03000000</string>
213− </dict>
214− </dict>
215− <dict>
216− <key>name</key>
217− <string>Floats</string>
218− <key>scope</key>
219− <string>none</string>
220− <key>settings</key>
221− <dict>
222− <key>foreground</key>
223− <string>#03000000</string>
224− </dict>
225− </dict>
226− <dict>
227− <key>name</key>
228− <string>Boolean</string>
229− <key>scope</key>
230− <string>none</string>
231− <key>settings</key>
232− <dict>
233− <key>foreground</key>
234− <string>#03000000</string>
235− </dict>
236− </dict>
237− <dict>
238− <key>name</key>
239− <string>Constants</string>
240− <key>scope</key>
241− <string>constant</string>
242− <key>settings</key>
243− <dict>
244− <key>foreground</key>
245− <string>#03000000</string>
246− </dict>
247− </dict>
248− <dict>
249− <key>name</key>
250− <string>Tags</string>
251− <key>scope</key>
252− <string>entity.name.tag</string>
253− <key>settings</key>
254− <dict>
255− <key>foreground</key>
256− <string>#01000000</string>
257− </dict>
258− </dict>
259− <dict>
260− <key>name</key>
261− <string>Attributes</string>
262− <key>scope</key>
263− <string>entity.other.attribute-name</string>
264− <key>settings</key>
265− <dict>
266− <key>foreground</key>
267− <string>#03000000</string>
268− </dict>
269− </dict>
270− <dict>
271− <key>name</key>
272− <string>Attribute IDs</string>
273− <key>scope</key>
274− <string>entity.other.attribute-name.id, punctuation.definition.entity</string>
275− <key>settings</key>
276− <dict>
277− <key>foreground</key>
278− <string>#04000000</string>
279− </dict>
280− </dict>
281− <dict>
282− <key>name</key>
283− <string>Selector</string>
284− <key>scope</key>
285− <string>meta.selector</string>
286− <key>settings</key>
287− <dict>
288− <key>foreground</key>
289− <string>#05000000</string>
290− </dict>
291− </dict>
292− <dict>
293− <key>name</key>
294− <string>Values</string>
295− <key>scope</key>
296− <string>none</string>
297− <key>settings</key>
298− <dict>
299− <key>foreground</key>
300− <string>#03000000</string>
301− </dict>
302− </dict>
303− <dict>
304− <key>name</key>
305− <string>Headings</string>
306− <key>scope</key>
307− <string>markup.heading punctuation.definition.heading, entity.name.section</string>
308− <key>settings</key>
309− <dict>
310− <key>fontStyle</key>
311− <string></string>
312− <key>foreground</key>
313− <string>#04000000</string>
314− </dict>
315− </dict>
316− <dict>
317− <key>name</key>
318− <string>Units</string>
319− <key>scope</key>
320− <string>keyword.other.unit</string>
321− <key>settings</key>
322− <dict>
323− <key>foreground</key>
324− <string>#03000000</string>
325− </dict>
326− </dict>
327− <dict>
328− <key>name</key>
329− <string>Bold</string>
330− <key>scope</key>
331− <string>markup.bold, punctuation.definition.bold</string>
332− <key>settings</key>
333− <dict>
334− <key>fontStyle</key>
335− <string>bold</string>
336− <key>foreground</key>
337− <string>#03000000</string>
338− </dict>
339− </dict>
340− <dict>
341− <key>name</key>
342− <string>Italic</string>
343− <key>scope</key>
344− <string>markup.italic, punctuation.definition.italic</string>
345− <key>settings</key>
346− <dict>
347− <key>fontStyle</key>
348− <string>italic</string>
349− <key>foreground</key>
350− <string>#05000000</string>
351− </dict>
352− </dict>
353− <dict>
354− <key>name</key>
355− <string>Code</string>
356− <key>scope</key>
357− <string>markup.raw.inline</string>
358− <key>settings</key>
359− <dict>
360− <key>foreground</key>
361− <string>#02000000</string>
362− </dict>
363− </dict>
364− <dict>
365− <key>name</key>
366− <string>Link Text</string>
367− <key>scope</key>
368− <string>string.other.link, punctuation.definition.string.end.markdown, punctuation.definition.string.begin.markdown</string>
369− <key>settings</key>
370− <dict>
371− <key>foreground</key>
372− <string>#01000000</string>
373− </dict>
374− </dict>
375− <dict>
376− <key>name</key>
377− <string>Link Url</string>
378− <key>scope</key>
379− <string>meta.link</string>
380− <key>settings</key>
381− <dict>
382− <key>foreground</key>
383− <string>#03000000</string>
384− </dict>
385− </dict>
386− <dict>
387− <key>name</key>
388− <string>Quotes</string>
389− <key>scope</key>
390− <string>markup.quote</string>
391− <key>settings</key>
392− <dict>
393− <key>foreground</key>
394− <string>#03000000</string>
395− </dict>
396− </dict>
397− <dict>
398− <key>name</key>
399− <string>Inserted</string>
400− <key>scope</key>
401− <string>markup.inserted</string>
402− <key>settings</key>
403− <dict>
404− <key>foreground</key>
405− <string>#02000000</string>
406− </dict>
407− </dict>
408− <dict>
409− <key>name</key>
410− <string>Deleted</string>
411− <key>scope</key>
412− <string>markup.deleted</string>
413− <key>settings</key>
414− <dict>
415− <key>foreground</key>
416− <string>#01000000</string>
417− </dict>
418− </dict>
419− <dict>
420− <key>name</key>
421− <string>Changed</string>
422− <key>scope</key>
423− <string>markup.changed</string>
424− <key>settings</key>
425− <dict>
426− <key>foreground</key>
427− <string>#05000000</string>
428− </dict>
429− </dict>
430− <dict>
431− <key>name</key>
432− <string>Colors</string>
433− <key>scope</key>
434− <string>constant.other.color</string>
435− <key>settings</key>
436− <dict>
437− <key>foreground</key>
438− <string>#06000000</string>
439− </dict>
440− </dict>
441− <dict>
442− <key>name</key>
443− <string>Regular Expressions</string>
444− <key>scope</key>
445− <string>string.regexp</string>
446− <key>settings</key>
447− <dict>
448− <key>foreground</key>
449− <string>#06000000</string>
450− </dict>
451− </dict>
452− <dict>
453− <key>name</key>
454− <string>Escape Characters</string>
455− <key>scope</key>
456− <string>constant.character.escape</string>
457− <key>settings</key>
458− <dict>
459− <key>foreground</key>
460− <string>#06000000</string>
461− </dict>
462− </dict>
463− <dict>
464− <key>name</key>
465− <string>Embedded</string>
466− <key>scope</key>
467− <string>punctuation.section.embedded, variable.interpolation</string>
468− <key>settings</key>
469− <dict>
470− <key>foreground</key>
471− <string>#05000000</string>
472− </dict>
473− </dict>
474− <dict>
475− <key>name</key>
476− <string>Illegal</string>
477− <key>scope</key>
478− <string>invalid.illegal</string>
479− <key>settings</key>
480− <dict>
481− <key>background</key>
482− <string>#01000000</string>
483− <key>foreground</key>
484− <string>#00000000</string>
485− </dict>
486− </dict>
487− <dict>
488− <key>name</key>
489− <string>Broken</string>
490− <key>scope</key>
491− <string>invalid.broken</string>
492− <key>settings</key>
493− <dict>
494− <key>background</key>
495− <string>#03000000</string>
496− <key>foreground</key>
497− <string>#07000000</string>
498− </dict>
499− </dict>
500− </array>
501− <key>uuid</key>
502− <string>uuid</string>
503− </dict>
504−</plist>
assets/themes/ansi-dark.tmTheme → assets/themes/ansi.tmThemerenamed+13−87
@@ -3,14 +3,14 @@
33<plist version="1.0">
44 <dict>
55 <!--
6− The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI
7− palette number from 00 to 0f, and AA is the special value 00 to indicate
8− that this encoding is being used.
6+ The colors in this theme are encoded as #RRGGBBAA where:
7+ * If AA is 00, then RR is an ANSI palette number from 00 to 07.
8+ * If AA is 01, the terminal's default fg/bg color is used.
99 -->
1010 <key>author</key>
1111 <string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
1212 <key>name</key>
13− <string>ANSI Dark</string>
13+ <string>ANSI</string>
1414 <key>colorSpaceName</key>
1515 <string>sRGB</string>
1616 <key>settings</key>
@@ -19,32 +19,17 @@
1919 <key>settings</key>
2020 <dict>
2121 <key>background</key>
22− <string>#00000000</string>
23− <key>caret</key>
24− <string>#07000000</string>
25− <key>foreground</key>
26− <string>#07000000</string>
27− <key>invisibles</key>
28− <string>#07000000</string>
29− <key>lineHighlight</key>
30− <string>#07000000</string>
31− <key>selection</key>
32− <string>#07000000</string>
22+ <string>#00000001</string>
23+ <key>foreground</key>
24+ <string>#00000001</string>
25+ <!--
26+ Explicitly set the gutter color since bat falls back to a
27+ hardcoded DEFAULT_GUTTER_COLOR otherwise.
28+ -->
3329 <key>gutter</key>
34− <string>#00000000</string>
30+ <string>#00000001</string>
3531 <key>gutterForeground</key>
36− <string>#07000000</string>
37− </dict>
38− </dict>
39− <dict>
40− <key>name</key>
41− <string>Text</string>
42− <key>scope</key>
43− <string>variable.parameter.function</string>
44− <key>settings</key>
45− <dict>
46− <key>foreground</key>
47− <string>#07000000</string>
32+ <string>#00000001</string>
4833 </dict>
4934 </dict>
5035 <dict>
@@ -58,39 +43,6 @@
5843 <string>#02000000</string>
5944 </dict>
6045 </dict>
61− <dict>
62− <key>name</key>
63− <string>Punctuation</string>
64− <key>scope</key>
65− <string>punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array</string>
66− <key>settings</key>
67− <dict>
68− <key>foreground</key>
69− <string>#07000000</string>
70− </dict>
71− </dict>
72− <dict>
73− <key>name</key>
74− <string>Delimiters</string>
75− <key>scope</key>
76− <string>none</string>
77− <key>settings</key>
78− <dict>
79− <key>foreground</key>
80− <string>#07000000</string>
81− </dict>
82− </dict>
83− <dict>
84− <key>name</key>
85− <string>Operators</string>
86− <key>scope</key>
87− <string>keyword.operator</string>
88− <key>settings</key>
89− <dict>
90− <key>foreground</key>
91− <string>#07000000</string>
92− </dict>
93− </dict>
9446 <dict>
9547 <key>name</key>
9648 <string>Keywords</string>
@@ -102,17 +54,6 @@
10254 <string>#05000000</string>
10355 </dict>
10456 </dict>
105− <dict>
106− <key>name</key>
107− <string>Variables</string>
108− <key>scope</key>
109− <string>variable</string>
110− <key>settings</key>
111− <dict>
112− <key>foreground</key>
113− <string>#07000000</string>
114− </dict>
115− </dict>
11657 <dict>
11758 <key>name</key>
11859 <string>Functions</string>
@@ -146,17 +87,6 @@
14687 <string>#03000000</string>
14788 </dict>
14889 </dict>
149− <dict>
150− <key>name</key>
151− <string>Classes</string>
152− <key>scope</key>
153− <string>meta.class</string>
154− <key>settings</key>
155− <dict>
156− <key>foreground</key>
157− <string>#07000000</string>
158− </dict>
159− </dict>
16090 <dict>
16191 <key>name</key>
16292 <string>Methods</string>
@@ -480,8 +410,6 @@
480410 <dict>
481411 <key>background</key>
482412 <string>#01000000</string>
483− <key>foreground</key>
484− <string>#07000000</string>
485413 </dict>
486414 </dict>
487415 <dict>
@@ -493,8 +421,6 @@
493421 <dict>
494422 <key>background</key>
495423 <string>#03000000</string>
496− <key>foreground</key>
497− <string>#00000000</string>
498424 </dict>
499425 </dict>
500426 </array>
src/assets.rs+9
@@ -189,6 +189,15 @@ impl HighlightingAssets {
189189 match self.theme_set.themes.get(theme) {
190190 Some(theme) => theme,
191191 None => {
192+ if theme == "ansi-light" || theme == "ansi-dark" {
193+ use ansi_term::Colour::Yellow;
194+ eprintln!(
195+ "{}: Theme '{}' is deprecated, using 'ansi' instead.",
196+ Yellow.paint("[bat warning]"),
197+ theme
198+ );
199+ return self.get_theme("ansi");
200+ }
192201 if theme != "" {
193202 use ansi_term::Colour::Yellow;
194203 eprintln!(
src/printer.rs+17−11
@@ -448,7 +448,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
448448 if text.len() != text_trimmed.len() {
449449 if let Some(background_color) = background_color {
450450 let mut ansi_style = Style::default();
451− ansi_style.background = Some(to_ansi_color(background_color, true_color));
451+ ansi_style.background = to_ansi_color(background_color, true_color);
452452 let width = if cursor_total <= cursor_max {
453453 cursor_max - cursor_total + 1
454454 } else {
@@ -589,8 +589,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
589589
590590 if let Some(background_color) = background_color {
591591 let mut ansi_style = Style::default();
592− ansi_style.background =
593− Some(to_ansi_color(background_color, self.config.true_color));
592+ ansi_style.background = to_ansi_color(background_color, self.config.true_color);
594593
595594 write!(
596595 handle,
@@ -624,20 +623,27 @@ impl Colors {
624623 }
625624
626625 fn colored(theme: &Theme, true_color: bool) -> Self {
627− let gutter_color = theme
628− .settings
629− .gutter_foreground
630− .map(|c| to_ansi_color(c, true_color))
631− .unwrap_or(Fixed(DEFAULT_GUTTER_COLOR));
626+ let gutter_style = Style {
627+ foreground: match theme.settings.gutter_foreground {
628+ // If the theme provides a gutter foreground color, use it.
629+ // Note: It might be the special value #00000001, in which case
630+ // to_ansi_color returns None and we use an empty Style
631+ // (resulting in the terminal's default foreground color).
632+ Some(c) => to_ansi_color(c, true_color),
633+ // Otherwise, use a specific fallback color.
634+ None => Some(Fixed(DEFAULT_GUTTER_COLOR)),
635+ },
636+ ..Style::default()
637+ };
632638
633639 Colors {
634− grid: gutter_color.normal(),
635− rule: gutter_color.normal(),
640+ grid: gutter_style,
641+ rule: gutter_style,
636642 filename: Style::new().bold(),
637643 git_added: Green.normal(),
638644 git_removed: Red.normal(),
639645 git_modified: Yellow.normal(),
640− line_number: gutter_color.normal(),
646+ line_number: gutter_style,
641647 }
642648 }
643649}
src/terminal.rs+19−9
@@ -3,13 +3,13 @@ use ansi_term::{self, Style};
33
44use syntect::highlighting::{self, FontStyle};
55
6−pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Color {
6+pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option<ansi_term::Color> {
77 if color.a == 0 {
88 // Themes can specify one of the user-configurable terminal colors by
99 // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set
10− // to the 8-bit color palette number. The built-in themes ansi-light,
11− // ansi-dark, base16, and base16-256 use this.
12− match color.r {
10+ // to the 8-bit color palette number. The built-in themes ansi, base16,
11+ // and base16-256 use this.
12+ Some(match color.r {
1313 // For the first 8 colors, use the Color enum to produce ANSI escape
1414 // sequences using codes 30-37 (foreground) and 40-47 (background).
1515 // For example, red foreground is \x1b[31m. This works on terminals
@@ -31,11 +31,18 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
3131 // 90-97 (foreground) and 100-107 (background), we should use those
3232 // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
3333 n => Fixed(n),
34− }
34+ })
35+ } else if color.a == 1 {
36+ // Themes can specify the terminal's default foreground/background color
37+ // (i.e. no escape sequence) using the encoding #RRGGBBAA with AA set to
38+ // 01. The built-in theme ansi uses this.
39+ None
3540 } else if true_color {
36− RGB(color.r, color.g, color.b)
41+ Some(RGB(color.r, color.g, color.b))
3742 } else {
38− Fixed(ansi_colours::ansi256_from_rgb((color.r, color.g, color.b)))
43+ Some(Fixed(ansi_colours::ansi256_from_rgb((
44+ color.r, color.g, color.b,
45+ ))))
3946 }
4047}
4148
@@ -54,7 +61,10 @@ pub fn as_terminal_escaped(
5461 let mut style = if !colored {
5562 Style::default()
5663 } else {
57− let mut color = Style::from(to_ansi_color(style.foreground, true_color));
64+ let mut color = Style {
65+ foreground: to_ansi_color(style.foreground, true_color),
66+ ..Style::default()
67+ };
5868 if style.font_style.contains(FontStyle::BOLD) {
5969 color = color.bold();
6070 }
@@ -67,6 +77,6 @@ pub fn as_terminal_escaped(
6777 color
6878 };
6979
70− style.background = background_color.map(|c| to_ansi_color(c, true_color));
80+ style.background = background_color.and_then(|c| to_ansi_color(c, true_color));
7181 style.paint(text).to_string()
7282}