diff --git a/.gitignore b/.gitignore index 869df07..408b8a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -Cargo.lock \ No newline at end of file +Cargo.lock +.idea \ No newline at end of file diff --git a/src/draw.rs b/src/draw.rs index a2a12b3..790e847 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -53,6 +53,30 @@ impl Characters { } } + pub fn unicode_straight() -> Self { + Self { + hbar: '─', + vbar: '│', + xbar: '┼', + vbar_break: '┆', + vbar_gap: '┆', + uarrow: '▲', + rarrow: '▶', + ltop: '┌', + mtop: '┬', + rtop: '┐', + lbot: '└', + mbot: '┴', + rbot: '┘', + lbox: '[', + rbox: ']', + lcross: '├', + rcross: '┤', + underbar: '┬', + underline: '─', + } + } + pub fn ascii() -> Self { Self { hbar: '-', diff --git a/src/lib.rs b/src/lib.rs index 691ce60..e927c0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -354,6 +354,8 @@ pub enum LabelAttach { pub enum CharSet { /// Unicode characters (an attempt is made to use only commonly-supported characters). Unicode, + /// Unicode characters for box drawing, using straight lines instead of curved ones. + UnicodeStraight, /// ASCII-only characters. Ascii, } diff --git a/src/write.rs b/src/write.rs index b2ae739..24673ff 100644 --- a/src/write.rs +++ b/src/write.rs @@ -149,6 +149,7 @@ impl Report<'_, S> { ) -> io::Result<()> { let draw = match self.config.char_set { CharSet::Unicode => draw::Characters::unicode(), + CharSet::UnicodeStraight => draw::Characters::unicode_straight(), CharSet::Ascii => draw::Characters::ascii(), }; @@ -1184,4 +1185,51 @@ mod tests { ---' "###) } + + #[test] + fn unicode_style() { + let source = "apple == orange;"; + let msg = Report::>::build(ReportKind::Error, (), 0) + .with_config(Config::default().with_char_set(CharSet::Unicode).with_color(false)) + .with_message("can't compare apples with oranges") + .with_label(Label::new(0..5).with_message("This is an apple")) + .with_label(Label::new(9..15).with_message("This is an orange")) + .finish() + .write_to_string(Source::from(source)); + assert_snapshot!(msg, @r###" + Error: can't compare apples with oranges + ╭─[:1:1] + │ + 1 │ apple == orange; + │ ──┬── ───┬── + │ ╰────────────── This is an apple + │ │ + │ ╰──── This is an orange + ───╯ + "###) + } + + #[test] + fn unicode_stright_style() { + let source = "apple == orange;"; + let msg = Report::>::build(ReportKind::Error, (), 0) + .with_config(Config::default().with_char_set(CharSet::UnicodeStraight).with_color(false)) + .with_message("can't compare apples with oranges") + .with_label(Label::new(0..5).with_message("This is an apple")) + .with_label(Label::new(9..15).with_message("This is an orange")) + .finish() + .write_to_string(Source::from(source)); + assert_snapshot!(msg, @r###" + Error: can't compare apples with oranges + ┌─[:1:1] + │ + 1 │ apple == orange; + │ ──┬── ───┬── + │ └────────────── This is an apple + │ │ + │ └──── This is an orange + ───┘ + "###) + } } +