wright/terminal_interface/
mod.rs1#[cfg(feature = "lexer")]
4use crate::lexer::token::Token;
5#[cfg(feature = "lexer")]
6use std::fmt::{self, Display};
7
8#[cfg(feature = "reporting")]
9pub mod reporting;
10pub mod supports_unicode;
11
12#[cfg(feature = "lexer")]
13impl Display for Token {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 let replacements = match supports_unicode::supports_unicode() {
18 true => &[("\n", "\u{240A}"), ("\r", "\u{240D}")],
19 false => &[("\n", "[nl]"), ("\r", "[cr]")],
20 };
21
22 let mut with_replacements = self.fragment.as_str().to_owned();
23
24 for (replace, replace_with) in replacements {
25 with_replacements = with_replacements.replace(replace, replace_with);
26 }
27
28 write!(f, "\"{with_replacements}\" ({:?})", self.variant)
29 }
30}