Added prompt escape code expansion flag to echo, -p
Added non-formatted runtime to prompt escape codes Added prompt escape code that expands to the output of a shell function Reworked internal logic for termios control
This commit is contained in:
@@ -11,17 +11,19 @@ use crate::{
|
||||
/// Initialize the line editor
|
||||
fn get_prompt() -> ShResult<String> {
|
||||
let Ok(prompt) = env::var("PS1") else {
|
||||
// prompt expands to:
|
||||
// default prompt expands to:
|
||||
//
|
||||
// username@hostname
|
||||
// short/path/to/pwd/
|
||||
// $ _
|
||||
let default =
|
||||
"\\n\\e[1;0m\\u\\e[1;36m@\\e[1;31m\\h\\n\\e[1;36m\\W\\e[1;32m/\\n\\e[1;32m\\$\\e[0m ";
|
||||
"\\e[0m\\n\\e[1;0m\\u\\e[1;36m@\\e[1;31m\\h\\n\\e[1;36m\\W\\e[1;32m/\\n\\e[1;32m\\$\\e[0m ";
|
||||
return expand_prompt(default);
|
||||
};
|
||||
let sanitized = format!("\\e[0m{prompt}");
|
||||
flog!(DEBUG, "Using prompt: {}", sanitized.replace("\n", "\\n"));
|
||||
|
||||
expand_prompt(&prompt)
|
||||
expand_prompt(&sanitized)
|
||||
}
|
||||
|
||||
pub fn readline(edit_mode: FernEditMode, initial: Option<&str>) -> ShResult<String> {
|
||||
|
||||
@@ -8,7 +8,6 @@ use vimode::{CmdReplay, ModeReport, ViInsert, ViMode, ViNormal, ViReplace, ViVis
|
||||
|
||||
use crate::libsh::{
|
||||
error::{ShErr, ShErrKind, ShResult},
|
||||
sys::sh_quit,
|
||||
term::{Style, Styled},
|
||||
};
|
||||
use crate::prelude::*;
|
||||
@@ -95,7 +94,7 @@ impl Readline for FernVi {
|
||||
if cmd.verb().is_some_and(|v| v.1 == Verb::EndOfFile) {
|
||||
if self.editor.buffer.is_empty() {
|
||||
std::mem::drop(raw_mode_guard);
|
||||
sh_quit(0);
|
||||
return Err(ShErr::simple(ShErrKind::CleanExit(0), "exit"));
|
||||
} else {
|
||||
self.editor.buffer.clear();
|
||||
continue;
|
||||
|
||||
@@ -687,7 +687,7 @@ impl LineWriter for TermWriter {
|
||||
for _ in 0..rows_to_clear {
|
||||
self.buffer.push_str("\x1b[2K\x1b[A");
|
||||
}
|
||||
self.buffer.push_str("\x1b[2K");
|
||||
self.buffer.push_str("\x1b[2K\r"); // Clear line and return to column 0
|
||||
write_all(self.out, self.buffer.as_str())?;
|
||||
self.buffer.clear();
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user