mirror of
https://github.com/rm-dr/daisy
synced 2025-08-02 01:34:50 -07:00
Cleaned up context argument
This commit is contained in:
@ -37,9 +37,9 @@ impl PromptBuffer {
|
||||
}
|
||||
|
||||
// Same as write_primpt, but pretends there is no cursor
|
||||
pub fn write_prompt_nocursor(&mut self, stdout: &mut RawTerminal<std::io::Stdout>, context: &Context) -> Result<(), std::io::Error> {
|
||||
pub fn write_prompt_nocursor(&mut self, context: &Context, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> {
|
||||
// Draw prettyprinted expression
|
||||
let (_, s) = substitute_cursor(&self.get_contents(), self.buffer.chars().count(), context);
|
||||
let (_, s) = substitute_cursor(context, &self.get_contents(), self.buffer.chars().count());
|
||||
|
||||
write!(
|
||||
stdout, "\r{}{}==>{}{} {}",
|
||||
@ -64,12 +64,12 @@ impl PromptBuffer {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn write_prompt(&mut self, stdout: &mut RawTerminal<std::io::Stdout>, context: &Context) -> Result<(), std::io::Error> {
|
||||
pub fn write_prompt(&mut self, context: &Context, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> {
|
||||
let l = self.buffer.chars().count();
|
||||
let i = if l == 0 {0} else {l - self.cursor};
|
||||
|
||||
// Draw prettyprinted expression
|
||||
let (display_cursor, s) = substitute_cursor(&self.get_contents(), i, context);
|
||||
let (display_cursor, s) = substitute_cursor(context, &self.get_contents(), i);
|
||||
|
||||
write!(
|
||||
stdout, "\r{}{}==>{}{} {}",
|
||||
|
@ -24,8 +24,8 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
// Handle command-line arguments
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.iter().any(|s| s == "--help") {
|
||||
let t = command::do_command(&String::from("help"), &mut context);
|
||||
t.write(&mut stdout)?;
|
||||
let t = command::do_command(&mut context, &String::from("help"));
|
||||
t.write(&context, &mut stdout)?;
|
||||
return Ok(());
|
||||
} else if args.iter().any(|s| s == "--version") {
|
||||
write!(stdout, "Daisy v{}\r\n", env!("CARGO_PKG_VERSION"))?;
|
||||
@ -34,7 +34,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
'outer: loop {
|
||||
|
||||
pb.write_prompt(&mut stdout, &context)?;
|
||||
pb.write_prompt(&mut context, &mut stdout)?;
|
||||
|
||||
let stdin = stdin();
|
||||
for c in stdin.keys() {
|
||||
@ -43,7 +43,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
'\n' => {
|
||||
// Print again without cursor, in case we pressed enter
|
||||
// while inside a substitution
|
||||
pb.write_prompt_nocursor(&mut stdout, &context)?;
|
||||
pb.write_prompt_nocursor(&mut context, &mut stdout)?;
|
||||
let in_str = pb.enter();
|
||||
write!(stdout, "\r\n")?;
|
||||
if in_str == "" { break; }
|
||||
@ -51,11 +51,11 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
if in_str.trim() == "quit" {
|
||||
break 'outer;
|
||||
} else {
|
||||
let r = crate::do_string(&in_str, &mut context);
|
||||
let r = crate::do_string(&mut context, &in_str);
|
||||
|
||||
match r {
|
||||
Ok(t) | Err(t) => {
|
||||
t.write(&mut stdout).unwrap();
|
||||
t.write(&context, &mut stdout).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
};
|
||||
};
|
||||
|
||||
pb.write_prompt(&mut stdout, &context)?;
|
||||
pb.write_prompt(&mut context, &mut stdout)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user