-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,58 @@ | ||
use clap::{Parser, Subcommand}; | ||
use fzf_wrapped::Fzf; | ||
|
||
#[derive(Debug, Parser)] | ||
struct Cli { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
RenameCurrentWorkspace, | ||
SwitchToWorkspace, | ||
} | ||
|
||
impl CliRun for Command { | ||
fn run(&self) { | ||
match self { | ||
Self::RenameCurrentWorkspace => todo!(), | ||
Self::SwitchToWorkspace => SwitchToWorkspace{}.run(), | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let cli = Cli::parse(); | ||
println!("{:?}", cli); | ||
|
||
let mut conn = swayipc::Connection::new().unwrap(); | ||
|
||
let workspaces = conn.get_workspaces().unwrap(); | ||
let workspace_names: Vec<&str> = workspaces.iter().map(|i| i.name.as_ref()).collect(); | ||
|
||
let users_selection = do_fzf(workspace_names); | ||
println!("{users_selection}"); | ||
} | ||
|
||
trait CliRun { | ||
fn run(&self); | ||
} | ||
|
||
struct SwitchToWorkspace{} | ||
|
||
impl CliRun for SwitchToWorkspace { | ||
fn run(&self) { | ||
todo!() | ||
} | ||
} | ||
|
||
fn do_fzf<T: IntoIterator<Item = impl Into<String>>>(items: T) -> String{ | ||
let mut fzf = Fzf::default(); | ||
fzf.run().expect("Failed to start fzf"); | ||
|
||
fzf.add_items(workspace_names).expect("Failed to add items"); | ||
fzf.add_items(items).expect("Failed to add items"); | ||
|
||
let users_selection = fzf.output().expect("Failed to get the user's output"); | ||
println!("{users_selection}"); | ||
users_selection | ||
} |