Commit 51f2f7e3 authored by stratact's avatar stratact

Merge branch 'prompt-sp' into 'master'

Implement PROMPT_SP fix

See merge request redox-os/liner!6
parents 5b895f5f f3bb8949
......@@ -17,7 +17,7 @@ name = "liner"
[dependencies]
bytecount = "0.3.1"
termion = "1.4.0"
termion = { git = "https://gitlab.redox-os.org/redox-os/termion" }
unicode-width = "0.1.*"
[dev-dependencies]
......
......@@ -65,7 +65,7 @@ impl<'a> From<&'a str> for Buffer {
impl fmt::Display for Buffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for &c in &self.data {
try!(f.write_char(c));
f.write_char(c)?;
}
Ok(())
}
......@@ -256,9 +256,7 @@ impl Buffer {
where W: Write
{
let string: String = self.data.iter().cloned().collect();
try!(out.write(string.as_bytes()));
Ok(())
out.write_all(string.as_bytes())
}
pub fn as_bytes(&self) -> Vec<u8> {
......@@ -274,7 +272,7 @@ impl Buffer {
where W: Write
{
let string: String = self.data.iter().skip(after).cloned().collect();
out.write(string.as_bytes())?;
out.write_all(string.as_bytes())?;
Ok(string.len())
}
......
......@@ -97,7 +97,7 @@ impl Context {
buffer: B,
) -> io::Result<String> {
let res = {
let stdout = stdout().into_raw_mode()?;
let mut stdout = stdout().into_raw_mode()?;
let ed = Editor::new_with_init_buffer(stdout, prompt, f, self, buffer)?;
match self.key_bindings {
KeyBindings::Emacs => Self::handle_keys(keymap::Emacs::new(ed), handler),
......@@ -117,8 +117,9 @@ impl Context {
String: From<M>,
{
let stdin = stdin();
let stdin = stdin.lock();
for c in stdin.keys() {
if try!(keymap.handle_key(c.unwrap(), handler)) {
if keymap.handle_key(c.unwrap(), handler)? {
break;
}
}
......
This diff is collapsed.
......@@ -36,7 +36,7 @@ impl<'a, W: Write> Emacs<'a, W> {
'k' => self.ed.delete_all_after_cursor(),
'w' => self.ed.delete_word_before_cursor(true),
'x' => {
try!(self.ed.undo());
self.ed.undo()?;
Ok(())
}
_ => Ok(()),
......@@ -51,7 +51,7 @@ impl<'a, W: Write> Emacs<'a, W> {
'f' => emacs_move_word(&mut self.ed, EmacsMoveDir::Right),
'b' => emacs_move_word(&mut self.ed, EmacsMoveDir::Left),
'r' => {
try!(self.ed.revert());
self.ed.revert()?;
Ok(())
}
'.' => self.handle_last_arg_fetch(),
......
......@@ -22,34 +22,34 @@ pub trait KeyMap<'a, W: Write, T>: From<T> {
match key {
Key::Ctrl('c') => {
try!(self.editor_mut().handle_newline());
self.editor_mut().handle_newline()?;
return Err(io::Error::new(ErrorKind::Interrupted, "ctrl-c"));
}
// if the current buffer is empty, treat ctrl-d as eof
Key::Ctrl('d') if is_empty => {
try!(self.editor_mut().handle_newline());
self.editor_mut().handle_newline()?;
return Err(io::Error::new(ErrorKind::UnexpectedEof, "ctrl-d"));
}
Key::Char('\t') => try!(self.editor_mut().complete(handler)),
Key::Char('\t') => self.editor_mut().complete(handler)?,
Key::Char('\n') => {
done = try!(self.editor_mut().handle_newline());
done = self.editor_mut().handle_newline()?;
}
Key::Ctrl('f') if self.editor().is_currently_showing_autosuggestion() => {
try!(self.editor_mut().accept_autosuggestion());
self.editor_mut().accept_autosuggestion()?;
}
Key::Right if self.editor().is_currently_showing_autosuggestion() &&
self.editor().cursor_is_at_end_of_line() => {
try!(self.editor_mut().accept_autosuggestion());
self.editor_mut().accept_autosuggestion()?;
}
_ => {
try!(self.handle_key_core(key));
self.handle_key_core(key)?;
self.editor_mut().skip_completions_hint();
}
};
handler(Event::new(self.editor_mut(), EventKind::AfterKey(key)));
try!(self.editor_mut().flush());
self.editor_mut().flush()?;
Ok(done)
}
......
......@@ -379,8 +379,8 @@ impl<'a, W: Write> Vi<'a, W> {
Delete(start_pos) => {
// perform the delete operation
match move_type {
Exclusive => try!(self.ed.delete_until(start_pos)),
Inclusive => try!(self.ed.delete_until_inclusive(start_pos)),
Exclusive => self.ed.delete_until(start_pos)?,
Inclusive => self.ed.delete_until_inclusive(start_pos)?,
}
// update the last state
......@@ -450,16 +450,16 @@ impl<'a, W: Write> Vi<'a, W> {
if let Some(insert_key) = self.last_insert {
// enter insert mode if necessary
try!(self.handle_key_core(insert_key));
self.handle_key_core(insert_key)?;
}
for k in keys.iter() {
try!(self.handle_key_core(*k));
for k in &keys {
self.handle_key_core(*k)?;
}
if self.last_insert.is_some() {
// leave insert mode
try!(self.handle_key_core(Key::Esc));
self.handle_key_core(Key::Esc)?;
}
// restore the last command
......@@ -492,14 +492,14 @@ impl<'a, W: Write> Vi<'a, W> {
self.last_count = self.count;
for _ in 1..self.count {
let keys = mem::replace(&mut self.last_command, Vec::new());
for k in keys.into_iter() {
try!(self.handle_key_core(k));
for k in keys {
self.handle_key_core(k)?;
}
}
self.count = 0;
}
// cursor moves to the left when switching from insert to normal mode
try!(self.ed.move_cursor_left(1));
self.ed.move_cursor_left(1)?;
self.pop_mode();
Ok(())
}
......@@ -539,7 +539,7 @@ impl<'a, W: Write> Vi<'a, W> {
self.count = 0;
self.movement_reset = true;
self.ed.current_buffer_mut().end_undo_group();
try!(self.ed.move_up());
self.ed.move_up()?;
self.ed.current_buffer_mut().start_undo_group();
Ok(())
}
......@@ -547,7 +547,7 @@ impl<'a, W: Write> Vi<'a, W> {
self.count = 0;
self.movement_reset = true;
self.ed.current_buffer_mut().end_undo_group();
try!(self.ed.move_down());
self.ed.move_down()?;
self.ed.current_buffer_mut().start_undo_group();
Ok(())
}
......@@ -589,7 +589,7 @@ impl<'a, W: Write> Vi<'a, W> {
self.last_insert = Some(key);
self.set_mode(Insert);
let pos = self.ed.cursor() + self.move_count_right();
try!(self.ed.delete_until(pos));
self.ed.delete_until(pos)?;
self.last_count = self.count;
self.count = 0;
Ok(())
......@@ -654,20 +654,20 @@ impl<'a, W: Write> Vi<'a, W> {
}
Key::Char('h') | Key::Left | Key::Backspace => {
let count = self.move_count_left();
try!(self.ed.move_cursor_left(count));
self.ed.move_cursor_left(count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('l') | Key::Right | Key::Char(' ') => {
let count = self.move_count_right();
try!(self.ed.move_cursor_right(count));
self.ed.move_cursor_right(count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('k') | Key::Up => {
try!(self.ed.move_up());
self.ed.move_up()?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('j') | Key::Down => {
try!(self.ed.move_down());
self.ed.move_down()?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('t') => {
......@@ -690,32 +690,32 @@ impl<'a, W: Write> Vi<'a, W> {
Key::Char(',') => self.handle_key_move_to_char(key, ReverseRepeat),
Key::Char('w') => {
let count = self.move_count();
try!(move_word(&mut self.ed, count));
move_word(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('W') => {
let count = self.move_count();
try!(move_word_ws(&mut self.ed, count));
move_word_ws(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('e') => {
let count = self.move_count();
try!(move_to_end_of_word(&mut self.ed, count));
move_to_end_of_word(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('E') => {
let count = self.move_count();
try!(move_to_end_of_word_ws(&mut self.ed, count));
move_to_end_of_word_ws(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('b') => {
let count = self.move_count();
try!(move_word_back(&mut self.ed, count));
move_word_back(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('B') => {
let count = self.move_count();
try!(move_word_ws_back(&mut self.ed, count));
move_word_ws_back(&mut self.ed, count)?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('g') => {
......@@ -724,7 +724,7 @@ impl<'a, W: Write> Vi<'a, W> {
}
// if count is 0, 0 should move to start of line
Key::Char('0') if self.count == 0 => {
try!(self.ed.move_cursor_to_start_of_line());
self.ed.move_cursor_to_start_of_line()?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char(i @ '0'...'9') => {
......@@ -736,7 +736,7 @@ impl<'a, W: Write> Vi<'a, W> {
Ok(())
}
Key::Char('$') => {
try!(self.ed.move_cursor_to_end_of_line());
self.ed.move_cursor_to_end_of_line()?;
self.pop_mode_after_movement(Exclusive)
}
Key::Char('x') | Key::Delete => {
......@@ -747,7 +747,7 @@ impl<'a, W: Write> Vi<'a, W> {
self.last_count = self.count;
let pos = self.ed.cursor() + self.move_count_right();
try!(self.ed.delete_until(pos));
self.ed.delete_until(pos)?;
self.count = 0;
Ok(())
}
......@@ -762,19 +762,19 @@ impl<'a, W: Write> Vi<'a, W> {
for _ in 0..self.move_count_right() {
let c = self.ed.current_buffer().char_after(self.ed.cursor()).unwrap();
if c.is_lowercase() {
try!(self.ed.delete_after_cursor());
self.ed.delete_after_cursor()?;
for c in c.to_uppercase() {
try!(self.ed.insert_after_cursor(c));
self.ed.insert_after_cursor(c)?;
}
}
else if c.is_uppercase() {
try!(self.ed.delete_after_cursor());
self.ed.delete_after_cursor()?;
for c in c.to_lowercase() {
try!(self.ed.insert_after_cursor(c));
self.ed.insert_after_cursor(c)?;
}
}
else {
try!(self.ed.move_cursor_right(1));
self.ed.move_cursor_right(1)?;
}
}
self.pop_mode();
......@@ -784,7 +784,7 @@ impl<'a, W: Write> Vi<'a, W> {
let count = self.move_count();
self.count = 0;
for _ in 0..count {
let did = try!(self.ed.undo());
let did = self.ed.undo()?;
if !did {
break;
}
......@@ -795,7 +795,7 @@ impl<'a, W: Write> Vi<'a, W> {
let count = self.move_count();
self.count = 0;
for _ in 0..count {
let did = try!(self.ed.redo());
let did = self.ed.redo()?;
if !did {
break;
}
......@@ -821,12 +821,12 @@ impl<'a, W: Write> Vi<'a, W> {
// replace count characters
self.ed.current_buffer_mut().start_undo_group();
for _ in 0..self.move_count_right() {
try!(self.ed.delete_after_cursor());
try!(self.ed.insert_after_cursor(c));
self.ed.delete_after_cursor()?;
self.ed.insert_after_cursor(c)?;
}
self.ed.current_buffer_mut().end_undo_group();
try!(self.ed.move_cursor_left(1));
self.ed.move_cursor_left(1)?;
}
self.pop_mode();
}
......@@ -878,8 +878,8 @@ impl<'a, W: Write> Vi<'a, W> {
// delete the whole line
self.count = 0;
self.secondary_count = 0;
try!(self.ed.move_cursor_to_start_of_line());
try!(self.ed.delete_all_after_cursor());
self.ed.move_cursor_to_start_of_line()?;
self.ed.delete_all_after_cursor()?;
// return to the previous mode
self.pop_mode();
......@@ -930,7 +930,7 @@ impl<'a, W: Write> Vi<'a, W> {
match key {
Key::Char(c) => {
let move_type;
try!(match movement {
match movement {
RightUntil => {
move_type = Inclusive;
match find_char(self.ed.current_buffer(), self.ed.cursor() + 1, c, count) {
......@@ -960,7 +960,7 @@ impl<'a, W: Write> Vi<'a, W> {
}
}
Repeat | ReverseRepeat => unreachable!(),
});
}?;
// go back to the previous mode
self.pop_mode_after_movement(move_type)
......@@ -979,11 +979,11 @@ impl<'a, W: Write> Vi<'a, W> {
let res = match key {
Key::Char('e') => {
try!(move_to_end_of_word_back(&mut self.ed, count));
move_to_end_of_word_back(&mut self.ed, count)?;
self.pop_mode_after_movement(Inclusive)
}
Key::Char('E') => {
try!(move_to_end_of_word_ws_back(&mut self.ed, count));
move_to_end_of_word_ws_back(&mut self.ed, count)?;
self.pop_mode_after_movement(Inclusive)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment