54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use log::debug;
|
|
|
|
use crate::{
|
|
hlwm::{
|
|
command::{CommandError, HlwmCommand},
|
|
key::Keybind,
|
|
parser::FromStrings,
|
|
},
|
|
split,
|
|
};
|
|
|
|
pub enum ActiveKeybinds {
|
|
All,
|
|
OmitNamedTagBinds,
|
|
OnlyNamedTagBinds,
|
|
}
|
|
|
|
pub fn active_keybinds(ty: ActiveKeybinds) -> Result<Vec<Keybind>, CommandError> {
|
|
let (use_tag, move_tag) = (
|
|
HlwmCommand::UseTag(String::new()).to_string(),
|
|
HlwmCommand::MoveTag(String::new()).to_string(),
|
|
);
|
|
HlwmCommand::ListKeybinds
|
|
.execute_str()?
|
|
.split("\n")
|
|
.map(|l| l.trim())
|
|
.filter(|l| !l.is_empty())
|
|
.filter(|i| {
|
|
let parts = split::tab_or_space(*i);
|
|
if parts.len() < 2 {
|
|
debug!(
|
|
"active_keybinds: parts.len() for [{i}] was [{}]; expected >= 2",
|
|
parts.len()
|
|
);
|
|
return false;
|
|
}
|
|
let command = parts[1].as_str();
|
|
match ty {
|
|
ActiveKeybinds::All => true,
|
|
ActiveKeybinds::OmitNamedTagBinds => command != use_tag && command != move_tag,
|
|
ActiveKeybinds::OnlyNamedTagBinds => command == use_tag || command == move_tag,
|
|
}
|
|
})
|
|
.map(|row: &str| {
|
|
Ok(
|
|
Keybind::from_strings(split::tab_or_space(row).into_iter()).map_err(|err| {
|
|
debug!("row: [{row}], error: [{err}]");
|
|
err
|
|
})?,
|
|
)
|
|
})
|
|
.collect::<Result<Vec<_>, CommandError>>()
|
|
}
|