Skip to content

Commit

Permalink
Use Query in cli.rs (#1024)
Browse files Browse the repository at this point in the history
I'm planning to support left/right move.
Query will support the keyboard events.

In this patch, I first want to replace the primitive `String` with
`Query` in advance.
  • Loading branch information
yykamei authored Aug 6, 2024
1 parent 73eaa26 commit 114251a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::error::Result;
use crate::finder::Finder;
use crate::matched_path::MatchedPath;
use crate::preferences::Preferences;
use crate::query::Query;
use crate::starting_point::StartingPoint;
use crate::status_line::StatusLine;
use crate::terminal::Terminal;
Expand Down Expand Up @@ -136,7 +137,7 @@ struct Runner<'a, W: Write, T: Terminal> {
max_columns: u16,
max_rows: u16,
starting_point: StartingPoint,
query: String,
query: Query,
selection: u16,
state: State,
}
Expand Down Expand Up @@ -167,7 +168,7 @@ impl<'a, W: Write, T: Terminal> Runner<'a, W, T> {
};
let (max_columns, max_rows) = terminal.size()?;
let starting_point = StartingPoint::new(&preferences.starting_point)?;
let query = preferences.query.clone();
let query = Query::new(&preferences.query);

Ok(Self {
preferences,
Expand Down Expand Up @@ -269,7 +270,11 @@ impl<'a, W: Write, T: Terminal> Runner<'a, W, T> {
fn find_paths(&self, limit: impl Into<usize>) -> Result<Vec<MatchedPath>> {
let mut paths = Vec::with_capacity(100); // TODO: Tune this capacity later.

for path in Finder::new(&self.starting_point, &self.query, self.repo.as_ref())? {
for path in Finder::new(
&self.starting_point,
&self.query.to_string(),
self.repo.as_ref(),
)? {
match path {
Ok(path) => paths.push(path),
Err(e) => log::error!("Failed to get the path: {}", e),
Expand Down
2 changes: 1 addition & 1 deletion src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Query {
Self { value, idx }
}

pub(crate) fn push(&mut self, s: &str) {
pub(crate) fn push<S: ToString>(&mut self, s: S) {
self.value.insert(self.idx, s.to_string());
self.idx += 1;
}
Expand Down

0 comments on commit 114251a

Please sign in to comment.