Skip to content

Commit f2edd4c

Browse files
committed
docs: add more documentation
1 parent af106c2 commit f2edd4c

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/config/commands.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
//! - Add the module to the `declare_global_commands!` macro invocation below
88
//! - Implement the [`crate::command::Handler`] trait for the `Command` generated by `declare_commands!`.
99
10-
use ui::popup::keybindings_cheatsheet;
11-
12-
use crate::ui;
13-
1410
use super::key::{KeyMods, KeySequence};
11+
use crate::ui;
12+
use ui::popup::keybindings_cheatsheet;
1513

1614
/// Handles commands which mutate state of the application.
1715
///
1816
/// A `Command` is a subset of a `Message` which can be bound to a keybinding, and
1917
/// can therefore receive a `count`.
18+
///
19+
/// You should use this as `crate::command::Handler`.
2020
pub trait CommandHandler {
2121
/// Handle the invoked command, mutating the `App`.
2222
///
@@ -58,7 +58,7 @@ pub trait CommandHandler {
5858
macro_rules! declare_commands {
5959
(
6060
$(#[$Command_Attr:meta])*
61-
enum Command {
61+
enum $Command:ident {
6262
$(
6363
$(#[$Keymappable_Command_Attr:meta])*
6464
$Keymappable_Command:ident $({$(
@@ -85,19 +85,13 @@ macro_rules! declare_commands {
8585
}
8686
)*
8787

88-
/// A list of keybindings which exist in the app
89-
#[derive(ferrishot_knus::Decode, Debug, Clone)]
90-
pub enum KeymappableCommand {
91-
$(
92-
$Keymappable_Command($Keymappable_Command),
93-
)*
94-
}
95-
96-
/// An action in the app
88+
/// Contains a couple of commands, which are specific to this module.
89+
///
90+
/// See [`Command`](crate::config::commands::Command) for more info.
9791
#[allow(clippy::derive_partial_eq_without_eq, reason = "f32 cannot derive `Eq`")]
9892
#[derive(Debug, Clone, PartialEq, Copy)]
9993
$(#[$Command_Attr])*
100-
pub enum Command {
94+
pub enum $Command {
10195
$(
10296
$(#[$Keymappable_Command_Attr])*
10397
$Keymappable_Command $(
@@ -110,7 +104,21 @@ macro_rules! declare_commands {
110104
)*
111105
}
112106

107+
/// Parses the corresponding commands in the KDL file.
108+
///
109+
/// See [`KeymappableCommand`](crate::config::commands::KeymappableCommand) for more info.
110+
#[derive(ferrishot_knus::Decode, Debug, Clone)]
111+
pub enum KeymappableCommand {
112+
$(
113+
$Keymappable_Command($Keymappable_Command),
114+
)*
115+
}
116+
113117
impl KeymappableCommand {
118+
/// # Returns
119+
///
120+
/// The keys necessary to trigger the `Command`, as well as the `Command` itself.
121+
/// This is a key-value pair which will be stored in the `KeyMap`.
114122
pub fn action(self) -> (($crate::config::key::KeySequence, $crate::config::key::KeyMods), Command) {
115123
match self {
116124
$(

0 commit comments

Comments
 (0)