diff --git a/src/lib/cli.rs b/src/lib/cli.rs index 53d83ad..3c63fc3 100644 --- a/src/lib/cli.rs +++ b/src/lib/cli.rs @@ -56,12 +56,12 @@ pub enum ShortcutCommand { #[clap(alias = "g")] Get { #[arg(short, long)] - mode: Option, + mode: Option, }, } #[derive(Clone, Copy, ValueEnum, Subcommand)] -pub enum ShortcutMode { +pub enum DisplayMode { /// Print formatted for dmenu/wofi #[clap(alias = "d")] Dmenu, @@ -147,6 +147,12 @@ pub enum ProfileCommand { #[command(subcommand)] shortcut_command: ShortcutCommand, }, + /// List Profiles + #[clap(alias = "l")] + List { + #[arg(short, long)] + mode: Option, + }, /// Initialize Sway-DE-Utils #[clap(alias = "i")] Init, diff --git a/src/lib/profile.rs b/src/lib/profile.rs index 369d6b4..35f2dff 100644 --- a/src/lib/profile.rs +++ b/src/lib/profile.rs @@ -4,7 +4,7 @@ use { get_xdg_dirs, lib::{ SDUError, - cli::{ProfileCommand, ProfileGetCommand, ProfileSwitchCommand}, + cli::{DisplayMode, ProfileCommand, ProfileGetCommand, ProfileSwitchCommand}, get, get_sway_connection, run_sway_command, shortcuts_fn, sway::focused_workspace_profile, }, @@ -130,9 +130,28 @@ pub fn profile_fn( .expect("could not find scripts for profile"), ) } + ProfileCommand::List { mode } => { + list_profiles(mode.unwrap_or(DisplayMode::Json), profiles_config) + } } } +//TODO: Consolidate this function with print_shortcuts in shortcuts.rs +fn list_profiles(mode: DisplayMode, profiles: Vec) -> Result<(), SDUError> { + let output = match mode { + DisplayMode::Dmenu => { + let mut dmenu_entries = Vec::::new(); + for profile in profiles { + dmenu_entries.push(format!("{} {}", profile.icon, profile.name)); + } + dmenu_entries.join("\n") + } + DisplayMode::Json => json!(profiles).to_string(), + }; + println!("{}", output); + Ok(()) +} + fn initialize( mut sway_connection: Connection, profile: Profile, diff --git a/src/lib/shortcuts.rs b/src/lib/shortcuts.rs index f1bcac7..146831d 100644 --- a/src/lib/shortcuts.rs +++ b/src/lib/shortcuts.rs @@ -5,21 +5,22 @@ use crate::{ config::ScriptConf, lib::{ SDUError, - cli::{ShortcutCommand, ShortcutMode}, + cli::{DisplayMode, ShortcutCommand}, sway_ipc::{get_sway_connection, run_sway_command}, }, }; -fn print_shortcuts(mode: &ShortcutMode, shortcuts: Vec) -> String { +fn print_shortcuts(mode: &DisplayMode, shortcuts: Vec) -> String { match mode { - ShortcutMode::Dmenu => { + DisplayMode::Dmenu => { let mut dmenu_entries = Vec::::new(); for shortcut in shortcuts { dmenu_entries.push(format!("{} {}", shortcut.icon, shortcut.name)); } + //TODO: collect active profile information before returning it here? dmenu_entries.join("\n") } - ShortcutMode::Json => json!(shortcuts).to_string(), + DisplayMode::Json => json!(shortcuts).to_string(), } } @@ -44,7 +45,7 @@ pub fn shortcuts_fn( exec_shortcut(shortcut_name.to_string(), shortcuts) } ShortcutCommand::Get { mode } => { - let shortcuts_string = print_shortcuts(&mode.unwrap_or(ShortcutMode::Json), shortcuts); + let shortcuts_string = print_shortcuts(&mode.unwrap_or(DisplayMode::Json), shortcuts); println!("{}", shortcuts_string); Ok(()) }