Highlight PRQL code printed to the terminal.
(tokens: &Tokens)
| 6 | |
| 7 | /// Highlight PRQL code printed to the terminal. |
| 8 | pub(crate) fn highlight(tokens: &Tokens) -> String { |
| 9 | let mut output = String::new(); |
| 10 | let mut last = 0; |
| 11 | |
| 12 | for token in &tokens.0 { |
| 13 | let diff = token.span.start - last; |
| 14 | last = token.span.end; |
| 15 | output.push_str(&" ".repeat(diff)); |
| 16 | output.push_str(&highlight_token_kind(&token.kind)); |
| 17 | } |
| 18 | |
| 19 | output |
| 20 | } |
| 21 | |
| 22 | fn highlight_token_kind(token: &TokenKind) -> String { |
| 23 | // LineWrap is recursive with TokenKind, so we needed to split this function |
no test coverage detected