Skip to content

Commit

Permalink
Clarify field names and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 20, 2024
1 parent fbbe6ca commit c858ee8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ in a terminal to launch Scooter. By default the current directory is used to sea
scooter ../foo/bar`
```

You can then enter some text to search with and text to replace matches with, toggle on or off fixed strings, and enter a regex pattern that filenames must match. A more extensive set of keymappings will be shown at the bottom of the window: these vary slightly depending on the screen you're on.
A set of keymappings will be shown at the bottom of the window: these vary slightly depending on the screen you're on.
### Search fields
When on the search screen the following fields are available:
- **Search text**: Text to search with. Defaults to regex, unless "Fixed strings" is enabled, in which case this reverts to case-sensitive string search.
- **Replace text**: Text to replace the search text with. If searching with regex, this can include capture groups.
- **Fixed strings**: If enabled, search with plain case-sensitive strings. If disabled, search with regex.
- **Path pattern (regex)**: Regex pattern that file paths must match. The relative path of the file is matched against: for instance, if searching in `/foo/`, if the path pattern is set to `bar` then `/foo/bar.txt` and `/foo/bar/file.rs` will be included. In the same example, if the path pattern is set to `foo` then `/foo/bar.txt` will *not* be included, but `/foo/foo.txt` will be.
## Installation
Expand Down Expand Up @@ -65,4 +74,4 @@ cargo install --path .
## Contributing
Contributions are very welcome! I'd be especially grateful for any contributions to add scooter to popular package managers. If you'd like to add a new feature, please create an issue first so we can discuss the idea, then create a PR with your changes.
Contributions are very welcome! I'd be especially grateful for any contributions to add Scooter to popular package managers. If you'd like to add a new feature, please create an issue first so we can discuss the idea, then create a PR with your changes.
15 changes: 5 additions & 10 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub enum FieldName {
Search,
Replace,
FixedStrings,
FilenamePattern,
PathPattern,
}

pub struct SearchField {
Expand Down Expand Up @@ -205,12 +205,7 @@ impl SearchFields {
Checkbox,
CheckboxField
);
define_field_accessor!(
filename_pattern,
FieldName::FilenamePattern,
Text,
TextField
);
define_field_accessor!(path_pattern, FieldName::PathPattern, Text, TextField);

pub fn focus_next(&mut self) {
self.highlighted = (self.highlighted + 1) % self.fields.len();
Expand Down Expand Up @@ -263,7 +258,7 @@ impl SearchFields {
field: Rc::new(RefCell::new(Field::checkbox(fixed_strings))),
},
SearchField {
name: FieldName::FilenamePattern,
name: FieldName::PathPattern,
field: Rc::new(RefCell::new(Field::text(filname_pattern.into()))),
},
],
Expand Down Expand Up @@ -462,15 +457,15 @@ impl App {

let mut results = vec![];

let s = self.search_fields.filename_pattern().text();
let s = self.search_fields.path_pattern().text();
let patt = if s.is_empty() {
None
} else {
match Regex::new(s.as_str()) {
Err(e) => {
info!("Error when parsing filname pattern regex {}", e);
self.search_fields
.filename_pattern()
.path_pattern()
.set_error("Couldn't parse regex".to_owned());
return Ok(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl FieldName {
FieldName::Search => "Search text",
FieldName::Replace => "Replace text",
FieldName::FixedStrings => "Fixed strings",
FieldName::FilenamePattern => "Filename pattern (regex)",
FieldName::PathPattern => "Path pattern (regex)",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn test_back_from_results() {
assert_eq!(app.search_fields.search().text, "foo");
assert_eq!(app.search_fields.replace().text, "bar");
assert!(app.search_fields.fixed_strings().checked);
assert_eq!(app.search_fields.filename_pattern().text, "pattern");
assert_eq!(app.search_fields.path_pattern().text, "pattern");
assert_eq!(app.current_screen, CurrentScreen::Searching);
assert_eq!(app.results, Results::Loading);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn test_search_fields() {
field: Rc::new(RefCell::new(Field::checkbox(false))),
},
SearchField {
name: FieldName::FilenamePattern,
name: FieldName::PathPattern,
field: Rc::new(RefCell::new(Field::text(""))),
},
],
Expand Down

0 comments on commit c858ee8

Please sign in to comment.