-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Shizcow/develop
New plugins
- Loading branch information
Showing
12 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,9 +359,7 @@ impl Drw { | |
} | ||
}, | ||
} | ||
if self.draw().is_err() { | ||
return Ok(true); | ||
} | ||
self.draw()?; | ||
} | ||
Ok(false) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fuzzy-matcher = "0.3.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use overrider::*; | ||
|
||
#[allow(unused_imports)] | ||
use crate::clapflags::CLAP_FLAGS; | ||
|
||
use fuzzy_matcher::FuzzyMatcher; | ||
use fuzzy_matcher::skim::SkimMatcherV2; | ||
|
||
use crate::drw::Drw; | ||
use crate::item::Item; | ||
|
||
#[override_default] | ||
impl Drw { | ||
pub fn gen_matches(&mut self) -> Result<Vec<Item>, String> { | ||
let searchterm = self.input.clone(); | ||
let mut items: Vec<(Item, i64)> = | ||
self.items.as_mut().unwrap().data.iter().map(|item| { | ||
let matcher: Box<dyn FuzzyMatcher> = Box::new(SkimMatcherV2::default()); | ||
(item.clone(), | ||
if let Some(score) = matcher.fuzzy_match(&item.text, &searchterm) { | ||
-score | ||
} else { | ||
1 | ||
}) | ||
}).collect(); | ||
items.retain(|(_, score)| *score <= 0); | ||
items.sort_by_key(|(item, _)| item.text.len()); // this prioritizes exact matches | ||
items.sort_by_key(|(_, score)| *score); | ||
|
||
Ok(items.into_iter().map(|(item, _)| item).collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
about: Fuzzy string matching for searches | ||
entry: main.rs | ||
cargo_dependencies: deps.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ispell = "0.3.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use overrider::*; | ||
|
||
use ispell::{SpellLauncher}; | ||
use std::process::{Command, Stdio}; | ||
use std::io::Write; | ||
|
||
use crate::drw::Drw; | ||
use crate::item::Item; | ||
|
||
#[override_flag(flag = spellcheck)] | ||
impl Drw { | ||
pub fn gen_matches(&mut self) -> Result<Vec<Item>, String> { | ||
let checker = SpellLauncher::new() | ||
.aspell() | ||
.launch(); | ||
|
||
let (first, second) = self.input.split_at(self.pseudo_globals.cursor); | ||
let first_replaced = first.replace(" ", ""); | ||
let second_replaced = second.replace(" ", ""); | ||
self.pseudo_globals.cursor = first_replaced.chars().count(); | ||
self.input = first_replaced+&second_replaced; | ||
|
||
match checker { | ||
Ok(mut checker) => { | ||
match checker.check(&self.input) { | ||
Ok(mut res) => { | ||
if res.is_empty() { | ||
Ok(vec![Item::new(self.input.clone(), false, self)?]) | ||
} else { | ||
let mut ret = Vec::new(); | ||
for word in res.swap_remove(0).suggestions.into_iter() { | ||
ret.push(Item::new(word, false, self)?); | ||
} | ||
Ok(ret) | ||
} | ||
}, | ||
Err(err) => Err(format!("Error: could not run aspell: {}", err)) | ||
} | ||
}, | ||
Err(err) => Err(format!("Error: could not start aspell: {}", err)) | ||
} | ||
} | ||
pub fn dispose(&mut self, output: String, recommendation: bool) -> Result<bool, String> { | ||
if output.len() > 0 { | ||
let mut child = Command::new("xclip") | ||
.arg("-sel") | ||
.arg("clip") | ||
.stdin(Stdio::piped()) | ||
.spawn() | ||
.map_err(|_| "Failed to spawn child process".to_owned())?; | ||
|
||
child.stdin.as_mut().ok_or("Failed to open stdin".to_owned())? | ||
.write_all(output.as_bytes()).map_err(|_| "Failed to write to stdin".to_owned())?; | ||
} | ||
Ok(recommendation) | ||
} | ||
} | ||
|
||
use crate::config::{ConfigDefault, DefaultWidth}; | ||
#[override_flag(flag = spellcheck)] | ||
impl ConfigDefault { | ||
pub fn nostdin() -> bool { | ||
true | ||
} | ||
pub fn render_flex() -> bool { | ||
true | ||
} | ||
pub fn render_default_width() -> DefaultWidth { | ||
DefaultWidth::Custom(10) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
about: Single word spellcheck | ||
entry: main.rs | ||
cargo_dependencies: deps.toml | ||
|
||
args: | ||
- spellcheck: | ||
help: Enter spellcheck mode | ||
long_help: "Enter spellcheck mode. Begin typing a word for spelling suggestions.\nOnly accepts | ||
single word queries.\nPressing Enter will copy to clipboard before exiting." | ||
long: spellcheck | ||
visible_aliases: sc |