mirror of
https://github.com/rm-dr/daisy
synced 2025-10-07 04:32:29 -07:00
Added user function parsing
This commit is contained in:
@ -4,7 +4,7 @@ use termion::raw::RawTerminal;
|
||||
use termion::color;
|
||||
use termion::style;
|
||||
use crate::parser::substitute_cursor;
|
||||
|
||||
use crate::context::Context;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PromptBuffer {
|
||||
@ -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>) -> Result<(), std::io::Error> {
|
||||
pub fn write_prompt_nocursor(&mut self, stdout: &mut RawTerminal<std::io::Stdout>, context: &Context) -> Result<(), std::io::Error> {
|
||||
// Draw prettyprinted expression
|
||||
let (_, s) = substitute_cursor(&self.get_contents(), self.buffer.chars().count());
|
||||
let (_, s) = substitute_cursor(&self.get_contents(), self.buffer.chars().count(), context);
|
||||
|
||||
write!(
|
||||
stdout, "\r{}{}==>{}{} {}",
|
||||
@ -64,12 +64,12 @@ impl PromptBuffer {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn write_prompt(&mut self, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> {
|
||||
pub fn write_prompt(&mut self, stdout: &mut RawTerminal<std::io::Stdout>, context: &Context) -> 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);
|
||||
let (display_cursor, s) = substitute_cursor(&self.get_contents(), i, context);
|
||||
|
||||
write!(
|
||||
stdout, "\r{}{}==>{}{} {}",
|
||||
|
@ -101,8 +101,8 @@ fn do_assignment(
|
||||
|
||||
let left = parts[0].trim().to_string();
|
||||
let right = parts[1].trim().to_string();
|
||||
let right = substitute(&right);
|
||||
let left = substitute(&left);
|
||||
let right = substitute(&right, &context);
|
||||
let left = substitute(&left, &context);
|
||||
|
||||
let is_function = left.contains("(");
|
||||
|
||||
@ -305,7 +305,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
'outer: loop {
|
||||
|
||||
pb.write_prompt(&mut stdout)?;
|
||||
pb.write_prompt(&mut stdout, &context)?;
|
||||
|
||||
let stdin = stdin();
|
||||
for c in stdin.keys() {
|
||||
@ -314,7 +314,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)?;
|
||||
pb.write_prompt_nocursor(&mut stdout, &context)?;
|
||||
let in_str = pb.enter();
|
||||
write!(stdout, "\r\n")?;
|
||||
if in_str == "" { break; }
|
||||
@ -384,7 +384,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
||||
};
|
||||
};
|
||||
|
||||
pb.write_prompt(&mut stdout)?;
|
||||
pb.write_prompt(&mut stdout, &context)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user