add profile list with json and dmenu display modes
This commit is contained in:
parent
4e2716cb46
commit
0b7b681e86
3 changed files with 34 additions and 8 deletions
|
|
@ -56,12 +56,12 @@ pub enum ShortcutCommand {
|
|||
#[clap(alias = "g")]
|
||||
Get {
|
||||
#[arg(short, long)]
|
||||
mode: Option<ShortcutMode>,
|
||||
mode: Option<DisplayMode>,
|
||||
},
|
||||
}
|
||||
|
||||
#[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<DisplayMode>,
|
||||
},
|
||||
/// Initialize Sway-DE-Utils
|
||||
#[clap(alias = "i")]
|
||||
Init,
|
||||
|
|
|
|||
|
|
@ -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<Profile>) -> Result<(), SDUError> {
|
||||
let output = match mode {
|
||||
DisplayMode::Dmenu => {
|
||||
let mut dmenu_entries = Vec::<String>::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,
|
||||
|
|
|
|||
|
|
@ -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<ScriptConf>) -> String {
|
||||
fn print_shortcuts(mode: &DisplayMode, shortcuts: Vec<ScriptConf>) -> String {
|
||||
match mode {
|
||||
ShortcutMode::Dmenu => {
|
||||
DisplayMode::Dmenu => {
|
||||
let mut dmenu_entries = Vec::<String>::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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue