From 83f00c761b9fba2b65c70a700622e5afd340b171 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 3 Aug 2023 14:25:11 -0700 Subject: [PATCH] Substitute cleanup --- src/command/mod.rs | 2 +- src/entry/unix/promptbuffer.rs | 5 ++--- src/entry/unix/unix.rs | 2 +- src/parser/mod.rs | 6 +++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/command/mod.rs b/src/command/mod.rs index ccabf7f..e6a1ee3 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -257,7 +257,7 @@ pub fn do_command( } let v = args[1].to_string(); - let (_, v) = substitute(&v, v.len()); + let v = substitute(&v); let r = context.delete_variable(&v); match r { diff --git a/src/entry/unix/promptbuffer.rs b/src/entry/unix/promptbuffer.rs index dbc426a..18c03aa 100644 --- a/src/entry/unix/promptbuffer.rs +++ b/src/entry/unix/promptbuffer.rs @@ -3,8 +3,7 @@ use std::io::Write; use termion::raw::RawTerminal; use termion::color; use termion::style; - -use crate::parser::substitute; +use crate::parser::substitute_cursor; #[derive(Debug)] @@ -43,7 +42,7 @@ impl PromptBuffer { let i = if l == 0 {0} else {l - self.cursor}; // Draw prettyprinted expression - let (display_cursor, s) = substitute(&self.get_contents(), i); + let (display_cursor, s) = substitute_cursor(&self.get_contents(), i); write!( stdout, "\r{}{}==>{}{} {}", diff --git a/src/entry/unix/unix.rs b/src/entry/unix/unix.rs index d4d54f0..e2e9edf 100644 --- a/src/entry/unix/unix.rs +++ b/src/entry/unix/unix.rs @@ -91,7 +91,7 @@ fn do_expression( Err((l, e)) => { // Display user input - let (_, s) = substitute(&s, s.len()); + let s = substitute(&s); write!( stdout, "\n{}{}==>{}{} {}\r\n", style::Bold, color::Fg(color::Red), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 7717f11..bb342a8 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -37,8 +37,12 @@ pub fn parse_no_context(s: &String) -> Result String { + let (_, s) = substitute_cursor(s, s.chars().count()); + return s; +} -pub fn substitute( +pub fn substitute_cursor( s: &String, // The string to substitute c: usize // Location of the cursor right now ) -> (