Compare commits

..

1 Commits

Author SHA1 Message Date
tranquillity-codes 9638945202 Remove unnecessary history is_some checks
6 days ago

@ -105,10 +105,6 @@ impl SequenceState {
self.out_buf.push(InputChar::Backspace);
Result::Ok(())
}
else if chr == 0x04 {
self.out_buf.push(InputChar::EoT);
Result::Ok(())
}
// Unrecognized
else {
Result::Err(AcceptError::Unimplemented(chr))

@ -1,6 +1,6 @@
#![allow(unused)]
use std::{io::Read, mem::MaybeUninit};
use std::mem::MaybeUninit;
use crate::reader::esc_parse::{InputChar, bell, hide_cursor, show_cursor};
@ -24,8 +24,7 @@ pub enum InitTTYError {
#[derive(Debug)]
pub enum ReadError {
EscapeError(esc_parse::AcceptError),
Exited,
EscapeError(esc_parse::AcceptError)
}
#[derive(Debug)]
@ -36,7 +35,6 @@ pub enum EditCommand {
CursorBack,
CursorForward,
DeleteBack,
Exit,
}
macro_rules! edit_cmd {
@ -84,10 +82,10 @@ impl ReaderState {
self.redraw();
}
fn current_hist(&mut self) -> Option<String> {
fn current_hist(&mut self) -> String {
let i: usize = self.history_inx.unwrap();
let line = self.history.get(self.history.len().saturating_sub(i+1));
return line.map(|s| s.to_string());
return line.unwrap().to_string();
}
fn set_current_hist(&mut self, str: String) {
@ -97,7 +95,7 @@ impl ReaderState {
}
fn insert_at_cursor_hist(&mut self, txt: String) {
let mut line = self.current_hist().expect("Trying to modify a non-existent history entry");
let mut line = self.current_hist();
line.insert_str(self.cursor, txt.as_str());
self.history_reset();
self.set_line(line.clone());
@ -147,9 +145,6 @@ impl ReaderState {
if chr == InputChar::Backspace {
return edit_cmd!(DeleteBack);
}
if chr == InputChar::EoT {
return edit_cmd!(Exit);
}
}
}
}
@ -177,7 +172,6 @@ impl ReaderState {
pub fn read_line(&mut self) -> Result<String, ReadError> {
use EditCommand::*;
loop {
self.set_prompt(format!("{:?}> ", self.history_inx));
let cmd = self.input_line();
if cmd.is_err() {
return Err(cmd.err().unwrap());
@ -203,8 +197,7 @@ impl ReaderState {
},
HistoryNext => {
self.history_front();
},
Exit => return Err(ReadError::Exited)
}
}
}
}
@ -233,7 +226,7 @@ impl ReaderState {
pub fn history_back(&mut self) {
let h = self.history.clone();
let mut i = self.history_inx;
if i.map_or(h.len() == 0, |v| v+1 == h.len()) {
if i.map_or(false, |v| v+1 == h.len()) {
bell();
return;
}
@ -246,12 +239,7 @@ impl ReaderState {
self.history_inx = i;
let i: usize = i.unwrap();
let line = h.get(h.len().saturating_sub(i+1));
if line.is_some() {
self.set_line(line.unwrap().to_string());
} else {
bell();
self.redraw();
}
}
fn saved_restore(&mut self) {
@ -274,12 +262,7 @@ impl ReaderState {
}
let i = i.unwrap();
let line = h.get(h.len().saturating_sub(i+1));
if line.is_some() {
self.set_line(line.unwrap().to_string());
} else {
bell();
self.redraw();
}
}
pub fn move_left(&mut self) {
@ -321,7 +304,7 @@ impl ReaderState {
pub fn backspace(&mut self) {
if self.history_inx.is_some() {
if self.cursor > 0 {
let mut line = self.current_hist().expect("Trying to modify a non-existent history entry");
let mut line = self.current_hist();
line.remove(self.cursor-1);
self.move_left();
self.history_reset();

Loading…
Cancel
Save