MCPcopy Create free account
hub / github.com/Autoparallel/learner / draw_command_input

Method draw_command_input

crates/learnerd/src/tui/ui.rs:224–293  ·  view source on GitHub ↗

Draws the command input area

(&mut self)

Source from the content-addressed store, hash-verified

222
223 /// Draws the command input area
224 fn draw_command_input(&mut self) {
225 let area = Rect {
226 x: 0,
227 y: self.frame.area().height - 1,
228 width: self.frame.area().width,
229 height: 1,
230 };
231
232 // Construct the display string with cursor
233 let buffer = &self.state.command_buffer;
234 let before_cursor = &buffer.input[..buffer.cursor_position];
235 let after_cursor = &buffer.input[buffer.cursor_position..];
236 let cursor_char = if buffer.cursor_position < buffer.input.len() {
237 &buffer.input[buffer.cursor_position..].chars().next().unwrap().to_string()
238 } else {
239 " "
240 };
241
242 // Show error or completions if any
243 let mut command_content = Vec::new();
244 if let Some(error) = &buffer.error {
245 command_content.push(Span::styled(":", Style::default().fg(Color::Yellow)));
246 command_content.push(Span::styled(before_cursor, Style::default().fg(Color::Yellow)));
247 command_content.push(Span::styled(
248 cursor_char,
249 Style::default().fg(Color::Yellow).bg(Color::DarkGray).add_modifier(Modifier::BOLD),
250 ));
251 command_content.push(Span::styled(
252 if buffer.cursor_position < buffer.input.len() { &after_cursor[1..] } else { "" },
253 Style::default().fg(Color::Yellow),
254 ));
255
256 // Draw error message above command line
257 let error_area = Rect { x: 0, y: area.y - 1, width: area.width, height: 1 };
258 let error_text = Paragraph::new(Line::from(vec![
259 Span::styled("Error: ", Style::default().fg(Color::Red)),
260 Span::styled(error, Style::default().fg(Color::Red)),
261 ]));
262 self.frame.render_widget(Clear, error_area);
263 self.frame.render_widget(error_text, error_area);
264 } else {
265 // Show completions if we're at the end of the input
266 let completions = buffer.get_completions();
267 if !completions.is_empty() && buffer.cursor_position == buffer.input.len() {
268 let completions_area =
269 Rect { x: 0, y: area.y - 1, width: area.width, height: 1 };
270 let completion_text = Paragraph::new(Line::from(vec![
271 Span::styled("Completions: ", Style::default().fg(Color::Blue)),
272 Span::styled(completions.join(" "), Style::default().fg(Color::White)),
273 ]));
274 self.frame.render_widget(Clear, completions_area);
275 self.frame.render_widget(completion_text, completions_area);
276 }
277
278 command_content.push(Span::styled(":", Style::default().fg(Color::Yellow)));
279 command_content.push(Span::styled(before_cursor, Style::default().fg(Color::Yellow)));
280 command_content.push(Span::styled(
281 cursor_char,

Callers 1

drawMethod · 0.80

Calls 2

get_completionsMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected