Skip to content

Commit 5dd5b44

Browse files
committed
Use the rustyline prompt on redox
1 parent b7a11df commit 5dd5b44

File tree

5 files changed

+35
-112
lines changed

5 files changed

+35
-112
lines changed

Cargo.lock

Lines changed: 25 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ dirs = "2.0"
3131
flame = { version = "0.2", optional = true }
3232
flamescope = { version = "0.1", optional = true }
3333

34-
[target.'cfg(not(target_os = "redox"))'.dependencies]
35-
rustyline = "4.1.0"
34+
rustyline = "=5.0.1"
3635

3736

3837
[dev-dependencies.cpython]
@@ -45,6 +44,5 @@ path = "src/main.rs"
4544
[patch.crates-io]
4645
# REDOX START, Uncommment when you want to compile/check with redoxer
4746
# time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" }
48-
# libc = { git = "https://github.com/AdminXVII/libc", branch = "extra-traits-redox" }
4947
# nix = { git = "https://github.com/AdminXVII/nix", branch = "add-redox-support" }
5048
# REDOX END

src/main.rs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use clap::{App, AppSettings, Arg, ArgMatches};
88
use rustpython_compiler::{compile, error::CompileError, error::CompileErrorType};
99
use rustpython_parser::error::ParseErrorType;
1010
use rustpython_vm::{
11-
import,
12-
obj::objstr::PyStringRef,
13-
print_exception,
11+
import, print_exception,
1412
pyobject::{ItemProtocol, PyObjectRef, PyResult},
1513
scope::Scope,
1614
util, PySettings, VirtualMachine,
@@ -463,13 +461,6 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul
463461
}
464462
}
465463

466-
fn get_prompt(vm: &VirtualMachine, prompt_name: &str) -> Option<PyStringRef> {
467-
vm.get_attribute(vm.sys_module.clone(), prompt_name)
468-
.and_then(|prompt| vm.to_str(&prompt))
469-
.ok()
470-
}
471-
472-
#[cfg(not(target_os = "redox"))]
473464
fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
474465
use rustyline::{error::ReadlineError, Editor};
475466

@@ -505,14 +496,13 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
505496
let mut continuing = false;
506497

507498
loop {
508-
let prompt = if continuing {
509-
get_prompt(vm, "ps2")
510-
} else {
511-
get_prompt(vm, "ps1")
512-
};
499+
let prompt_name = if continuing { "ps2" } else { "ps1" };
500+
let prompt = vm
501+
.get_attribute(vm.sys_module.clone(), prompt_name)
502+
.and_then(|prompt| vm.to_str(&prompt));
513503
let prompt = match prompt {
514-
Some(ref s) => s.as_str(),
515-
None => "",
504+
Ok(ref s) => s.as_str(),
505+
Err(_) => "",
516506
};
517507
let result = match repl.readline(prompt) {
518508
Ok(line) => {
@@ -577,39 +567,3 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
577567

578568
Ok(())
579569
}
580-
581-
#[cfg(target_os = "redox")]
582-
fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
583-
use std::io::{self, BufRead, Write};
584-
585-
println!(
586-
"Welcome to the magnificent Rust Python {} interpreter!",
587-
crate_version!()
588-
);
589-
590-
fn print_prompt(vm: &VirtualMachine) {
591-
let prompt = get_prompt(vm, "ps1");
592-
let prompt = match prompt {
593-
Some(ref s) => s.as_str(),
594-
None => "",
595-
};
596-
print!("{}", prompt);
597-
io::stdout().lock().flush().expect("flush failed");
598-
}
599-
600-
let stdin = io::stdin();
601-
602-
print_prompt(vm);
603-
for line in stdin.lock().lines() {
604-
let mut line = line.expect("line failed");
605-
line.push_str("\n");
606-
match shell_exec(vm, &line, scope.clone()) {
607-
ShellExecResult::Ok => {}
608-
ShellExecResult::Continue => println!("Unexpected EOF"),
609-
ShellExecResult::PyErr(exc) => print_exception(vm, &exc),
610-
}
611-
print_prompt(vm);
612-
}
613-
614-
Ok(())
615-
}

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ blake2 = "0.8"
2626

2727
num-complex = { version = "0.2", features = ["serde"] }
2828
num-bigint = { version = "0.2", features = ["serde"] }
29-
num-traits = "0.2.6"
29+
num-traits = "=0.2.6"
3030
num-integer = "0.1.39"
3131
num-rational = "0.2.1"
3232
num-iter = "0.1"

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
12291229
"openpty" => ctx.new_rustfunc(os_openpty),
12301230
});
12311231

1232-
#[cfg(not(target_os = "macos"))]
1232+
#[cfg(not(any(target_os = "macos", target_os = "android", target_os = "redox")))]
12331233
extend_module!(vm, module, {
12341234
"SEEK_DATA" => ctx.new_int(Whence::SeekData as i8),
12351235
"SEEK_HOLE" => ctx.new_int(Whence::SeekHole as i8)

0 commit comments

Comments
 (0)