Skip to content

Commit 5da00de

Browse files
authored
Make print_prompt() a fn
1 parent 13d7d63 commit 5da00de

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/main.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,28 +583,26 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
583583
use std::io::{self, BufRead, Write};
584584

585585
println!(
586-
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
586+
"Welcome to the magnificent Rust Python {} interpreter!",
587587
crate_version!()
588588
);
589589

590-
let stdin = io::stdin();
591-
let stdout = io::stdout();
592-
let mut stdout = stdout.lock();
593-
594-
let mut print_prompt = || {
590+
fn print_prompt() {
595591
let prompt = get_prompt(vm, "ps1");
596592
let prompt = match prompt {
597593
Some(ref s) => s.as_str(),
598594
None => "",
599595
};
600596
print!("{}", prompt);
601-
stdout.flush().expect("flush failed");
602-
};
597+
io::stdout().lock().flush().expect("flush failed");
598+
}
599+
600+
let stdin = io::stdin();
603601

604602
print_prompt();
605603
for line in stdin.lock().lines() {
606604
let mut line = line.expect("line failed");
607-
line.push('\n');
605+
line.push_str("\n");
608606
match shell_exec(vm, &line, scope.clone()) {
609607
ShellExecResult::Ok => {}
610608
ShellExecResult::Continue => println!("Unexpected EOF"),

0 commit comments

Comments
 (0)