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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use ;
/// Creates a parser for Select Graphic Rendition(SGR) sequences.
///
/// NOTE: The interace is not very stable yet.
/// A parser for SGR sequences.
// A different logic.
// use super::{parsers::parse_visual_attribute, Output, VisualAttribute};
// /// Creates a parser for Select Graphic Rendition(SGR) sequences.
// pub fn parse_ansi_sgr(text: &str) -> SGRParser<'_> {
// SGRParser {
// text,
// is_start: true,
// next_seq: None,
// }
// }
// /// A parser for SGR sequences.
// #[derive(Debug)]
// pub struct SGRParser<'a> {
// is_start: bool,
// text: &'a str,
// next_seq: Option<VisualAttribute>,
// }
// impl<'a> Iterator for SGRParser<'a> {
// type Item = Output<'a, VisualAttribute>;
// fn next(&mut self) -> Option<Self::Item> {
// if let Some(seq) = self.next_seq.take() {
// return Some(Output::Escape(seq));
// }
// if self.text.is_empty() {
// return None;
// }
// let mut text = self.text;
// if !self.is_start && text.starts_with(';') && text.len() > 1 {
// text = &text[1..];
// }
// if self.is_start {
// self.is_start = false;
// }
// let mut unknown_length = 0;
// let mut ptr = text;
// loop {
// let attr = parse_visual_attribute(ptr);
// match attr {
// Ok((rest, mode)) => {
// self.text = rest;
// if unknown_length != 0 {
// self.next_seq = Some(mode);
// let unknown_text = &text[..unknown_length];
// return Some(Output::Text(unknown_text));
// } else {
// return Some(Output::Escape(mode));
// }
// }
// Err(_) => {
// if ptr.is_empty() {
// let unknown_text = &text[..unknown_length];
// self.text = "";
// return Some(Output::Text(unknown_text));
// }
// // the best we can for now is to try to move text one char at a time
// let next_char_pos = ptr.chars().next().unwrap().len_utf8();
// ptr = &ptr[next_char_pos..];
// unknown_length += next_char_pos;
// }
// }
// }
// }
// }