Skip to content

Commit 6e42490

Browse files
authored
Merge pull request #276 from Muscraft/decor-style
fix!: Rename OutputTheme to DecorStyle
2 parents 622b394 + 7b2effd commit 6e42490

File tree

6 files changed

+76
-78
lines changed

6 files changed

+76
-78
lines changed

examples/custom_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use annotate_snippets::renderer::OutputTheme;
1+
use annotate_snippets::renderer::DecorStyle;
22
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
33

44
fn main() {
@@ -29,6 +29,6 @@ pub static C: u32 = 0 - 1;
2929
),
3030
)];
3131

32-
let renderer = Renderer::styled().theme(OutputTheme::Unicode);
32+
let renderer = Renderer::styled().theme(DecorStyle::Unicode);
3333
anstream::println!("{}", renderer.render(message));
3434
}

examples/custom_level.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use annotate_snippets::renderer::OutputTheme;
1+
use annotate_snippets::renderer::DecorStyle;
22
use annotate_snippets::{AnnotationKind, Group, Level, Patch, Renderer, Snippet};
33

44
fn main() {
@@ -63,6 +63,6 @@ fn main() {
6363
),
6464
];
6565

66-
let renderer = Renderer::styled().theme(OutputTheme::Unicode);
66+
let renderer = Renderer::styled().theme(DecorStyle::Unicode);
6767
anstream::println!("{}", renderer.render(message));
6868
}

examples/id_hyperlink.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use annotate_snippets::renderer::OutputTheme;
1+
use annotate_snippets::renderer::DecorStyle;
22
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
33

44
fn main() {
@@ -29,6 +29,6 @@ fn main() {
2929
),
3030
)];
3131

32-
let renderer = Renderer::styled().theme(OutputTheme::Unicode);
32+
let renderer = Renderer::styled().theme(DecorStyle::Unicode);
3333
anstream::println!("{}", renderer.render(message));
3434
}

src/renderer/mod.rs

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub const DEFAULT_TERM_WIDTH: usize = 140;
6767
pub struct Renderer {
6868
anonymized_line_numbers: bool,
6969
term_width: usize,
70-
theme: OutputTheme,
70+
theme: DecorStyle,
7171
stylesheet: Stylesheet,
7272
short_message: bool,
7373
}
@@ -78,7 +78,7 @@ impl Renderer {
7878
Self {
7979
anonymized_line_numbers: false,
8080
term_width: DEFAULT_TERM_WIDTH,
81-
theme: OutputTheme::Ascii,
81+
theme: DecorStyle::Ascii,
8282
stylesheet: Stylesheet::plain(),
8383
short_message: false,
8484
}
@@ -153,7 +153,7 @@ impl Renderer {
153153
self
154154
}
155155

156-
pub const fn theme(mut self, output_theme: OutputTheme) -> Self {
156+
pub const fn theme(mut self, output_theme: DecorStyle) -> Self {
157157
self.theme = output_theme;
158158
self
159159
}
@@ -606,7 +606,7 @@ impl Renderer {
606606
buffer.append(buffer_msg_line_offset + i, &padding, ElementStyle::NoStyle);
607607
if title_style == TitleStyle::Secondary
608608
&& is_cont
609-
&& matches!(self.theme, OutputTheme::Unicode)
609+
&& matches!(self.theme, DecorStyle::Unicode)
610610
{
611611
// There's another note after this one, associated to the subwindow above.
612612
// We write additional vertical lines to join them:
@@ -765,7 +765,7 @@ impl Renderer {
765765
} else {
766766
let buffer_msg_line_offset = buffer.num_lines();
767767
if is_primary {
768-
if self.theme == OutputTheme::Unicode {
768+
if self.theme == DecorStyle::Unicode {
769769
buffer.puts(
770770
buffer_msg_line_offset,
771771
max_line_num_len,
@@ -2331,29 +2331,27 @@ impl Renderer {
23312331
style: ElementStyle,
23322332
) {
23332333
let chr = match (style, self.theme) {
2334-
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, OutputTheme::Ascii) => {
2335-
'|'
2336-
}
2337-
(_, OutputTheme::Ascii) => '|',
2338-
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, OutputTheme::Unicode) => {
2334+
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, DecorStyle::Ascii) => '|',
2335+
(_, DecorStyle::Ascii) => '|',
2336+
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, DecorStyle::Unicode) => {
23392337
'┃'
23402338
}
2341-
(_, OutputTheme::Unicode) => '│',
2339+
(_, DecorStyle::Unicode) => '│',
23422340
};
23432341
buffer.putc(line, offset + depth - 1, chr, style);
23442342
}
23452343

23462344
fn col_separator(&self) -> char {
23472345
match self.theme {
2348-
OutputTheme::Ascii => '|',
2349-
OutputTheme::Unicode => '│',
2346+
DecorStyle::Ascii => '|',
2347+
DecorStyle::Unicode => '│',
23502348
}
23512349
}
23522350

23532351
fn multi_suggestion_separator(&self) -> &'static str {
23542352
match self.theme {
2355-
OutputTheme::Ascii => "|",
2356-
OutputTheme::Unicode => "├╴",
2353+
DecorStyle::Ascii => "|",
2354+
DecorStyle::Unicode => "├╴",
23572355
}
23582356
}
23592357

@@ -2375,7 +2373,7 @@ impl Renderer {
23752373

23762374
fn draw_col_separator_start(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
23772375
match self.theme {
2378-
OutputTheme::Ascii => {
2376+
DecorStyle::Ascii => {
23792377
self.draw_col_separator_no_space_with_style(
23802378
buffer,
23812379
'|',
@@ -2384,7 +2382,7 @@ impl Renderer {
23842382
ElementStyle::LineNumber,
23852383
);
23862384
}
2387-
OutputTheme::Unicode => {
2385+
DecorStyle::Unicode => {
23882386
self.draw_col_separator_no_space_with_style(
23892387
buffer,
23902388
'╭',
@@ -2405,7 +2403,7 @@ impl Renderer {
24052403

24062404
fn draw_col_separator_end(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
24072405
match self.theme {
2408-
OutputTheme::Ascii => {
2406+
DecorStyle::Ascii => {
24092407
self.draw_col_separator_no_space_with_style(
24102408
buffer,
24112409
'|',
@@ -2414,7 +2412,7 @@ impl Renderer {
24142412
ElementStyle::LineNumber,
24152413
);
24162414
}
2417-
OutputTheme::Unicode => {
2415+
DecorStyle::Unicode => {
24182416
self.draw_col_separator_no_space_with_style(
24192417
buffer,
24202418
'╰',
@@ -2457,16 +2455,16 @@ impl Renderer {
24572455

24582456
fn file_start(&self, is_first: bool) -> &'static str {
24592457
match self.theme {
2460-
OutputTheme::Ascii => "--> ",
2461-
OutputTheme::Unicode if is_first => " ╭▸ ",
2462-
OutputTheme::Unicode => " ├▸ ",
2458+
DecorStyle::Ascii => "--> ",
2459+
DecorStyle::Unicode if is_first => " ╭▸ ",
2460+
DecorStyle::Unicode => " ├▸ ",
24632461
}
24642462
}
24652463

24662464
fn secondary_file_start(&self) -> &'static str {
24672465
match self.theme {
2468-
OutputTheme::Ascii => "::: ",
2469-
OutputTheme::Unicode => " ⸬ ",
2466+
DecorStyle::Ascii => "::: ",
2467+
DecorStyle::Unicode => " ⸬ ",
24702468
}
24712469
}
24722470

@@ -2478,32 +2476,32 @@ impl Renderer {
24782476
is_cont: bool,
24792477
) {
24802478
let chr = match self.theme {
2481-
OutputTheme::Ascii => "= ",
2482-
OutputTheme::Unicode if is_cont => "├ ",
2483-
OutputTheme::Unicode => "╰ ",
2479+
DecorStyle::Ascii => "= ",
2480+
DecorStyle::Unicode if is_cont => "├ ",
2481+
DecorStyle::Unicode => "╰ ",
24842482
};
24852483
buffer.puts(line, col, chr, ElementStyle::LineNumber);
24862484
}
24872485

24882486
fn diff(&self) -> char {
24892487
match self.theme {
2490-
OutputTheme::Ascii => '~',
2491-
OutputTheme::Unicode => '±',
2488+
DecorStyle::Ascii => '~',
2489+
DecorStyle::Unicode => '±',
24922490
}
24932491
}
24942492

24952493
fn draw_line_separator(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
24962494
let (column, dots) = match self.theme {
2497-
OutputTheme::Ascii => (0, "..."),
2498-
OutputTheme::Unicode => (col - 2, "‡"),
2495+
DecorStyle::Ascii => (0, "..."),
2496+
DecorStyle::Unicode => (col - 2, "‡"),
24992497
};
25002498
buffer.puts(line, column, dots, ElementStyle::LineNumber);
25012499
}
25022500

25032501
fn margin(&self) -> &'static str {
25042502
match self.theme {
2505-
OutputTheme::Ascii => "...",
2506-
OutputTheme::Unicode => "…",
2503+
DecorStyle::Ascii => "...",
2504+
DecorStyle::Unicode => "…",
25072505
}
25082506
}
25092507

@@ -2533,7 +2531,7 @@ impl Renderer {
25332531
// ┗━━┛ < bottom_right
25342532

25352533
match (self.theme, is_primary) {
2536-
(OutputTheme::Ascii, true) => UnderlineParts {
2534+
(DecorStyle::Ascii, true) => UnderlineParts {
25372535
style: ElementStyle::UnderlinePrimary,
25382536
underline: '^',
25392537
label_start: '^',
@@ -2550,7 +2548,7 @@ impl Renderer {
25502548
multiline_end_same_line: '^',
25512549
multiline_bottom_right_with_text: '|',
25522550
},
2553-
(OutputTheme::Ascii, false) => UnderlineParts {
2551+
(DecorStyle::Ascii, false) => UnderlineParts {
25542552
style: ElementStyle::UnderlineSecondary,
25552553
underline: '-',
25562554
label_start: '-',
@@ -2567,7 +2565,7 @@ impl Renderer {
25672565
multiline_end_same_line: '-',
25682566
multiline_bottom_right_with_text: '|',
25692567
},
2570-
(OutputTheme::Unicode, true) => UnderlineParts {
2568+
(DecorStyle::Unicode, true) => UnderlineParts {
25712569
style: ElementStyle::UnderlinePrimary,
25722570
underline: '━',
25732571
label_start: '┯',
@@ -2584,7 +2582,7 @@ impl Renderer {
25842582
multiline_end_same_line: '┛',
25852583
multiline_bottom_right_with_text: '┥',
25862584
},
2587-
(OutputTheme::Unicode, false) => UnderlineParts {
2585+
(DecorStyle::Unicode, false) => UnderlineParts {
25882586
style: ElementStyle::UnderlineSecondary,
25892587
underline: '─',
25902588
label_start: '┬',
@@ -2929,7 +2927,7 @@ struct UnderlineParts {
29292927
}
29302928

29312929
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2932-
pub enum OutputTheme {
2930+
pub enum DecorStyle {
29332931
Ascii,
29342932
Unicode,
29352933
}

0 commit comments

Comments
 (0)