use {super::RegistrationFlags, crate::core::CommandId};
const CAP_ACCEPTS_COUNT: u8 = 1 << 0;
const CAP_ACCEPTS_MOTION: u8 = 1 << 1;
const CAP_IS_JUMP: u8 = 1 << 2;
const CAP_IS_TEXT_MODIFYING: u8 = 1 << 3;
#[derive(Debug, Clone)]
pub struct CommandRegistration {
pub id: &'static str,
pub name: &'static str,
pub description: &'static str,
pub category: Option<&'static str>,
capabilities: u8,
pub depends_on: &'static [&'static str],
pub flags: RegistrationFlags,
}
impl CommandRegistration {
#[must_use]
pub const fn new(id: &'static str) -> Self {
Self {
id,
name: "",
description: "",
category: None,
capabilities: 0,
depends_on: &[],
flags: RegistrationFlags::new(),
}
}
#[must_use]
pub const fn with_name(mut self, name: &'static str) -> Self {
self.name = name;
self
}
#[must_use]
pub const fn with_description(mut self, desc: &'static str) -> Self {
self.description = desc;
self
}
#[must_use]
pub const fn with_category(mut self, cat: &'static str) -> Self {
self.category = Some(cat);
self
}
#[must_use]
pub const fn with_count(mut self) -> Self {
self.capabilities |= CAP_ACCEPTS_COUNT;
self
}
#[must_use]
pub const fn with_motion(mut self) -> Self {
self.capabilities |= CAP_ACCEPTS_MOTION;
self
}
#[must_use]
pub const fn with_jump(mut self) -> Self {
self.capabilities |= CAP_IS_JUMP;
self
}
#[must_use]
pub const fn with_text_modifying(mut self) -> Self {
self.capabilities |= CAP_IS_TEXT_MODIFYING;
self
}
#[must_use]
pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
self.depends_on = deps;
self
}
#[must_use]
pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
self.flags = flags;
self
}
#[must_use]
pub const fn accepts_count(&self) -> bool {
self.capabilities & CAP_ACCEPTS_COUNT != 0
}
#[must_use]
pub const fn accepts_motion(&self) -> bool {
self.capabilities & CAP_ACCEPTS_MOTION != 0
}
#[must_use]
pub const fn is_jump(&self) -> bool {
self.capabilities & CAP_IS_JUMP != 0
}
#[must_use]
pub const fn is_text_modifying(&self) -> bool {
self.capabilities & CAP_IS_TEXT_MODIFYING != 0
}
}
#[derive(Debug, Clone)]
pub struct KeybindingRegistration {
pub keys: &'static str,
pub command_id: CommandId,
pub modes: &'static [&'static str],
pub description: &'static str,
pub category: Option<&'static str>,
pub enabled: bool,
pub priority: u32,
pub depends_on: &'static [&'static str],
pub flags: RegistrationFlags,
}
impl KeybindingRegistration {
#[must_use]
pub const fn new(keys: &'static str, command_id: CommandId) -> Self {
Self {
keys,
command_id,
modes: &[],
description: "",
category: None,
enabled: true,
priority: 100, depends_on: &[],
flags: RegistrationFlags::new(),
}
}
#[must_use]
pub const fn with_modes(mut self, modes: &'static [&'static str]) -> Self {
self.modes = modes;
self
}
#[must_use]
pub const fn with_description(mut self, desc: &'static str) -> Self {
self.description = desc;
self
}
#[must_use]
pub const fn with_category(mut self, cat: &'static str) -> Self {
self.category = Some(cat);
self
}
#[must_use]
pub const fn with_disabled(mut self) -> Self {
self.enabled = false;
self
}
#[must_use]
pub const fn with_priority(mut self, priority: u32) -> Self {
self.priority = priority;
self
}
#[must_use]
pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
self.depends_on = deps;
self
}
#[must_use]
pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
self.flags = flags;
self
}
}
#[derive(Debug, Clone)]
pub struct EventHandlerRegistration {
pub event_type: &'static str,
pub priority: u32,
pub description: &'static str,
pub once: bool,
pub target_component: Option<&'static str>,
pub depends_on: &'static [&'static str],
pub flags: RegistrationFlags,
}
impl EventHandlerRegistration {
#[must_use]
pub const fn new(event_type: &'static str) -> Self {
Self {
event_type,
priority: 100, description: "",
once: false,
target_component: None,
depends_on: &[],
flags: RegistrationFlags::new(),
}
}
#[must_use]
pub const fn with_priority(mut self, priority: u32) -> Self {
self.priority = priority;
self
}
#[must_use]
pub const fn with_description(mut self, desc: &'static str) -> Self {
self.description = desc;
self
}
#[must_use]
pub const fn with_once(mut self) -> Self {
self.once = true;
self
}
#[must_use]
pub const fn with_target(mut self, component: &'static str) -> Self {
self.target_component = Some(component);
self
}
#[must_use]
pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
self.depends_on = deps;
self
}
#[must_use]
pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
self.flags = flags;
self
}
#[must_use]
pub const fn core_priority(mut self, priority: u32) -> Self {
self.priority = if priority > 50 { 50 } else { priority };
self
}
}