-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no_ui
option that directly writes the first suggestion to a file
#276
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,41 @@ fn handle_addition(settings: &Settings) { | |
|
||
fn handle_search(settings: &Settings) { | ||
let history = History::load(settings.history_format); | ||
|
||
if settings.no_ui { | ||
history.build_cache_table( | ||
&settings.dir.to_owned(), | ||
&Some(settings.session_id.to_owned()), | ||
None, | ||
None, | ||
None, | ||
settings.limit.to_owned(), | ||
); | ||
let matches = history.find_matches( | ||
&settings.command, | ||
settings.results as i16, | ||
settings.fuzzy, | ||
&mcfly::settings::ResultSort::Rank, | ||
); | ||
|
||
let cmd = match matches.first() { | ||
Some(cmd) => cmd.cmd.to_owned(), | ||
None => settings.command.to_owned(), | ||
}; | ||
let cmd_t = cmd.trim(); | ||
if cmd_t.is_empty() { | ||
return; | ||
} | ||
|
||
let out = format!("mode display\ncommandline {}\n", cmd_t); | ||
if let Some(path) = &settings.output_selection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of requiring
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was originally written this way, however I found that we are happily There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should only be using print! to output when there's an error. Those should probably be converted to use STDERR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should update all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! |
||
fs::write(path, out) | ||
.unwrap_or_else(|err| panic!("McFly error: unable to write to {}: {}", path, err)); | ||
} | ||
|
||
return; | ||
} | ||
|
||
let result = Interface::new(settings, &history).display(); | ||
if let Some(cmd) = result.selection { | ||
if let Some(path) = &settings.output_selection { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like if it cannot find a match, it should return nothing, not the search query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I somehow misunderstood what the original UI code was doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still returning the search query, right?