Substitute cleanup

pull/2/head
Mark 2023-08-03 14:25:11 -07:00
parent 917746f44f
commit 83f00c761b
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 9 additions and 6 deletions

View File

@ -257,7 +257,7 @@ pub fn do_command(
} }
let v = args[1].to_string(); let v = args[1].to_string();
let (_, v) = substitute(&v, v.len()); let v = substitute(&v);
let r = context.delete_variable(&v); let r = context.delete_variable(&v);
match r { match r {

View File

@ -3,8 +3,7 @@ use std::io::Write;
use termion::raw::RawTerminal; use termion::raw::RawTerminal;
use termion::color; use termion::color;
use termion::style; use termion::style;
use crate::parser::substitute_cursor;
use crate::parser::substitute;
#[derive(Debug)] #[derive(Debug)]
@ -43,7 +42,7 @@ impl PromptBuffer {
let i = if l == 0 {0} else {l - self.cursor}; let i = if l == 0 {0} else {l - self.cursor};
// Draw prettyprinted expression // Draw prettyprinted expression
let (display_cursor, s) = substitute(&self.get_contents(), i); let (display_cursor, s) = substitute_cursor(&self.get_contents(), i);
write!( write!(
stdout, "\r{}{}==>{}{} {}", stdout, "\r{}{}==>{}{} {}",

View File

@ -91,7 +91,7 @@ fn do_expression(
Err((l, e)) => { Err((l, e)) => {
// Display user input // Display user input
let (_, s) = substitute(&s, s.len()); let s = substitute(&s);
write!( write!(
stdout, "\n{}{}==>{}{} {}\r\n", stdout, "\n{}{}==>{}{} {}\r\n",
style::Bold, color::Fg(color::Red), style::Bold, color::Fg(color::Red),

View File

@ -37,8 +37,12 @@ pub fn parse_no_context(s: &String) -> Result<Expression, (LineLocation, ParserE
parse(s, &Context::new()) parse(s, &Context::new())
} }
pub fn substitute(s: &String) -> String {
let (_, s) = substitute_cursor(s, s.chars().count());
return s;
}
pub fn substitute( pub fn substitute_cursor(
s: &String, // The string to substitute s: &String, // The string to substitute
c: usize // Location of the cursor right now c: usize // Location of the cursor right now
) -> ( ) -> (