MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / input

Method input

src/sys/prompt.rs:462–508  ·  view source on GitHub ↗

Input

(&mut self, prompt: &str)

Source from the content-addressed store, hash-verified

460
461 // Input
462 pub fn input(&mut self, prompt: &str) -> Option<String>
463 {
464 print!("{}", prompt);
465 self.offset = offset_from_prompt(prompt);
466 self.cur = self.offset;
467 self.ln = Vec::with_capacity(80);
468 let mut parser = Parser::new();
469
470 while let Some(c) = crate::io::stdin().readchar()
471 {
472 match c
473 {
474 // End of text
475 '\x03' =>
476 {
477 println!();
478 return Some(String::new());
479 }
480
481 // End of transmission
482 '\x04' =>
483 {
484 println!();
485 return None;
486 },
487
488 // New line
489 '\n' =>
490 {
491 self.compupdate();
492 self.histupdate();
493 println!();
494 return Some(self.ln.iter().collect());
495 },
496
497 c =>
498 {
499 for b in c.to_string().as_bytes()
500 {
501 parser.advance(self, *b);
502 }
503 }
504 }
505 }
506
507 None
508 }
509
510
511 // New

Callers 1

runFunction · 0.80

Calls 5

offset_from_promptFunction · 0.85
readcharMethod · 0.80
compupdateMethod · 0.80
histupdateMethod · 0.80
stdinFunction · 0.50

Tested by

no test coverage detected