Skip to content
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

Accept a query parameter to start #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Action {
Suspend,
Resume,
Quit,
Init,
Init { query: Option<String> },
Refresh,
NextTab,
PreviousTab,
Expand Down
21 changes: 16 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ impl App {
}

/// Runs the main loop of the application, handling events and actions
pub async fn run(&mut self, mut tui: Tui, mut events: Events) -> Result<()> {
pub async fn run(
&mut self,
mut tui: Tui,
mut events: Events,
query: Option<String>,
) -> Result<()> {
// uncomment to test error handling
// panic!("test panic");
// Err(color_eyre::eyre::eyre!("Error"))?;
self.tx.send(Action::Init)?;
self.tx.send(Action::Init { query })?;

loop {
if let Some(e) = events.next().await {
Expand Down Expand Up @@ -207,7 +212,7 @@ impl App {
match action {
Action::Quit => self.quit(),
Action::KeyRefresh => self.key_refresh_tick(),
Action::Init => self.init()?,
Action::Init { ref query } => self.init(query)?,
Action::Tick => self.tick(),
Action::StoreTotalNumberOfCrates(n) => self.store_total_number_of_crates(n),
Action::ScrollUp => self.scroll_up(),
Expand Down Expand Up @@ -282,8 +287,14 @@ impl App {
self.search.update_search_table_results();
}

fn init(&mut self) -> Result<()> {
self.summary.request()?;
fn init(&mut self, query: &Option<String>) -> Result<()> {
if let Some(query) = query {
self.search.search = query.clone();
let _ = self.tx.send(Action::SwitchMode(Mode::Search));
let _ = self.tx.send(Action::SubmitSearch);
} else {
self.summary.request()?;
}
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const HELP_STYLES: Styles = Styles::styled()
#[derive(Debug, Default, Parser, Serialize)]
#[command(author, version = version(), about, long_about = None, styles = HELP_STYLES)]
pub struct Cli {
/// Initial Query
#[arg(value_name = "QUERY")]
pub query: Option<String>,

/// Print default configuration
#[arg(long)]
pub print_default_config: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<()> {

let tui = tui::init()?;
let events = events::Events::new();
App::new().run(tui, events).await?;
App::new().run(tui, events, cli.query).await?;
tui::restore()?;
Ok(())
}
Loading