backspace
This commit is contained in:
parent
0282b26265
commit
c080a25603
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -118,6 +118,12 @@ version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
|
||||
[[package]]
|
||||
name = "env_home"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.10"
|
||||
@ -225,9 +231,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "luajit-src"
|
||||
version = "210.5.11+97813fb"
|
||||
version = "210.5.12+a4f56a4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3015551c284515db7c30c559fc1080f9cb9ee990d1f6fca315451a107c7540bb"
|
||||
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"which",
|
||||
@ -597,12 +603,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "6.0.3"
|
||||
version = "7.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f"
|
||||
checksum = "fb4a9e33648339dc1642b0e36e21b3385e6148e289226f657c809dee59df5028"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"env_home",
|
||||
"rustix",
|
||||
"winsafe",
|
||||
]
|
||||
|
@ -99,7 +99,7 @@ impl<'a> Command<'a> {
|
||||
history.add(self.0.as_str());
|
||||
child.wait().ok();
|
||||
},
|
||||
Err(_) => println!("pse: Unknown command: {}", self.0),
|
||||
Err(_) => println!("\npse: Unknown command: {}", self.0),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ use crate::{commands::Command, session::{self, Pse}};
|
||||
pub enum InputHandleError {
|
||||
#[error("UserExit")]
|
||||
UserExit,
|
||||
#[error("Sigterm")]
|
||||
Sigterm,
|
||||
#[error("Sigint")]
|
||||
Sigint,
|
||||
#[error("Render failure: {0}")]
|
||||
Write(io::Error),
|
||||
#[error("Flush failure: {0}")]
|
||||
@ -25,6 +25,8 @@ type InputResult<T> = Result<T, InputHandleError>;
|
||||
|
||||
trait SpecificKeybinds {
|
||||
const TERM_ID_1: &str;
|
||||
const KEY_SPACE: char;
|
||||
fn key_literal(&mut self, keycode: KeyCode) -> InputResult<()>;
|
||||
fn key_ctrl(&mut self, input_key: KeyEvent, keycode: KeyCode) -> InputResult<()>;
|
||||
fn key_enter(&mut self) -> InputResult<()>;
|
||||
fn key_backspace(&mut self) -> InputResult<()>;
|
||||
@ -33,15 +35,22 @@ trait SpecificKeybinds {
|
||||
}
|
||||
impl SpecificKeybinds for Pse {
|
||||
const TERM_ID_1: &str = "exit";
|
||||
const KEY_SPACE: char = ' ';
|
||||
|
||||
fn key_literal(&mut self, keycode: KeyCode) -> InputResult<()> {
|
||||
match keycode {
|
||||
KeyCode::Char(Self::KEY_SPACE) => self.term_render(Self::KEY_SPACE.to_string()),
|
||||
keycode => self.term_render(keycode.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn key_ctrl(&mut self, input_key: KeyEvent, keycode: KeyCode) -> InputResult<()> {
|
||||
if input_key.modifiers.contains(KeyModifiers::CONTROL) {
|
||||
match keycode {
|
||||
KeyCode::Char('c') => Err(InputHandleError::Sigterm),
|
||||
match input_key.modifiers.contains(KeyModifiers::CONTROL) {
|
||||
true => match keycode {
|
||||
KeyCode::Char('c') => Err(InputHandleError::Sigint),
|
||||
_ => Ok(())
|
||||
}
|
||||
} else {
|
||||
self.term_render(keycode.to_string())
|
||||
},
|
||||
false => self.key_literal(keycode)
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +60,7 @@ impl SpecificKeybinds for Pse {
|
||||
terminal::disable_raw_mode().map_err(InputHandleError::DisableRaw)?;
|
||||
Command::new(&self.rt.input).exec(&mut self.history);
|
||||
self.rt.input.clear();
|
||||
Ok(())
|
||||
self.term_render_ps()
|
||||
}
|
||||
|
||||
fn key_backspace(&mut self) -> InputResult<()> {
|
||||
@ -78,6 +87,7 @@ impl SpecificKeybinds for Pse {
|
||||
|
||||
pub trait TermProcessor {
|
||||
fn term_render(&mut self, def_string: String) -> InputResult<()>;
|
||||
fn term_render_ps(&self) -> InputResult<()>;
|
||||
fn term_input_handler(&mut self, input_key: KeyEvent) -> Option<()>;
|
||||
fn term_input_mainthread(&mut self) -> io::Result<()>;
|
||||
fn term_input_processor(&mut self) -> io::Result<()>;
|
||||
@ -89,6 +99,11 @@ impl TermProcessor for Pse {
|
||||
io::stdout().flush().map_err(InputHandleError::Flush)
|
||||
}
|
||||
|
||||
fn term_render_ps(&self) -> InputResult<()> {
|
||||
print!("{}", self.rt.ps.borrow());
|
||||
io::stdout().flush().map_err(InputHandleError::Flush)
|
||||
}
|
||||
|
||||
fn term_input_handler(&mut self, input_key: KeyEvent) -> Option<()> {
|
||||
let input_handle = match input_key.code {
|
||||
KeyCode::Enter => self.key_enter(),
|
||||
@ -102,13 +117,14 @@ impl TermProcessor for Pse {
|
||||
};
|
||||
input_handle.map_or_else(|inp_err| match inp_err {
|
||||
InputHandleError::UserExit => None,
|
||||
InputHandleError::Sigterm => self.term_render("^C".to_owned()).ok(),
|
||||
InputHandleError::Sigint => self.term_render("^C".to_owned()).ok(),
|
||||
input_err => session::shell_error_none(input_err)
|
||||
}, Some)
|
||||
}
|
||||
|
||||
fn term_input_mainthread(&mut self) -> io::Result<()> {
|
||||
execute!(io::stdout(), event::EnableBracketedPaste)?;
|
||||
self.term_render_ps();
|
||||
loop {
|
||||
terminal::enable_raw_mode()?;
|
||||
if let Event::Key(event) = event::read()? {
|
||||
|
Loading…
x
Reference in New Issue
Block a user