MCPcopy Create free account
hub / github.com/GCWing/BitFun / run

Method run

src/apps/cli/src/ui/startup.rs:305–382  ·  view source on GitHub ↗
(&mut self, terminal: &mut Terminal<B>)

Source from the content-addressed store, hash-verified

303 }
304
305 pub fn run<B: Backend>(&mut self, terminal: &mut Terminal<B>) -> Result<StartupResult> {
306 terminal.clear()?;
307
308 loop {
309 terminal.draw(|f| self.render(f))?;
310
311 if event::poll(Duration::from_millis(50))? {
312 if let Ok(first_event) = event::read() {
313 let mut events = vec![first_event];
314 // Short wait to let rapid paste events arrive in the same batch.
315 // Duration::ZERO would split pastes across loop iterations.
316 while event::poll(Duration::from_millis(5))? {
317 if let Ok(ev) = event::read() {
318 events.push(ev);
319 } else {
320 break;
321 }
322 }
323
324 // Paste detection: multiple key events with Enter + printable chars
325 let key_count = events
326 .iter()
327 .filter(|e| matches!(e, Event::Key(k) if k.kind == KeyEventKind::Press || k.kind == KeyEventKind::Repeat))
328 .count();
329 let has_enter = events.iter().any(|e| {
330 matches!(e, Event::Key(k) if (k.kind == KeyEventKind::Press || k.kind == KeyEventKind::Repeat) && k.code == KeyCode::Enter)
331 });
332 let has_printable = events.iter().any(|e| {
333 matches!(e, Event::Key(k) if (k.kind == KeyEventKind::Press || k.kind == KeyEventKind::Repeat) && matches!(k.code, KeyCode::Char(_)))
334 });
335 let is_paste_batch = key_count > 1 && has_enter && has_printable;
336
337 if is_paste_batch {
338 let mut paste_buf = String::new();
339 let mut non_key_events = Vec::new();
340 for ev in events {
341 match ev {
342 Event::Key(k)
343 if k.kind == KeyEventKind::Press
344 || k.kind == KeyEventKind::Repeat =>
345 {
346 match k.code {
347 KeyCode::Char(c) => paste_buf.push(c),
348 KeyCode::Enter => paste_buf.push('\n'),
349 _ => {}
350 }
351 }
352 other => non_key_events.push(other),
353 }
354 }
355 if !paste_buf.is_empty() {
356 self.text_input.insert_paste(&paste_buf);
357 self.refresh_command_menu();
358 }
359 for ev in non_key_events {
360 self.handle_non_key_event(ev, terminal)?;
361 }
362 } else {

Callers 7

runFunction · 0.45
get_announcement_tipsFunction · 0.45
handle_exec_commandFunction · 0.45
run_interactiveFunction · 0.45
runFunction · 0.45

Calls 12

pollFunction · 0.85
readFunction · 0.85
iterMethod · 0.80
insert_pasteMethod · 0.80
handle_keyMethod · 0.80
renderMethod · 0.65
clearMethod · 0.45
pushMethod · 0.45
countMethod · 0.45
is_emptyMethod · 0.45
refresh_command_menuMethod · 0.45
handle_non_key_eventMethod · 0.45

Tested by

no test coverage detected