Skip to content

Commit

Permalink
add nonregex match; fix clipboard plugin type
Browse files Browse the repository at this point in the history
  • Loading branch information
griccardos committed Oct 16, 2023
1 parent aa3a192 commit 9ae1d88
Show file tree
Hide file tree
Showing 16 changed files with 1,711 additions and 345 deletions.
425 changes: 376 additions & 49 deletions dioxus/Cargo.lock

Large diffs are not rendered by default.

133 changes: 62 additions & 71 deletions dioxus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn app(cx: Scope<()>) -> Element {
ext: "".to_string(),
name: "".to_string(),
is_folder: false,
plugin: None,
});
};
message.set(format!("Found {} in {:.2}s", found_count, fe.duration.as_secs_f32()));
Expand All @@ -91,6 +92,7 @@ fn app(cx: Scope<()>) -> Element {
ext: "".to_string(),
name: "".to_string(),
is_folder: false,
plugin: None,
});
}
}
Expand All @@ -108,80 +110,72 @@ fn app(cx: Scope<()>) -> Element {

cx.render(rsx!(

div{
div {

//toolbar
div { style: "background-color:#404040;padding:10px;",
div { class: "mui-textfield",

//toolbar
div{
style:"background-color:#404040;padding:10px;",
div{
class:"mui-textfield",

input{
style:"color:lightgray;",
value:"{text_name}",
placeholder:"Regex file name search e.g. ^mai.*rs$ or r.st or ^best",
oninput: move|evt|{ let newval=evt.value.clone(); text_name.set(newval);},
input {
style: "color:lightgray;",
value: "{text_name}",
placeholder: "Regex file name search e.g. ^mai.*rs$ or r.st or ^best",
oninput: move |evt| {
let newval = evt.value.clone();
text_name.set(newval);
}
}
label { style: "color:white", "File name" }
}
label{
style:"color:white",
"File name"
div { class: "mui-textfield",
input {
style: "color:lightgray;",
value: "{text_contents}",
placeholder: "Regex content search e.g. str.{2}g",
oninput: move |evt| {
let newval = evt.value.clone();
text_contents.set(newval);
}
}
label { style: "color:white", "Contents" }
}
}
div{
class:"mui-textfield",
input{
style:"color:lightgray;",
value:"{text_contents}",
placeholder:"Regex content search e.g. str.{2}g",
oninput: move|evt|{ let newval=evt.value.clone(); text_contents.set(newval);},
}
label{
style:"color:white",
"Contents"
}
}
div{
class:"mui-textfield",
input{
style:"color:lightgray;",
value:"{text_dir}",
oninput: move|evt|{ let newval=evt.value.clone(); text_dir.set(newval);},
},
label{
style:"color:white",
"Directory"
div { class: "mui-textfield",
input {
style: "color:lightgray;",
value: "{text_dir}",
oninput: move |evt| {
let newval = evt.value.clone();
text_dir.set(newval);
}
}
label { style: "color:white", "Directory" }
}
div { "{message}" }
div {
button {
class: "mui-btn mui-btn--primary mui-btn--raised",
onclick: move |_| {
if text_name.is_empty() {
message.set("Nothing to search for".to_string());
} else {
message.set("Searching".to_string());
man.with_mut(|x| {
x.search(Search {
name_text: text_name.to_string(),
contents_text: text_contents.to_string(),
dir: text_dir.to_string(),
..Default::default()
})
});
}
},
"Find"
}
}
}
div{
"{message}",
}
div{
button{
class:"mui-btn mui-btn--primary mui-btn--raised",
onclick:move|_|{
if text_name.is_empty(){
message.set("Nothing to search for".to_string());
}else{
message.set("Searching".to_string());
man.with_mut(|x|x.search(Search {
name_text: text_name.to_string(),
contents_text:text_contents.to_string(),
dir: text_dir.to_string(),
..Default::default()
}));
}


},
"Find"
}
}
}

//results
div{
style:"padding:10px",
//results
div { style: "padding:10px",
data.current().borrow().iter().map(|x|
{
rsx!(
Expand All @@ -208,11 +202,8 @@ fn app(cx: Scope<()>) -> Element {

}
)


}

}
}
))
}

Expand Down
37 changes: 17 additions & 20 deletions druid/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion druid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rusl"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
build = "build.rs"
description = "search gui"
Expand Down
30 changes: 26 additions & 4 deletions druid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use druid::{
use regex::{Regex, RegexBuilder};

use librusl::{
extended::ExtendedTrait,
fileinfo::FileInfo,
manager::{FinalResults, Manager, SearchResult},
options::FTypes,
Expand Down Expand Up @@ -59,6 +60,7 @@ struct AppState {
name_use_gitignore: bool,
content_case_sensitive: bool,
content_extended: bool,
content_nonregex: bool,
//regex
#[data(ignore)]
re_name: Result<Regex, regex::Error>,
Expand Down Expand Up @@ -109,6 +111,7 @@ pub fn main() {
name_search_file_type: SearchFileType::All,
content_case_sensitive: ops.content.case_sensitive,
content_extended: ops.content.extended,
content_nonregex: ops.content.nonregex,
//regex
re_name: Regex::new(""),
re_content: Regex::new(""),
Expand Down Expand Up @@ -267,6 +270,7 @@ fn settings_panel() -> impl Widget<AppState> {
.with_child(Label::new("Content Settings").align_left().padding(10.))
.with_child(Checkbox::new("Case sensitive").lens(AppState::content_case_sensitive).align_left())
.with_child(Checkbox::new("Extended file types").lens(AppState::content_extended).align_left())
.with_child(Checkbox::new("Text match (non regex)").lens(AppState::content_nonregex).align_left())
.padding(10.),
Flex::column(),
)
Expand Down Expand Up @@ -337,6 +341,7 @@ impl AppDelegate<AppState> for Delegate {
ops.name.same_filesystem = data.name_same_filesystem;
ops.content.case_sensitive = data.content_case_sensitive;
ops.content.extended = data.content_extended;
ops.content.nonregex = data.content_nonregex;
ops.name.ignore_dot = data.name_ignore_dot;
ops.name.use_gitignore = data.name_use_gitignore;
ops.name.file_types = data.name_search_file_type.clone().into();
Expand Down Expand Up @@ -406,6 +411,10 @@ impl AppDelegate<AppState> for Delegate {
if filecount > 0 && foldercount > 0 {
string += &format!(" {} total", filecount + foldercount);
}
let line_count = results.data.iter().map(|x| x.matches.len()).sum::<usize>();
if line_count > 0 {
string += &format!(" with {} lines", line_count);
}

string += &format!(" in {:.3}s", data.start.elapsed().as_secs_f64());

Expand Down Expand Up @@ -544,6 +553,12 @@ fn highlight_result(
}
full.push(' ');
full.push_str(&x.path);
let plugin = if let Some(plug) = x.plugin {
format!(" ({})", plug.name())
} else {
String::new()
};
full.push_str(&plugin);
let mut rich = if !x.matches.is_empty() {
let start = full.len();
full.push('\n');
Expand Down Expand Up @@ -582,8 +597,8 @@ fn highlight_result(
if let Some(mat) = cap.get(0) {
let mut range = mat.range();
if range.end <= content.len() {
range.start += x.path.len() + symlen + 2;
range.end += x.path.len() + symlen + 2;
range.start += x.path.len() + plugin.len() + symlen + 2;
range.end += x.path.len() + plugin.len() + symlen + 2;
if full.is_char_boundary(range.start) && full.is_char_boundary(range.end) {
rich.add_attribute(range.clone(), Attribute::Weight(FontWeight::BOLD));
rich.add_attribute(range.clone(), Attribute::text_color(Color::rgb8(189, 60, 71)));
Expand All @@ -594,15 +609,22 @@ fn highlight_result(
}
}
}
//highlight plugin
if !plugin.is_empty() {
rich.add_attribute(
x.path.len() + symlen + 1..x.path.len() + symlen + 1 + plugin.len(),
Attribute::text_color(Color::rgb8(18, 110, 171)),
);
}

//highlight line number
if let Ok(re) = &re_numbers {
for cap in re.captures_iter(&content) {
if let Some(mat) = cap.get(0) {
let mut range = mat.range();
if range.end <= content.len() {
range.start += x.path.len() + symlen + 2;
range.end += x.path.len() + symlen + 2;
range.start += x.path.len() + plugin.len() + symlen + 2;
range.end += x.path.len() + plugin.len() + symlen + 2;
rich.add_attribute(range.clone(), Attribute::Weight(FontWeight::BOLD));
rich.add_attribute(range.clone(), Attribute::text_color(Color::rgb8(17, 122, 13)));
} else {
Expand Down
Loading

0 comments on commit 9ae1d88

Please sign in to comment.