Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Aug 18, 2024
1 parent 25a60f6 commit fed3744
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
19 changes: 19 additions & 0 deletions overlays/pkgs/sway-helper/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 overlays/pkgs/sway-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "4.5.16"
clap = { version = "4.5.16", features = ["derive"] }
fzf-wrapped = "0.1.4"
swayipc = "3.0.2"
46 changes: 44 additions & 2 deletions overlays/pkgs/sway-helper/src/main.rs
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
}

0 comments on commit fed3744

Please sign in to comment.