Commit c585bc5d authored by Michael Aaron Murphy's avatar Michael Aaron Murphy

Merge branch 'no-type-completer' into 'master'

Move the generic typing from the Completer type to the on_event method

See merge request !17
parents 367de8bc 615ea3b7
......@@ -21,16 +21,16 @@ struct CommentCompleter {
inner: Option<FilenameCompleter>,
}
impl<W: io::Write> Completer<W> for CommentCompleter {
impl Completer for CommentCompleter {
fn completions(&mut self, start: &str) -> Vec<String> {
if let Some(inner) = &mut self.inner {
Completer::<W>::completions(inner, start)
inner.completions(start)
} else {
Vec::new()
}
}
fn on_event(&mut self, event: Event<W>) {
fn on_event<W: std::io::Write>(&mut self, event: Event<W>) {
if let EventKind::BeforeComplete = event.kind {
let (_, pos) = event.editor.get_words_and_cursor_position();
......
......@@ -20,16 +20,16 @@ struct NoCommentCompleter {
inner: Option<FilenameCompleter>,
}
impl<W: io::Write> Completer<W> for NoCommentCompleter {
impl Completer for NoCommentCompleter {
fn completions(&mut self, start: &str) -> Vec<String> {
if let Some(inner) = &mut self.inner {
Completer::<W>::completions(inner, start)
inner.completions(start)
} else {
Vec::new()
}
}
fn on_event(&mut self, event: Event<W>) {
fn on_event<W: std::io::Write>(&mut self, event: Event<W>) {
if let EventKind::BeforeComplete = event.kind {
let (_, pos) = event.editor.get_words_and_cursor_position();
......
......@@ -2,9 +2,9 @@ use super::event::Event;
use std::io::Write;
use std::path::PathBuf;
pub trait Completer<W: Write> {
pub trait Completer {
fn completions(&mut self, start: &str) -> Vec<String>;
fn on_event(&mut self, _event: Event<W>) {}
fn on_event<W: Write>(&mut self, _event: Event<W>) {}
}
pub struct BasicCompleter {
......@@ -19,7 +19,7 @@ impl BasicCompleter {
}
}
impl<T: Write> Completer<T> for BasicCompleter {
impl Completer for BasicCompleter {
fn completions(&mut self, start: &str) -> Vec<String> {
self.prefixes
.iter()
......@@ -41,7 +41,7 @@ impl FilenameCompleter {
}
}
impl<T: Write> Completer<T> for FilenameCompleter {
impl Completer for FilenameCompleter {
fn completions(&mut self, mut start: &str) -> Vec<String> {
// XXX: this function is really bad, TODO rewrite
......
use std::io::{self, stdin, stdout, Stdout, Write};
use std::io::{self, stdin, stdout, Write};
use termion::input::TermRead;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::raw::IntoRawMode;
use super::*;
use keymap;
......@@ -65,7 +65,7 @@ impl Context {
/// The output is stdout.
/// The returned line has the newline removed.
/// Before returning, will revert all changes to the history buffers.
pub fn read_line<P: Into<String>, C: Completer<RawTerminal<Stdout>>>(
pub fn read_line<P: Into<String>, C: Completer>(
&mut self,
prompt: P,
f: Option<ColorClosure>,
......@@ -81,7 +81,7 @@ impl Context {
///
/// struct EmptyCompleter;
///
/// impl<W: std::io::Write> Completer<W> for EmptyCompleter {
/// impl Completer for EmptyCompleter {
/// fn completions(&mut self, _start: &str) -> Vec<String> {
/// Vec::new()
/// }
......@@ -94,11 +94,7 @@ impl Context {
/// Some(Box::new(|s| String::from(s))),
/// "some initial buffer");
/// ```
pub fn read_line_with_init_buffer<
P: Into<String>,
B: Into<Buffer>,
C: Completer<RawTerminal<Stdout>>,
>(
pub fn read_line_with_init_buffer<P: Into<String>, B: Into<Buffer>, C: Completer>(
&mut self,
prompt: P,
handler: &mut C,
......@@ -118,7 +114,7 @@ impl Context {
res
}
fn handle_keys<'a, W: Write, M: KeyMap, C: Completer<W>>(
fn handle_keys<'a, W: Write, M: KeyMap, C: Completer>(
mut keymap: M,
mut ed: Editor<'a, W>,
handler: &mut C,
......
......@@ -427,7 +427,7 @@ impl<'a, W: Write> Editor<'a, W> {
self.show_completions_hint = None;
}
pub fn complete<T: Completer<W>>(&mut self, handler: &mut T) -> io::Result<()> {
pub fn complete<T: Completer>(&mut self, handler: &mut T) -> io::Result<()> {
handler.on_event(Event::new(self, EventKind::BeforeComplete));
if let Some((completions, i)) = self.show_completions_hint.take() {
......
......@@ -197,7 +197,7 @@ mod tests {
struct EmptyCompleter;
impl<W: Write> Completer<W> for EmptyCompleter {
impl Completer for EmptyCompleter {
fn completions(&mut self, _start: &str) -> Vec<String> {
Vec::default()
}
......
......@@ -13,7 +13,7 @@ pub trait KeyMap: Default {
fn init<'a, W: Write>(&mut self, _editor: &mut Editor<'a, W>) {}
fn handle_key<'a, W: Write, C: Completer<W>>(
fn handle_key<'a, W: Write, C: Completer>(
&mut self,
mut key: Key,
editor: &mut Editor<'a, W>,
......@@ -101,7 +101,7 @@ mod tests {
struct EmptyCompleter;
impl<W: Write> Completer<W> for EmptyCompleter {
impl Completer for EmptyCompleter {
fn completions(&mut self, _start: &str) -> Vec<String> {
Vec::default()
}
......
......@@ -1090,7 +1090,7 @@ mod tests {
struct EmptyCompleter;
impl<W: Write> Completer<W> for EmptyCompleter {
impl Completer for EmptyCompleter {
fn completions(&mut self, _start: &str) -> Vec<String> {
Vec::default()
}
......
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