From ae36284d60b828869ede5a77343ccb307046b69a Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 3 Aug 2019 15:22:01 +0800 Subject: Fix clippy lints --- src/readline/mod.rs | 66 +++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) (limited to 'src/readline') diff --git a/src/readline/mod.rs b/src/readline/mod.rs index e9d4b33..41cd742 100644 --- a/src/readline/mod.rs +++ b/src/readline/mod.rs @@ -1,11 +1,11 @@ -use std::borrow::Cow::{self,Owned}; +use std::borrow::Cow::{self, Owned}; +use rustyline::completion::{Completer, FilenameCompleter, Pair}; +use rustyline::config::{Builder, ColorMode, CompletionType, EditMode}; use rustyline::error::ReadlineError; -use rustyline::{ Editor, Context, Helper }; -use rustyline::config::{ Builder, ColorMode, EditMode, CompletionType }; -use rustyline::hint::{ Hinter, HistoryHinter }; -use rustyline::completion::{ FilenameCompleter, Completer, Pair }; use rustyline::highlight::Highlighter; +use rustyline::hint::{Hinter, HistoryHinter}; +use rustyline::{Context, Editor, Helper}; use regex::Regex; @@ -17,7 +17,7 @@ pub struct RLHelper { hinter: HistoryHinter, } -struct LineHighlighter { } +struct LineHighlighter {} impl Highlighter for LineHighlighter { fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { Owned(format!("\x1b[90m{}\x1b[0m", hint)) @@ -28,14 +28,9 @@ impl Highlighter for LineHighlighter { Ok(_) => { let constants = ["e", "pi"]; let functions = [ - "sin" , "cos" , "tan" , - "csc" , "sec" , "cot" , - "sinh" , "cosh" , "tanh" , - "ln" , "log" , "sqrt" , - "ceil" , "floor" , "rad" , - "deg" , "abs" , "asin" , - "acos" , "atan" , "acsc" , - "asec" , "acot" + "sin", "cos", "tan", "csc", "sec", "cot", "sinh", "cosh", "tanh", "ln", "log", + "sqrt", "ceil", "floor", "rad", "deg", "abs", "asin", "acos", "atan", "acsc", + "asec", "acot", ]; let ops = Regex::new(r"(?P[\+-/\*%\^!])").unwrap(); let mut coloured: String = ops.replace_all(line, "\x1b[33m$o\x1b[0m").into(); @@ -46,14 +41,14 @@ impl Highlighter for LineHighlighter { for f in &functions { coloured = coloured.replace(f, &format!("\x1b[34m{}\x1b[0m", f)); } - Owned(coloured.into()) - }, - Err(_) => Owned(format!("\x1b[31m{}\x1b[0m", line)) + Owned(coloured) + } + Err(_) => Owned(format!("\x1b[31m{}\x1b[0m", line)), } } } -impl Highlighter for RLHelper { +impl Highlighter for RLHelper { fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { self.highlighter.highlight_hint(hint) } @@ -69,11 +64,11 @@ impl Completer for RLHelper { line: &str, pos: usize, ctx: &Context<'_>, - ) -> Result<(usize, Vec), ReadlineError> { + ) -> Result<(usize, Vec), ReadlineError> { self.completer.complete(line, pos, ctx) } } - + impl Hinter for RLHelper { fn hint(&self, line: &str, a: usize, b: &Context) -> Option { self.hinter.hint(line, a, b) @@ -83,19 +78,20 @@ impl Hinter for RLHelper { impl Helper for RLHelper {} pub fn create_readline() -> Editor { - let config_builder = Builder::new(); - let config = config_builder.color_mode(ColorMode::Enabled) - .edit_mode(EditMode::Emacs) - .history_ignore_space(true) - .completion_type(CompletionType::Circular) - .max_history_size(1000) - .build(); - let mut rl = Editor::with_config(config); - let h = RLHelper { - completer: FilenameCompleter::new(), - highlighter: LineHighlighter {}, - hinter: HistoryHinter {} - }; - rl.set_helper(Some(h)); - return rl; + let config_builder = Builder::new(); + let config = config_builder + .color_mode(ColorMode::Enabled) + .edit_mode(EditMode::Emacs) + .history_ignore_space(true) + .completion_type(CompletionType::Circular) + .max_history_size(1000) + .build(); + let mut rl = Editor::with_config(config); + let h = RLHelper { + completer: FilenameCompleter::new(), + highlighter: LineHighlighter {}, + hinter: HistoryHinter {}, + }; + rl.set_helper(Some(h)); + rl } -- cgit v1.2.3