pub struct StyledBuffer { /* private fields */ }
Expand description
Memory representation of the lines and styles
Implementations§
Source§impl StyledBuffer
impl StyledBuffer
Sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Insert character at the current position with default style
Sourcepub fn insert_styled_char(&mut self, ch: char, style: Style)
pub fn insert_styled_char(&mut self, ch: char, style: Style)
Insert character at the current position with style
Sourcepub fn insert_string(&mut self, str: &str)
pub fn insert_string(&mut self, str: &str)
Insert string at the current position with default style
Sourcepub fn insert_styled_string(&mut self, str: &str, style: Style)
pub fn insert_styled_string(&mut self, str: &str, style: Style)
Insert string at the current position with style
Examples found in repository?
27 fn hint(&self, buffer: &mut StyledBuffer) -> Option<StyledBuffer> {
28 if let Some(keyword) = buffer.last_alphabetic_keyword() {
29 let keyword_lower = keyword.to_lowercase();
30 for word in GITQL_RESERVED_KEYWORDS {
31 if word.starts_with(&keyword_lower) {
32 let hint = &word[keyword.len()..];
33 let mut styled_buffer = StyledBuffer::default();
34 let mut style = Style::default();
35 style.set_foreground_color(Color::DarkGrey);
36 styled_buffer.insert_styled_string(hint, style);
37 return Some(styled_buffer);
38 }
39 }
40 }
41 None
42 }
More examples
19 fn hint(&self, buffer: &mut StyledBuffer) -> Option<StyledBuffer> {
20 if let Some(keyword) = buffer.last_alphabetic_keyword() {
21 let keyword_lower = keyword.to_lowercase();
22 for word in GITQL_RESERVED_KEYWORDS {
23 if word.starts_with(&keyword_lower) {
24 let hint = &word[keyword.len()..];
25 let mut styled_buffer = StyledBuffer::default();
26 let mut style = Style::default();
27 style.set_foreground_color(Color::DarkGrey);
28 styled_buffer.insert_styled_string(hint, style);
29 return Some(styled_buffer);
30 }
31 }
32 }
33 None
34 }
Sourcepub fn move_char_right(&mut self)
pub fn move_char_right(&mut self)
Safe Move the cursor position to the right
Sourcepub fn move_char_left(&mut self)
pub fn move_char_left(&mut self)
Safe Move the cursor position to the left
Sourcepub fn move_word_right(&mut self)
pub fn move_word_right(&mut self)
Move the cursor to the begin of the next right word
Sourcepub fn move_word_left(&mut self)
pub fn move_word_left(&mut self)
Move the cursor to the begin of the next right word
Sourcepub fn move_to_start(&mut self)
pub fn move_to_start(&mut self)
Move cursor to the start of the buffer
Sourcepub fn move_to_end(&mut self)
pub fn move_to_end(&mut self)
Move cursor to the end of the buffer
Sourcepub fn delete_right_char(&mut self)
pub fn delete_right_char(&mut self)
Deletes one character to the right
Sourcepub fn delete_left_char(&mut self)
pub fn delete_left_char(&mut self)
Deletes one character to the left
Sourcepub fn delete_range(&mut self, from: usize, to: usize)
pub fn delete_range(&mut self, from: usize, to: usize)
Deletes range of characters and styles from buffer
Sourcepub fn buffer(&mut self) -> &Vec<char>
pub fn buffer(&mut self) -> &Vec<char>
Get current Buffer
Examples found in repository?
76 fn highlight(&self, buffer: &mut StyledBuffer) {
77 let lines = buffer.buffer().clone();
78 let mut i: usize = 0;
79
80 let mut keyword_style = Style::default();
81 keyword_style.set_foreground_color(Color::Magenta);
82
83 let mut string_style = Style::default();
84 string_style.set_foreground_color(Color::Yellow);
85
86 loop {
87 if i >= lines.len() {
88 break;
89 }
90
91 // Highlight String literal
92 if lines[i] == '"' {
93 buffer.style_char(i, string_style.clone());
94 i += 1;
95
96 while i < lines.len() && lines[i] != '"' {
97 buffer.style_char(i, string_style.clone());
98 i += 1;
99 }
100
101 if i < lines.len() && lines[i] == '"' {
102 buffer.style_char(i, string_style.clone());
103 i += 1;
104 }
105
106 continue;
107 }
108
109 // Highlight reserved keyword
110 if lines[i].is_alphabetic() {
111 let start = i;
112 let mut keyword = String::new();
113 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
114 keyword.push(lines[i]);
115 i += 1;
116 }
117
118 keyword = keyword.to_lowercase();
119 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
120 buffer.style_range(start, i, keyword_style.clone())
121 }
122 continue;
123 }
124
125 i += 1;
126 }
127 }
128}
129
130#[derive(Default)]
131pub struct MatchingBracketsHighlighter;
132
133impl Highlighter for MatchingBracketsHighlighter {
134 fn highlight(&self, buffer: &mut StyledBuffer) {
135 let colors = vec![Color::Red, Color::Blue, Color::Yellow, Color::Green];
136 let mut brackets_stack: Vec<Color> = vec![];
137 let mut current_color_index = 0;
138
139 let lines = buffer.buffer().clone();
140 let mut i: usize = 0;
141 loop {
142 if i >= lines.len() {
143 break;
144 }
145
146 if lines[i] == '"' {
147 i += 1;
148 while i < lines.len() && lines[i] != '"' {
149 i += 1;
150 }
151
152 if i < lines.len() {
153 i += 1;
154 }
155 continue;
156 }
157
158 if lines[i] == '(' || lines[i] == '<' || lines[i] == '[' || lines[i] == '{' {
159 if current_color_index >= colors.len() {
160 current_color_index = 0;
161 }
162
163 let color = colors[current_color_index];
164 current_color_index += 1;
165
166 brackets_stack.push(color);
167
168 let mut style = Style::default();
169 style.set_foreground_color(color);
170 buffer.style_char(i, style);
171 i += 1;
172 continue;
173 }
174
175 if lines[i] == ')' || lines[i] == '>' || lines[i] == ']' || lines[i] == '}' {
176 let color = if brackets_stack.is_empty() {
177 colors[0]
178 } else {
179 brackets_stack.pop().unwrap()
180 };
181
182 let mut style = Style::default();
183 style.set_foreground_color(color);
184 buffer.style_char(i, style);
185
186 i += 1;
187 continue;
188 }
189 i += 1;
190 }
191 }
More examples
19 fn highlight(&self, buffer: &mut StyledBuffer) {
20 let lines = buffer.buffer().clone();
21 let mut i: usize = 0;
22
23 let mut keyword_style = Style::default();
24 keyword_style.set_foreground_color(Color::Magenta);
25
26 let mut string_style = Style::default();
27 string_style.set_foreground_color(Color::Yellow);
28
29 loop {
30 if i >= lines.len() {
31 break;
32 }
33
34 // Highlight String literal
35 if lines[i] == '"' {
36 buffer.style_char(i, string_style.clone());
37 i += 1;
38
39 while i < lines.len() && lines[i] != '"' {
40 buffer.style_char(i, string_style.clone());
41 i += 1;
42 }
43
44 if i < lines.len() && lines[i] == '"' {
45 buffer.style_char(i, string_style.clone());
46 i += 1;
47 }
48
49 continue;
50 }
51
52 // Highlight reserved keyword
53 if lines[i].is_alphabetic() {
54 let start = i;
55 let mut keyword = String::new();
56 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
57 keyword.push(lines[i]);
58 i += 1;
59 }
60
61 keyword = keyword.to_lowercase();
62 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
63 buffer.style_range(start, i, keyword_style.clone())
64 }
65 continue;
66 }
67
68 i += 1;
69 }
70 }
13 fn highlight(&self, buffer: &mut StyledBuffer) {
14 let lines = buffer.buffer().clone();
15 let mut i: usize = 0;
16
17 loop {
18 if i >= lines.len() {
19 break;
20 }
21
22 // Highlight String literal
23 if lines[i] == '"' {
24 i += 1;
25
26 while i < lines.len() && lines[i] != '"' {
27 i += 1;
28 }
29
30 if i < lines.len() && lines[i] == '"' {
31 i += 1;
32 }
33
34 continue;
35 }
36
37 // Highlight hex value background with it value
38 if lines[i] == '#' && i + 6 < lines.len() {
39 let start = i;
40 i += 1;
41 let hex_value = &lines[i..i + 6];
42 for ch in hex_value {
43 if !ch.is_ascii_hexdigit() {
44 return;
45 }
46 }
47 let hex_string = hex_value.iter().cloned().collect::<String>();
48 if let Ok(hex_value) = usize::from_str_radix(&hex_string, 16) {
49 let red = (hex_value >> 16) & 0xFF;
50 let green = (hex_value >> 8) & 0xFF;
51 let blue = hex_value & 0xFF;
52 let mut style = Style::default();
53 style.set_background_color(Color::Rgb {
54 r: red as u8,
55 g: green as u8,
56 b: blue as u8,
57 });
58 buffer.style_range(start, start + 7, style);
59 }
60 }
61
62 i += 1;
63 }
64 }
13 fn highlight(&self, buffer: &mut StyledBuffer) {
14 let colors = vec![Color::Red, Color::Blue, Color::Yellow, Color::Green];
15 let mut brackets_stack: Vec<Color> = vec![];
16 let mut current_color_index = 0;
17
18 let lines = buffer.buffer().clone();
19 let mut i: usize = 0;
20 loop {
21 if i >= lines.len() {
22 break;
23 }
24
25 if lines[i] == '"' {
26 i += 1;
27 while i < lines.len() && lines[i] != '"' {
28 i += 1;
29 }
30
31 if i < lines.len() {
32 i += 1;
33 }
34 continue;
35 }
36
37 if lines[i] == '(' || lines[i] == '<' || lines[i] == '[' || lines[i] == '{' {
38 if current_color_index >= colors.len() {
39 current_color_index = 0;
40 }
41
42 let color = colors[current_color_index];
43 current_color_index += 1;
44
45 brackets_stack.push(color);
46
47 let mut style = Style::default();
48 style.set_foreground_color(color);
49 buffer.style_char(i, style);
50 i += 1;
51 continue;
52 }
53
54 if lines[i] == ')' || lines[i] == '>' || lines[i] == ']' || lines[i] == '}' {
55 let color = if brackets_stack.is_empty() {
56 colors[0]
57 } else {
58 brackets_stack.pop().unwrap()
59 };
60
61 let mut style = Style::default();
62 style.set_foreground_color(color);
63 buffer.style_char(i, style);
64
65 i += 1;
66 continue;
67 }
68 i += 1;
69 }
70 }
Sourcepub fn sub_string(&self, start: usize, end: usize) -> Option<String>
pub fn sub_string(&self, start: usize, end: usize) -> Option<String>
Get the sub string from the provided range, or None if range is invalid
Sourcepub fn last_alphabetic_keyword(&self) -> Option<String>
pub fn last_alphabetic_keyword(&self) -> Option<String>
Return the last keyword that contains alphabetic characters on the buffer or None
Examples found in repository?
27 fn hint(&self, buffer: &mut StyledBuffer) -> Option<StyledBuffer> {
28 if let Some(keyword) = buffer.last_alphabetic_keyword() {
29 let keyword_lower = keyword.to_lowercase();
30 for word in GITQL_RESERVED_KEYWORDS {
31 if word.starts_with(&keyword_lower) {
32 let hint = &word[keyword.len()..];
33 let mut styled_buffer = StyledBuffer::default();
34 let mut style = Style::default();
35 style.set_foreground_color(Color::DarkGrey);
36 styled_buffer.insert_styled_string(hint, style);
37 return Some(styled_buffer);
38 }
39 }
40 }
41 None
42 }
43}
44
45pub struct FixedCompleter;
46
47impl Completer for FixedCompleter {
48 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
49 let mut suggestions: Vec<Suggestion> = vec![];
50 if input.position() != input.len() {
51 return suggestions;
52 }
53
54 if let Some(keyword) = input.last_alphabetic_keyword() {
55 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
56 if reserved_keyword.starts_with(&keyword) {
57 let suggestion = Suggestion {
58 content: StyledBuffer::from(reserved_keyword),
59 span: Span {
60 start: input.len() - keyword.len(),
61 end: input.len(),
62 },
63 };
64 suggestions.push(suggestion);
65 }
66 }
67 }
68 suggestions
69 }
More examples
19 fn hint(&self, buffer: &mut StyledBuffer) -> Option<StyledBuffer> {
20 if let Some(keyword) = buffer.last_alphabetic_keyword() {
21 let keyword_lower = keyword.to_lowercase();
22 for word in GITQL_RESERVED_KEYWORDS {
23 if word.starts_with(&keyword_lower) {
24 let hint = &word[keyword.len()..];
25 let mut styled_buffer = StyledBuffer::default();
26 let mut style = Style::default();
27 style.set_foreground_color(Color::DarkGrey);
28 styled_buffer.insert_styled_string(hint, style);
29 return Some(styled_buffer);
30 }
31 }
32 }
33 None
34 }
21 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
22 let mut suggestions: Vec<Suggestion> = vec![];
23 if input.position() != input.len() {
24 return suggestions;
25 }
26
27 if let Some(keyword) = input.last_alphabetic_keyword() {
28 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
29 if reserved_keyword.starts_with(&keyword) {
30 let suggestion = Suggestion {
31 content: StyledBuffer::from(reserved_keyword),
32 span: Span {
33 start: input.len() - keyword.len(),
34 end: input.len(),
35 },
36 };
37 suggestions.push(suggestion);
38 }
39 }
40 }
41 suggestions
42 }
Sourcepub fn set_styles(&mut self, styles: &mut Vec<Style>)
pub fn set_styles(&mut self, styles: &mut Vec<Style>)
Update the current list of styles
Sourcepub fn style_char(&mut self, position: usize, style: Style)
pub fn style_char(&mut self, position: usize, style: Style)
Set style for one character
Examples found in repository?
76 fn highlight(&self, buffer: &mut StyledBuffer) {
77 let lines = buffer.buffer().clone();
78 let mut i: usize = 0;
79
80 let mut keyword_style = Style::default();
81 keyword_style.set_foreground_color(Color::Magenta);
82
83 let mut string_style = Style::default();
84 string_style.set_foreground_color(Color::Yellow);
85
86 loop {
87 if i >= lines.len() {
88 break;
89 }
90
91 // Highlight String literal
92 if lines[i] == '"' {
93 buffer.style_char(i, string_style.clone());
94 i += 1;
95
96 while i < lines.len() && lines[i] != '"' {
97 buffer.style_char(i, string_style.clone());
98 i += 1;
99 }
100
101 if i < lines.len() && lines[i] == '"' {
102 buffer.style_char(i, string_style.clone());
103 i += 1;
104 }
105
106 continue;
107 }
108
109 // Highlight reserved keyword
110 if lines[i].is_alphabetic() {
111 let start = i;
112 let mut keyword = String::new();
113 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
114 keyword.push(lines[i]);
115 i += 1;
116 }
117
118 keyword = keyword.to_lowercase();
119 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
120 buffer.style_range(start, i, keyword_style.clone())
121 }
122 continue;
123 }
124
125 i += 1;
126 }
127 }
128}
129
130#[derive(Default)]
131pub struct MatchingBracketsHighlighter;
132
133impl Highlighter for MatchingBracketsHighlighter {
134 fn highlight(&self, buffer: &mut StyledBuffer) {
135 let colors = vec![Color::Red, Color::Blue, Color::Yellow, Color::Green];
136 let mut brackets_stack: Vec<Color> = vec![];
137 let mut current_color_index = 0;
138
139 let lines = buffer.buffer().clone();
140 let mut i: usize = 0;
141 loop {
142 if i >= lines.len() {
143 break;
144 }
145
146 if lines[i] == '"' {
147 i += 1;
148 while i < lines.len() && lines[i] != '"' {
149 i += 1;
150 }
151
152 if i < lines.len() {
153 i += 1;
154 }
155 continue;
156 }
157
158 if lines[i] == '(' || lines[i] == '<' || lines[i] == '[' || lines[i] == '{' {
159 if current_color_index >= colors.len() {
160 current_color_index = 0;
161 }
162
163 let color = colors[current_color_index];
164 current_color_index += 1;
165
166 brackets_stack.push(color);
167
168 let mut style = Style::default();
169 style.set_foreground_color(color);
170 buffer.style_char(i, style);
171 i += 1;
172 continue;
173 }
174
175 if lines[i] == ')' || lines[i] == '>' || lines[i] == ']' || lines[i] == '}' {
176 let color = if brackets_stack.is_empty() {
177 colors[0]
178 } else {
179 brackets_stack.pop().unwrap()
180 };
181
182 let mut style = Style::default();
183 style.set_foreground_color(color);
184 buffer.style_char(i, style);
185
186 i += 1;
187 continue;
188 }
189 i += 1;
190 }
191 }
More examples
19 fn highlight(&self, buffer: &mut StyledBuffer) {
20 let lines = buffer.buffer().clone();
21 let mut i: usize = 0;
22
23 let mut keyword_style = Style::default();
24 keyword_style.set_foreground_color(Color::Magenta);
25
26 let mut string_style = Style::default();
27 string_style.set_foreground_color(Color::Yellow);
28
29 loop {
30 if i >= lines.len() {
31 break;
32 }
33
34 // Highlight String literal
35 if lines[i] == '"' {
36 buffer.style_char(i, string_style.clone());
37 i += 1;
38
39 while i < lines.len() && lines[i] != '"' {
40 buffer.style_char(i, string_style.clone());
41 i += 1;
42 }
43
44 if i < lines.len() && lines[i] == '"' {
45 buffer.style_char(i, string_style.clone());
46 i += 1;
47 }
48
49 continue;
50 }
51
52 // Highlight reserved keyword
53 if lines[i].is_alphabetic() {
54 let start = i;
55 let mut keyword = String::new();
56 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
57 keyword.push(lines[i]);
58 i += 1;
59 }
60
61 keyword = keyword.to_lowercase();
62 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
63 buffer.style_range(start, i, keyword_style.clone())
64 }
65 continue;
66 }
67
68 i += 1;
69 }
70 }
13 fn highlight(&self, buffer: &mut StyledBuffer) {
14 let colors = vec![Color::Red, Color::Blue, Color::Yellow, Color::Green];
15 let mut brackets_stack: Vec<Color> = vec![];
16 let mut current_color_index = 0;
17
18 let lines = buffer.buffer().clone();
19 let mut i: usize = 0;
20 loop {
21 if i >= lines.len() {
22 break;
23 }
24
25 if lines[i] == '"' {
26 i += 1;
27 while i < lines.len() && lines[i] != '"' {
28 i += 1;
29 }
30
31 if i < lines.len() {
32 i += 1;
33 }
34 continue;
35 }
36
37 if lines[i] == '(' || lines[i] == '<' || lines[i] == '[' || lines[i] == '{' {
38 if current_color_index >= colors.len() {
39 current_color_index = 0;
40 }
41
42 let color = colors[current_color_index];
43 current_color_index += 1;
44
45 brackets_stack.push(color);
46
47 let mut style = Style::default();
48 style.set_foreground_color(color);
49 buffer.style_char(i, style);
50 i += 1;
51 continue;
52 }
53
54 if lines[i] == ')' || lines[i] == '>' || lines[i] == ']' || lines[i] == '}' {
55 let color = if brackets_stack.is_empty() {
56 colors[0]
57 } else {
58 brackets_stack.pop().unwrap()
59 };
60
61 let mut style = Style::default();
62 style.set_foreground_color(color);
63 buffer.style_char(i, style);
64
65 i += 1;
66 continue;
67 }
68 i += 1;
69 }
70 }
Sourcepub fn style_range(&mut self, start: usize, end: usize, style: Style)
pub fn style_range(&mut self, start: usize, end: usize, style: Style)
Set style for a range of characters
Examples found in repository?
76 fn highlight(&self, buffer: &mut StyledBuffer) {
77 let lines = buffer.buffer().clone();
78 let mut i: usize = 0;
79
80 let mut keyword_style = Style::default();
81 keyword_style.set_foreground_color(Color::Magenta);
82
83 let mut string_style = Style::default();
84 string_style.set_foreground_color(Color::Yellow);
85
86 loop {
87 if i >= lines.len() {
88 break;
89 }
90
91 // Highlight String literal
92 if lines[i] == '"' {
93 buffer.style_char(i, string_style.clone());
94 i += 1;
95
96 while i < lines.len() && lines[i] != '"' {
97 buffer.style_char(i, string_style.clone());
98 i += 1;
99 }
100
101 if i < lines.len() && lines[i] == '"' {
102 buffer.style_char(i, string_style.clone());
103 i += 1;
104 }
105
106 continue;
107 }
108
109 // Highlight reserved keyword
110 if lines[i].is_alphabetic() {
111 let start = i;
112 let mut keyword = String::new();
113 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
114 keyword.push(lines[i]);
115 i += 1;
116 }
117
118 keyword = keyword.to_lowercase();
119 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
120 buffer.style_range(start, i, keyword_style.clone())
121 }
122 continue;
123 }
124
125 i += 1;
126 }
127 }
More examples
19 fn highlight(&self, buffer: &mut StyledBuffer) {
20 let lines = buffer.buffer().clone();
21 let mut i: usize = 0;
22
23 let mut keyword_style = Style::default();
24 keyword_style.set_foreground_color(Color::Magenta);
25
26 let mut string_style = Style::default();
27 string_style.set_foreground_color(Color::Yellow);
28
29 loop {
30 if i >= lines.len() {
31 break;
32 }
33
34 // Highlight String literal
35 if lines[i] == '"' {
36 buffer.style_char(i, string_style.clone());
37 i += 1;
38
39 while i < lines.len() && lines[i] != '"' {
40 buffer.style_char(i, string_style.clone());
41 i += 1;
42 }
43
44 if i < lines.len() && lines[i] == '"' {
45 buffer.style_char(i, string_style.clone());
46 i += 1;
47 }
48
49 continue;
50 }
51
52 // Highlight reserved keyword
53 if lines[i].is_alphabetic() {
54 let start = i;
55 let mut keyword = String::new();
56 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
57 keyword.push(lines[i]);
58 i += 1;
59 }
60
61 keyword = keyword.to_lowercase();
62 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
63 buffer.style_range(start, i, keyword_style.clone())
64 }
65 continue;
66 }
67
68 i += 1;
69 }
70 }
13 fn highlight(&self, buffer: &mut StyledBuffer) {
14 let lines = buffer.buffer().clone();
15 let mut i: usize = 0;
16
17 loop {
18 if i >= lines.len() {
19 break;
20 }
21
22 // Highlight String literal
23 if lines[i] == '"' {
24 i += 1;
25
26 while i < lines.len() && lines[i] != '"' {
27 i += 1;
28 }
29
30 if i < lines.len() && lines[i] == '"' {
31 i += 1;
32 }
33
34 continue;
35 }
36
37 // Highlight hex value background with it value
38 if lines[i] == '#' && i + 6 < lines.len() {
39 let start = i;
40 i += 1;
41 let hex_value = &lines[i..i + 6];
42 for ch in hex_value {
43 if !ch.is_ascii_hexdigit() {
44 return;
45 }
46 }
47 let hex_string = hex_value.iter().cloned().collect::<String>();
48 if let Ok(hex_value) = usize::from_str_radix(&hex_string, 16) {
49 let red = (hex_value >> 16) & 0xFF;
50 let green = (hex_value >> 8) & 0xFF;
51 let blue = hex_value & 0xFF;
52 let mut style = Style::default();
53 style.set_background_color(Color::Rgb {
54 r: red as u8,
55 g: green as u8,
56 b: blue as u8,
57 });
58 buffer.style_range(start, start + 7, style);
59 }
60 }
61
62 i += 1;
63 }
64 }
Sourcepub fn reset_styles(&mut self)
pub fn reset_styles(&mut self)
Reset all styles to the default one
pub fn set_position(&mut self, pos: usize)
Sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
Get cursor position
Examples found in repository?
48 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
49 let mut suggestions: Vec<Suggestion> = vec![];
50 if input.position() != input.len() {
51 return suggestions;
52 }
53
54 if let Some(keyword) = input.last_alphabetic_keyword() {
55 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
56 if reserved_keyword.starts_with(&keyword) {
57 let suggestion = Suggestion {
58 content: StyledBuffer::from(reserved_keyword),
59 span: Span {
60 start: input.len() - keyword.len(),
61 end: input.len(),
62 },
63 };
64 suggestions.push(suggestion);
65 }
66 }
67 }
68 suggestions
69 }
More examples
21 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
22 let mut suggestions: Vec<Suggestion> = vec![];
23 if input.position() != input.len() {
24 return suggestions;
25 }
26
27 if let Some(keyword) = input.last_alphabetic_keyword() {
28 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
29 if reserved_keyword.starts_with(&keyword) {
30 let suggestion = Suggestion {
31 content: StyledBuffer::from(reserved_keyword),
32 span: Span {
33 start: input.len() - keyword.len(),
34 end: input.len(),
35 },
36 };
37 suggestions.push(suggestion);
38 }
39 }
40 }
41 suggestions
42 }
Sourcepub fn is_cursor_at_the_end(&self) -> bool
pub fn is_cursor_at_the_end(&self) -> bool
Returns true if the cursor position is at the end of the buffer
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Length of the buffer
Examples found in repository?
48 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
49 let mut suggestions: Vec<Suggestion> = vec![];
50 if input.position() != input.len() {
51 return suggestions;
52 }
53
54 if let Some(keyword) = input.last_alphabetic_keyword() {
55 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
56 if reserved_keyword.starts_with(&keyword) {
57 let suggestion = Suggestion {
58 content: StyledBuffer::from(reserved_keyword),
59 span: Span {
60 start: input.len() - keyword.len(),
61 end: input.len(),
62 },
63 };
64 suggestions.push(suggestion);
65 }
66 }
67 }
68 suggestions
69 }
More examples
21 fn complete(&self, input: &StyledBuffer) -> Vec<Suggestion> {
22 let mut suggestions: Vec<Suggestion> = vec![];
23 if input.position() != input.len() {
24 return suggestions;
25 }
26
27 if let Some(keyword) = input.last_alphabetic_keyword() {
28 for reserved_keyword in GITQL_RESERVED_KEYWORDS {
29 if reserved_keyword.starts_with(&keyword) {
30 let suggestion = Suggestion {
31 content: StyledBuffer::from(reserved_keyword),
32 span: Span {
33 start: input.len() - keyword.len(),
34 end: input.len(),
35 },
36 };
37 suggestions.push(suggestion);
38 }
39 }
40 }
41 suggestions
42 }
Trait Implementations§
Source§impl Default for StyledBuffer
Create default instance of StyledBuffer
impl Default for StyledBuffer
Create default instance of StyledBuffer