Skip to content

Commit

Permalink
Use FuzzySelect for workspace and project selection
Browse files Browse the repository at this point in the history
  • Loading branch information
blachniet committed Feb 24, 2024
1 parent 4f573ea commit 1c9f578
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
43 changes: 32 additions & 11 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/main.rs"
anyhow = "1.0"
chrono = "0.4.22"
clap = { version = "4.0.23", features = ["derive"] }
dialoguer = "0.10.2"
dialoguer = { version = "0.11", features = ["fuzzy-select"] }
elsa = "1.7.0"
keyring = "1"
thiserror = "1.0"
Expand Down
26 changes: 14 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,27 @@ fn run_start() -> Result<()> {
.get_workspaces()
.context("Failed to retrieve workspaces")?;
let workspace_names: Vec<_> = workspaces.iter().map(|w| w.name.to_string()).collect();
let workspace_idx = dialoguer::Select::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt("Select a workspace")
.items(&workspace_names)
.default(0)
.interact_on_opt(&dialoguer::console::Term::stderr())
.context("Failed to read workspace input")?
.ok_or_else(|| anyhow!("You must select a workspace"))?;
let workspace_idx =
dialoguer::FuzzySelect::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt("Select a workspace")
.items(&workspace_names)
.default(0)
.interact_on_opt(&dialoguer::console::Term::stderr())
.context("Failed to read workspace input")?
.ok_or_else(|| anyhow!("You must select a workspace"))?;

let workspace = &workspaces[workspace_idx];
let projects = client
.get_projects(workspace.id)
.context("Failed to get projects")?;
let projects: Vec<_> = projects.iter().filter(|p| p.active).collect();
let project_names: Vec<_> = projects.iter().map(|p| p.name.to_string()).collect();
let project_idx = dialoguer::Select::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt("Select a project or press 'q' to skip")
.items(&project_names)
.interact_on_opt(&dialoguer::console::Term::stderr())
.context("Failed to read project selection")?;
let project_idx =
dialoguer::FuzzySelect::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt("Select a project or press 'Esc' to skip")
.items(&project_names)
.interact_on_opt(&dialoguer::console::Term::stderr())
.context("Failed to read project selection")?;

let project_id = project_idx.map(|i| projects[i].id);
let description: String = dialoguer::Input::new()
Expand Down

0 comments on commit 1c9f578

Please sign in to comment.