Skip to content
Snippets Groups Projects
Commit 4eddf071 authored by gwenn's avatar gwenn
Browse files

Handle more Vi cmds (#94)

Replace char ('r')
KillWholeLine ('S', 'dd', 'cc')
parent e56e5c9f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ extern crate rustyline;
use rustyline::completion::FilenameCompleter;
use rustyline::error::ReadlineError;
use rustyline::{Config, CompletionType, Editor};
use rustyline::{Config, CompletionType, Editor, EditMode};
// On unix platforms you can use ANSI escape sequences
#[cfg(unix)]
......@@ -17,6 +17,7 @@ fn main() {
let config = Config::builder()
.history_ignore_space(true)
.completion_type(CompletionType::List)
.edit_mode(EditMode::Emacs)
.build();
let c = FilenameCompleter::new();
let mut rl = Editor::with_config(config);
......
......@@ -27,7 +27,7 @@ pub enum Cmd {
ForwardWord(Word), // Command For Moving
Interrupt,
KillLine, // Command For Killing
KillWholeLine, // Command For Killing (TODO Delete current line)
KillWholeLine, // Command For Killing
KillWord(Word), // Command For Killing
NextHistory, // Command For History
Noop,
......@@ -313,7 +313,7 @@ impl EditState {
KeyPress::Esc => {
// vi-movement-mode/vi-command-mode: Vi enter command mode (use alternative key bindings).
self.insert = false;
Cmd::Noop
Cmd::BackwardChar
}
KeyPress::UnknownEscSeq => Cmd::Noop,
_ => Cmd::Unknown,
......
......@@ -667,22 +667,22 @@ fn page_completions<R: RawReader>(rdr: &mut R,
for row in 0..num_rows {
if row == pause_row {
try!(write_and_flush(s.out, b"\n--More--"));
let mut key = KeyPress::Null;
while key != KeyPress::Char('y') && key != KeyPress::Char('Y') &&
key != KeyPress::Char('n') && key != KeyPress::Char('N') &&
key != KeyPress::Char('q') &&
key != KeyPress::Char('Q') &&
key != KeyPress::Char(' ') &&
key != KeyPress::Backspace && key != KeyPress::Enter {
key = try!(rdr.next_key(config.keyseq_timeout()));
let mut cmd = Cmd::Noop;
while cmd != Cmd::SelfInsert('y') && cmd != Cmd::SelfInsert('Y') &&
cmd != Cmd::SelfInsert('n') && cmd != Cmd::SelfInsert('N') &&
cmd != Cmd::SelfInsert('q') &&
cmd != Cmd::SelfInsert('Q') &&
cmd != Cmd::SelfInsert(' ') &&
cmd != Cmd::BackwardDeleteChar && cmd != Cmd::AcceptLine {
cmd = try!(s.next_cmd(rdr, config));
}
match key {
KeyPress::Char('y') |
KeyPress::Char('Y') |
KeyPress::Char(' ') => {
match cmd {
Cmd::SelfInsert('y') |
Cmd::SelfInsert('Y') |
Cmd::SelfInsert(' ') => {
pause_row += s.term.get_rows() - 1;
}
KeyPress::Enter => {
Cmd::AcceptLine => {
pause_row += 1;
}
_ => break,
......@@ -859,6 +859,12 @@ fn readline_edit<C: Completer>(prompt: &str,
// Delete (forward) one character at point.
try!(edit_delete(&mut s))
}
Cmd::Replace(c) => {
editor.kill_ring.reset();
try!(edit_delete(&mut s));
try!(edit_insert(&mut s, c));
try!(edit_move_left(&mut s))
}
Cmd::EndOfFile => {
editor.kill_ring.reset();
if !s.edit_state.is_emacs_mode() || s.line.is_empty() {
......@@ -888,6 +894,12 @@ fn readline_edit<C: Completer>(prompt: &str,
editor.kill_ring.kill(&text, Mode::Append)
}
}
Cmd::KillWholeLine => {
try!(edit_move_home(&mut s));
if let Some(text) = try!(edit_kill_line(&mut s)) {
editor.kill_ring.kill(&text, Mode::Append)
}
}
Cmd::ClearScreen => {
// Clear the screen leaving the current line at the top of the screen.
try!(s.term.clear_screen(&mut s.out));
......@@ -1204,7 +1216,7 @@ mod test {
snapshot: LineBuffer::with_capacity(100),
term: term,
byte_buffer: [0; 4],
edit_state : EditState::new(&config),
edit_state: EditState::new(&config),
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment