1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use nu_ansi_term::Style;
use reedline::Highlighter;
use reedline::StyledText;

use crate::parser::*;
use crate::session::SessionParserConfig;

impl Highlighter for Localization {
    fn highlight(&self, line: &str, _pos: usize) -> StyledText {
        let mut styled_text = StyledText::new();
        match self.parse_highlight(line) {
            Ok(pairs) => {
                for (text, style) in pairs.into_iter() {
                    styled_text.push((style.into(), text));
                }
                styled_text
            }
            Err(_) => {
                styled_text.push((Style::new(), line.to_string()));
                styled_text
            }
        }
    }
}

impl Highlighter for SessionParserConfig {
    fn highlight(&self, line: &str, _pos: usize) -> StyledText {
        let mut styled_text = StyledText::new();
        match self.locale.parse_highlight_with(line, self) {
            Ok(pairs) => {
                for (text, style) in pairs.into_iter() {
                    styled_text.push((style.into(), text));
                }
                styled_text
            }
            Err(_) => {
                styled_text.push((Style::new(), line.to_string()));
                styled_text
            }
        }
    }
}