Fix clippy suggestions

This commit is contained in:
Ferran Basora 2020-04-23 19:56:45 +00:00
parent 1b035a658d
commit bef83eef38
5 changed files with 51 additions and 55 deletions

View File

@ -31,7 +31,7 @@ pub struct Alphabet<'a> {
impl<'a> Alphabet<'a> { impl<'a> Alphabet<'a> {
fn new(letters: &'a str) -> Alphabet { fn new(letters: &'a str) -> Alphabet {
Alphabet { letters: letters } Alphabet { letters }
} }
pub fn hints(&self, matches: usize) -> Vec<String> { pub fn hints(&self, matches: usize) -> Vec<String> {
@ -44,7 +44,7 @@ impl<'a> Alphabet<'a> {
if expansion.len() + expanded.len() >= matches { if expansion.len() + expanded.len() >= matches {
break; break;
} }
if expansion.len() == 0 { if expansion.is_empty() {
break; break;
} }
@ -61,7 +61,7 @@ impl<'a> Alphabet<'a> {
expansion = expansion expansion = expansion
.iter() .iter()
.take(matches - expanded.len()) .take(matches - expanded.len())
.map(|s| s.clone()) .cloned()
.collect(); .collect();
expansion.append(&mut expanded); expansion.append(&mut expanded);
expansion expansion

View File

@ -11,7 +11,7 @@ use clap::crate_version;
use std::io::{self, Read}; use std::io::{self, Read};
fn app_args<'a>() -> clap::ArgMatches<'a> { fn app_args<'a>() -> clap::ArgMatches<'a> {
return App::new("thumbs") App::new("thumbs")
.version(crate_version!()) .version(crate_version!())
.about("A lightning fast version copy/pasting like vimium/vimperator") .about("A lightning fast version copy/pasting like vimium/vimperator")
.arg( .arg(
@ -103,7 +103,7 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
.long("contrast") .long("contrast")
.short("c"), .short("c"),
) )
.get_matches(); .get_matches()
} }
fn main() { fn main() {
@ -136,7 +136,7 @@ fn main() {
handle.read_to_string(&mut output).unwrap(); handle.read_to_string(&mut output).unwrap();
let lines = output.split("\n").collect::<Vec<&str>>(); let lines = output.split('\n').collect::<Vec<&str>>();
let mut state = state::State::new(&lines, alphabet, &regexp); let mut state = state::State::new(&lines, alphabet, &regexp);

View File

@ -65,9 +65,9 @@ pub struct State<'a> {
impl<'a> State<'a> { impl<'a> State<'a> {
pub fn new(lines: &'a Vec<&'a str>, alphabet: &'a str, regexp: &'a Vec<&'a str>) -> State<'a> { pub fn new(lines: &'a Vec<&'a str>, alphabet: &'a str, regexp: &'a Vec<&'a str>) -> State<'a> {
State { State {
lines: lines, lines,
alphabet: alphabet, alphabet,
regexp: regexp, regexp,
} }
} }
@ -131,7 +131,7 @@ impl<'a> State<'a> {
} }
chunk = chunk.get(matching.end()..).expect("Unknown chunk"); chunk = chunk.get(matching.end()..).expect("Unknown chunk");
offset = offset + matching.end() as i32; offset += matching.end() as i32;
} else { } else {
panic!("No matching?"); panic!("No matching?");
} }
@ -175,7 +175,7 @@ impl<'a> State<'a> {
matches.reverse(); matches.reverse();
} }
return matches; matches
} }
} }

View File

@ -69,17 +69,17 @@ impl<'a> Swapper<'a> {
let signal = format!("thumbs-finished-{}", since_the_epoch.as_secs()); let signal = format!("thumbs-finished-{}", since_the_epoch.as_secs());
Swapper { Swapper {
executor: executor, executor,
dir: dir, dir,
command: command, command,
upcase_command: upcase_command, upcase_command,
active_pane_id: None, active_pane_id: None,
active_pane_height: None, active_pane_height: None,
active_pane_scroll_position: None, active_pane_scroll_position: None,
active_pane_in_copy_mode: None, active_pane_in_copy_mode: None,
thumbs_pane_id: None, thumbs_pane_id: None,
content: None, content: None,
signal: signal, signal,
} }
} }
@ -95,33 +95,31 @@ impl<'a> Swapper<'a> {
.executor .executor
.execute(active_command.iter().map(|arg| arg.to_string()).collect()); .execute(active_command.iter().map(|arg| arg.to_string()).collect());
let lines: Vec<&str> = output.split("\n").collect(); let lines: Vec<&str> = output.split('\n').collect();
let chunks: Vec<Vec<&str>> = lines let chunks: Vec<Vec<&str>> = lines
.into_iter() .into_iter()
.map(|line| line.split(":").collect()) .map(|line| line.split(':').collect())
.collect(); .collect();
let active_pane = chunks let active_pane = chunks
.iter() .iter()
.find(|&chunks| *chunks.iter().nth(4).unwrap() == "active") .find(|&chunks| *chunks.get(4).unwrap() == "active")
.expect("Unable to find active pane"); .expect("Unable to find active pane");
let pane_id = active_pane.iter().nth(0).unwrap(); let pane_id = active_pane.get(0).unwrap();
let pane_in_copy_mode = active_pane.iter().nth(1).unwrap().to_string(); let pane_in_copy_mode = active_pane.get(1).unwrap().to_string();
self.active_pane_id = Some(pane_id.to_string()); self.active_pane_id = Some(pane_id.to_string());
self.active_pane_in_copy_mode = Some(pane_in_copy_mode); self.active_pane_in_copy_mode = Some(pane_in_copy_mode);
if self.active_pane_in_copy_mode.clone().unwrap() == "1" { if self.active_pane_in_copy_mode.clone().unwrap() == "1" {
let pane_height = active_pane let pane_height = active_pane
.iter() .get(2)
.nth(2)
.unwrap() .unwrap()
.parse() .parse()
.expect("Unable to retrieve pane height"); .expect("Unable to retrieve pane height");
let pane_scroll_position = active_pane let pane_scroll_position = active_pane
.iter() .get(3)
.nth(3)
.unwrap() .unwrap()
.parse() .parse()
.expect("Unable to retrieve pane scroll"); .expect("Unable to retrieve pane scroll");
@ -135,7 +133,7 @@ impl<'a> Swapper<'a> {
let options_command = vec!["tmux", "show", "-g"]; let options_command = vec!["tmux", "show", "-g"];
let params: Vec<String> = options_command.iter().map(|arg| arg.to_string()).collect(); let params: Vec<String> = options_command.iter().map(|arg| arg.to_string()).collect();
let options = self.executor.execute(params); let options = self.executor.execute(params);
let lines: Vec<&str> = options.split("\n").collect(); let lines: Vec<&str> = options.split('\n').collect();
let pattern = Regex::new(r#"@thumbs-([\w\-0-9]+) "(.*)""#).unwrap(); let pattern = Regex::new(r#"@thumbs-([\w\-0-9]+) "(.*)""#).unwrap();
@ -149,7 +147,7 @@ impl<'a> Swapper<'a> {
let boolean_params = vec!["reverse", "unique", "contrast"]; let boolean_params = vec!["reverse", "unique", "contrast"];
if boolean_params.iter().any(|&x| x == name) { if boolean_params.iter().any(|&x| x == name) {
return vec![format!("--{}", name).to_string()]; return vec![format!("--{}", name)];
} }
let string_params = vec![ let string_params = vec![
@ -164,13 +162,13 @@ impl<'a> Swapper<'a> {
if string_params.iter().any(|&x| x == name) { if string_params.iter().any(|&x| x == name) {
return vec![ return vec![
format!("--{}", name).to_string(), format!("--{}", name),
format!("'{}'", value).to_string(), format!("'{}'", value),
]; ];
} }
if name.starts_with("regexp") { if name.starts_with("regexp") {
return vec!["--regexp".to_string(), format!("'{}'", value).to_string()]; return vec!["--regexp".to_string(), format!("'{}'", value)];
} }
vec![] vec![]
@ -298,7 +296,7 @@ mod tests {
fn new(outputs: Vec<String>) -> TestShell { fn new(outputs: Vec<String>) -> TestShell {
TestShell { TestShell {
executed: None, executed: None,
outputs: outputs, outputs,
} }
} }
} }
@ -356,8 +354,9 @@ mod tests {
assert_eq!(executor.last_executed().unwrap(), expectation); assert_eq!(executor.last_executed().unwrap(), expectation);
} }
} }
fn app_args<'a>() -> clap::ArgMatches<'a> { fn app_args<'a>() -> clap::ArgMatches<'a> {
return App::new("tmux-thumbs") App::new("tmux-thumbs")
.version(crate_version!()) .version(crate_version!())
.about("A lightning fast version of tmux-fingers, copy/pasting tmux like vimium/vimperator") .about("A lightning fast version of tmux-fingers, copy/pasting tmux like vimium/vimperator")
.arg( .arg(
@ -378,7 +377,7 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
.long("upcase-command") .long("upcase-command")
.default_value("tmux set-buffer {} && tmux paste-buffer"), .default_value("tmux set-buffer {} && tmux paste-buffer"),
) )
.get_matches(); .get_matches()
} }
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {

View File

@ -36,42 +36,40 @@ impl<'a> View<'a> {
hint_background_color: Color, hint_background_color: Color,
) -> View<'a> { ) -> View<'a> {
View { View {
state: state, state,
skip: 0, skip: 0,
multi: multi, multi,
reverse: reverse, reverse,
unique: unique, unique,
contrast: contrast, contrast,
position: position, position,
select_foreground_color: select_foreground_color, select_foreground_color,
select_background_color: select_background_color, select_background_color,
foreground_color: foreground_color, foreground_color,
background_color: background_color, background_color,
hint_foreground_color: hint_foreground_color, hint_foreground_color,
hint_background_color: hint_background_color, hint_background_color,
} }
} }
pub fn prev(&mut self) { pub fn prev(&mut self) {
if self.skip > 0 { if self.skip > 0 {
self.skip = self.skip - 1; self.skip -= 1;
} }
} }
pub fn next(&mut self, maximum: usize) { pub fn next(&mut self, maximum: usize) {
if self.skip < maximum { if self.skip < maximum {
self.skip = self.skip + 1; self.skip += 1;
} }
} }
fn make_hint_text(&self, hint: &str) -> String { fn make_hint_text(&self, hint: &str) -> String {
let text = if self.contrast { if self.contrast {
format!("[{}]", hint).to_string() format!("[{}]", hint)
} else { } else {
hint.to_string() hint.to_string()
}; }
text
} }
pub fn present(&mut self) -> Vec<(String, bool)> { pub fn present(&mut self) -> Vec<(String, bool)> {
@ -88,8 +86,7 @@ impl<'a> View<'a> {
.iter() .iter()
.filter_map(|m| m.hint.clone()) .filter_map(|m| m.hint.clone())
.max_by(|x, y| x.len().cmp(&y.len())) .max_by(|x, y| x.len().cmp(&y.len()))
.unwrap() .unwrap();
.clone();
let mut selected; let mut selected;
let mut chosen = vec![]; let mut chosen = vec![];
@ -102,7 +99,7 @@ impl<'a> View<'a> {
for (index, line) in self.state.lines.iter().enumerate() { for (index, line) in self.state.lines.iter().enumerate() {
let clean = line.trim_end_matches(|c: char| c.is_whitespace()); let clean = line.trim_end_matches(|c: char| c.is_whitespace());
if clean.len() > 0 { if !clean.is_empty() {
let text = self.make_hint_text(line); let text = self.make_hint_text(line);
rustbox.print( rustbox.print(