Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ pub static C: u32 = 0 - 1;
),
)];

let renderer = Renderer::styled().theme(DecorStyle::Unicode);
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(message));
}
2 changes: 1 addition & 1 deletion examples/custom_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ fn main() {
),
];

let renderer = Renderer::styled().theme(DecorStyle::Unicode);
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(message));
}
2 changes: 1 addition & 1 deletion examples/id_hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ fn main() {
),
)];

let renderer = Renderer::styled().theme(DecorStyle::Unicode);
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(message));
}
36 changes: 18 additions & 18 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub const DEFAULT_TERM_WIDTH: usize = 140;
pub struct Renderer {
anonymized_line_numbers: bool,
term_width: usize,
theme: DecorStyle,
decor_style: DecorStyle,
stylesheet: Stylesheet,
short_message: bool,
}
Expand All @@ -78,7 +78,7 @@ impl Renderer {
Self {
anonymized_line_numbers: false,
term_width: DEFAULT_TERM_WIDTH,
theme: DecorStyle::Ascii,
decor_style: DecorStyle::Ascii,
stylesheet: Stylesheet::plain(),
short_message: false,
}
Expand Down Expand Up @@ -153,8 +153,8 @@ impl Renderer {
self
}

pub const fn theme(mut self, output_theme: DecorStyle) -> Self {
self.theme = output_theme;
pub const fn decor_style(mut self, decor_style: DecorStyle) -> Self {
self.decor_style = decor_style;
self
}

Expand Down Expand Up @@ -606,7 +606,7 @@ impl Renderer {
buffer.append(buffer_msg_line_offset + i, &padding, ElementStyle::NoStyle);
if title_style == TitleStyle::Secondary
&& is_cont
&& matches!(self.theme, DecorStyle::Unicode)
&& matches!(self.decor_style, DecorStyle::Unicode)
{
// There's another note after this one, associated to the subwindow above.
// We write additional vertical lines to join them:
Expand Down Expand Up @@ -765,7 +765,7 @@ impl Renderer {
} else {
let buffer_msg_line_offset = buffer.num_lines();
if is_primary {
if self.theme == DecorStyle::Unicode {
if self.decor_style == DecorStyle::Unicode {
buffer.puts(
buffer_msg_line_offset,
max_line_num_len,
Expand Down Expand Up @@ -2330,7 +2330,7 @@ impl Renderer {
depth: usize,
style: ElementStyle,
) {
let chr = match (style, self.theme) {
let chr = match (style, self.decor_style) {
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, DecorStyle::Ascii) => '|',
(_, DecorStyle::Ascii) => '|',
(ElementStyle::UnderlinePrimary | ElementStyle::LabelPrimary, DecorStyle::Unicode) => {
Expand All @@ -2342,14 +2342,14 @@ impl Renderer {
}

fn col_separator(&self) -> char {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => '|',
DecorStyle::Unicode => '│',
}
}

fn multi_suggestion_separator(&self) -> &'static str {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => "|",
DecorStyle::Unicode => "├╴",
}
Expand All @@ -2372,7 +2372,7 @@ impl Renderer {
}

fn draw_col_separator_start(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => {
self.draw_col_separator_no_space_with_style(
buffer,
Expand Down Expand Up @@ -2402,7 +2402,7 @@ impl Renderer {
}

fn draw_col_separator_end(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => {
self.draw_col_separator_no_space_with_style(
buffer,
Expand Down Expand Up @@ -2454,15 +2454,15 @@ impl Renderer {
}

fn file_start(&self, is_first: bool) -> &'static str {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => "--> ",
DecorStyle::Unicode if is_first => " ╭▸ ",
DecorStyle::Unicode => " ├▸ ",
}
}

fn secondary_file_start(&self) -> &'static str {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => "::: ",
DecorStyle::Unicode => " ⸬ ",
}
Expand All @@ -2475,7 +2475,7 @@ impl Renderer {
col: usize,
is_cont: bool,
) {
let chr = match self.theme {
let chr = match self.decor_style {
DecorStyle::Ascii => "= ",
DecorStyle::Unicode if is_cont => "├ ",
DecorStyle::Unicode => "╰ ",
Expand All @@ -2484,22 +2484,22 @@ impl Renderer {
}

fn diff(&self) -> char {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => '~',
DecorStyle::Unicode => '±',
}
}

fn draw_line_separator(&self, buffer: &mut StyledBuffer, line: usize, col: usize) {
let (column, dots) = match self.theme {
let (column, dots) = match self.decor_style {
DecorStyle::Ascii => (0, "..."),
DecorStyle::Unicode => (col - 2, "‡"),
};
buffer.puts(line, column, dots, ElementStyle::LineNumber);
}

fn margin(&self) -> &'static str {
match self.theme {
match self.decor_style {
DecorStyle::Ascii => "...",
DecorStyle::Unicode => "…",
}
Expand Down Expand Up @@ -2530,7 +2530,7 @@ impl Renderer {
// ┃ ╿ < multiline_end_up
// ┗━━┛ < bottom_right

match (self.theme, is_primary) {
match (self.decor_style, is_primary) {
(DecorStyle::Ascii, true) => UnderlineParts {
style: ElementStyle::UnderlinePrimary,
underline: '^',
Expand Down
36 changes: 18 additions & 18 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ error: bad
╰╴━
"#]];

let renderer = renderer.theme(DecorStyle::Unicode);
let renderer = renderer.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(message), expected_unicode);
}

Expand Down Expand Up @@ -1747,7 +1747,7 @@ LL │ type Error = E;
"#]];
let renderer = Renderer::plain()
.term_width(40)
.theme(DecorStyle::Unicode)
.decor_style(DecorStyle::Unicode)
.anonymized_line_numbers(true);
assert_data_eq!(renderer.render(input_new), expected);
}
Expand Down Expand Up @@ -1835,7 +1835,7 @@ LL │ type Error = E;
"#]];
let renderer = Renderer::plain()
.term_width(40)
.theme(DecorStyle::Unicode)
.decor_style(DecorStyle::Unicode)
.anonymized_line_numbers(true);
assert_data_eq!(renderer.render(input_new), expected);
}
Expand Down Expand Up @@ -1996,7 +1996,7 @@ LL │ ┃ )))))))))))))))))))))))))))))];
"#]];
let renderer = Renderer::plain()
.term_width(60)
.theme(DecorStyle::Unicode)
.decor_style(DecorStyle::Unicode)
.anonymized_line_numbers(true);
assert_data_eq!(renderer.render(input_new), expected);
}
Expand Down Expand Up @@ -2076,7 +2076,7 @@ LL │ ┃ )>>) {}
╰╴┗━━━┛
"#]];
let renderer = Renderer::plain()
.theme(DecorStyle::Unicode)
.decor_style(DecorStyle::Unicode)
.anonymized_line_numbers(true);
assert_data_eq!(renderer.render(input_new), expected);
}
Expand Down Expand Up @@ -2122,7 +2122,7 @@ error: title
5 │ ┃ ]
╰╴┗━┛ annotation
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2159,7 +2159,7 @@ error: expected item, found `?`
╰ note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2196,7 +2196,7 @@ error: expected item, found `?`
╰ note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2233,7 +2233,7 @@ error: expected item, found `?`
╰ note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2285,7 +2285,7 @@ LL │ …♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻
│ │
╰╴ expected due to this
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2368,7 +2368,7 @@ LL │ let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓
╰╴ +++++++++++
"#]];

let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2432,7 +2432,7 @@ LL │ �|�␂!5�cc␕␂�Ӻi��WWj�ȥ�'�}�␒�J�ȉ��W
│ ━
╰ note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2634,7 +2634,7 @@ LL - });
LL + break;
╰╴
"#]];
let renderer_unicode = renderer_ascii.theme(DecorStyle::Unicode);
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2841,7 +2841,7 @@ error:
1 │ def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
╰╴ ━━━━━━━━ annotation
"#]];
let renderer = Renderer::plain().theme(DecorStyle::Unicode);
let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2883,7 +2883,7 @@ error:
1 │ def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
╰╴ ━━━━━━━━ annotation
"#]];
let renderer = Renderer::plain().theme(DecorStyle::Unicode);
let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(input), expected_unicode);
}

Expand Down Expand Up @@ -2941,7 +2941,7 @@ LL │ .sum::<_>() //~ ERROR type annotations needed
│ ━━━ cannot infer type of the type parameter `S` declared on the method `sum`
╰╴
"#]];
let renderer = renderer.theme(DecorStyle::Unicode);
let renderer = renderer.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(input), expected_unicode);
}

Expand Down Expand Up @@ -3018,7 +3018,7 @@ LL - .sum::<_>() //~ ERROR type annotations needed
LL + .sum::<GENERIC_ARG>() //~ ERROR type annotations needed
╰╴
"#]];
let renderer = renderer.theme(DecorStyle::Unicode);
let renderer = renderer.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(input), expected_unicode);
}

Expand Down Expand Up @@ -3220,6 +3220,6 @@ error[E0609]: no field `field` on type `Thing`
LL │ t.field;
╰╴ ━━━━━ unknown field
"#]];
let renderer = renderer.theme(DecorStyle::Unicode);
let renderer = renderer.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(input), expected_unicode);
}
Loading
Loading