reovim_kernel/api/module/
registration.rs1use {super::RegistrationFlags, crate::core::CommandId};
4
5const CAP_ACCEPTS_COUNT: u8 = 1 << 0;
7const CAP_ACCEPTS_MOTION: u8 = 1 << 1;
9const CAP_IS_JUMP: u8 = 1 << 2;
11const CAP_IS_TEXT_MODIFYING: u8 = 1 << 3;
13
14#[derive(Debug, Clone)]
23pub struct CommandRegistration {
24 pub id: &'static str,
26 pub name: &'static str,
28 pub description: &'static str,
30 pub category: Option<&'static str>,
32 capabilities: u8,
34 pub depends_on: &'static [&'static str],
36 pub flags: RegistrationFlags,
38}
39
40impl CommandRegistration {
41 #[must_use]
43 pub const fn new(id: &'static str) -> Self {
44 Self {
45 id,
46 name: "",
47 description: "",
48 category: None,
49 capabilities: 0,
50 depends_on: &[],
51 flags: RegistrationFlags::new(),
52 }
53 }
54
55 #[must_use]
57 pub const fn with_name(mut self, name: &'static str) -> Self {
58 self.name = name;
59 self
60 }
61
62 #[must_use]
64 pub const fn with_description(mut self, desc: &'static str) -> Self {
65 self.description = desc;
66 self
67 }
68
69 #[must_use]
71 pub const fn with_category(mut self, cat: &'static str) -> Self {
72 self.category = Some(cat);
73 self
74 }
75
76 #[must_use]
78 pub const fn with_count(mut self) -> Self {
79 self.capabilities |= CAP_ACCEPTS_COUNT;
80 self
81 }
82
83 #[must_use]
85 pub const fn with_motion(mut self) -> Self {
86 self.capabilities |= CAP_ACCEPTS_MOTION;
87 self
88 }
89
90 #[must_use]
92 pub const fn with_jump(mut self) -> Self {
93 self.capabilities |= CAP_IS_JUMP;
94 self
95 }
96
97 #[must_use]
99 pub const fn with_text_modifying(mut self) -> Self {
100 self.capabilities |= CAP_IS_TEXT_MODIFYING;
101 self
102 }
103
104 #[must_use]
106 pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
107 self.depends_on = deps;
108 self
109 }
110
111 #[must_use]
113 pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
114 self.flags = flags;
115 self
116 }
117
118 #[must_use]
124 pub const fn accepts_count(&self) -> bool {
125 self.capabilities & CAP_ACCEPTS_COUNT != 0
126 }
127
128 #[must_use]
130 pub const fn accepts_motion(&self) -> bool {
131 self.capabilities & CAP_ACCEPTS_MOTION != 0
132 }
133
134 #[must_use]
136 pub const fn is_jump(&self) -> bool {
137 self.capabilities & CAP_IS_JUMP != 0
138 }
139
140 #[must_use]
142 pub const fn is_text_modifying(&self) -> bool {
143 self.capabilities & CAP_IS_TEXT_MODIFYING != 0
144 }
145}
146
147#[derive(Debug, Clone)]
151pub struct KeybindingRegistration {
152 pub keys: &'static str,
154 pub command_id: CommandId,
156 pub modes: &'static [&'static str],
159 pub description: &'static str,
161 pub category: Option<&'static str>,
163 pub enabled: bool,
165 pub priority: u32,
168 pub depends_on: &'static [&'static str],
170 pub flags: RegistrationFlags,
172}
173
174impl KeybindingRegistration {
175 #[must_use]
181 pub const fn new(keys: &'static str, command_id: CommandId) -> Self {
182 Self {
183 keys,
184 command_id,
185 modes: &[],
186 description: "",
187 category: None,
188 enabled: true,
189 priority: 100, depends_on: &[],
191 flags: RegistrationFlags::new(),
192 }
193 }
194
195 #[must_use]
197 pub const fn with_modes(mut self, modes: &'static [&'static str]) -> Self {
198 self.modes = modes;
199 self
200 }
201
202 #[must_use]
204 pub const fn with_description(mut self, desc: &'static str) -> Self {
205 self.description = desc;
206 self
207 }
208
209 #[must_use]
211 pub const fn with_category(mut self, cat: &'static str) -> Self {
212 self.category = Some(cat);
213 self
214 }
215
216 #[must_use]
218 pub const fn with_disabled(mut self) -> Self {
219 self.enabled = false;
220 self
221 }
222
223 #[must_use]
225 pub const fn with_priority(mut self, priority: u32) -> Self {
226 self.priority = priority;
227 self
228 }
229
230 #[must_use]
232 pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
233 self.depends_on = deps;
234 self
235 }
236
237 #[must_use]
239 pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
240 self.flags = flags;
241 self
242 }
243}
244
245#[derive(Debug, Clone)]
254pub struct EventHandlerRegistration {
255 pub event_type: &'static str,
257 pub priority: u32,
259 pub description: &'static str,
261 pub once: bool,
263 pub target_component: Option<&'static str>,
265 pub depends_on: &'static [&'static str],
267 pub flags: RegistrationFlags,
269}
270
271impl EventHandlerRegistration {
272 #[must_use]
274 pub const fn new(event_type: &'static str) -> Self {
275 Self {
276 event_type,
277 priority: 100, description: "",
279 once: false,
280 target_component: None,
281 depends_on: &[],
282 flags: RegistrationFlags::new(),
283 }
284 }
285
286 #[must_use]
288 pub const fn with_priority(mut self, priority: u32) -> Self {
289 self.priority = priority;
290 self
291 }
292
293 #[must_use]
295 pub const fn with_description(mut self, desc: &'static str) -> Self {
296 self.description = desc;
297 self
298 }
299
300 #[must_use]
302 pub const fn with_once(mut self) -> Self {
303 self.once = true;
304 self
305 }
306
307 #[must_use]
309 pub const fn with_target(mut self, component: &'static str) -> Self {
310 self.target_component = Some(component);
311 self
312 }
313
314 #[must_use]
316 pub const fn with_depends_on(mut self, deps: &'static [&'static str]) -> Self {
317 self.depends_on = deps;
318 self
319 }
320
321 #[must_use]
323 pub const fn with_flags(mut self, flags: RegistrationFlags) -> Self {
324 self.flags = flags;
325 self
326 }
327
328 #[must_use]
330 pub const fn core_priority(mut self, priority: u32) -> Self {
331 self.priority = if priority > 50 { 50 } else { priority };
332 self
333 }
334}