Rename Group::Action to Event

This commit is contained in:
Joscha 2023-04-27 20:38:09 +02:00
parent 15177a529a
commit 6c99f7a53a
3 changed files with 36 additions and 36 deletions

View file

@ -56,7 +56,7 @@ default_bindings! {
pub fn to_next_unseen_message => ["L", "ctrl+right"];
}
pub mod tree_op {
pub mod tree_action {
pub fn reply => ["r"];
pub fn reply_alternate => ["R"];
pub fn new_thread => ["t"];
@ -77,7 +77,7 @@ default_bindings! {
pub fn down => [];
}
pub mod editor_op {
pub mod editor_action {
pub fn newline => [];
pub fn backspace => [];
pub fn delete => [];
@ -227,28 +227,28 @@ impl Default for EditorCursor {
}
#[derive(Debug, Deserialize, Document, Group)]
pub struct EditorOp {
pub struct EditorAction {
/// Insert newline.
#[serde(default = "default::editor_op::newline")]
#[serde(default = "default::editor_action::newline")]
pub newline: KeyBinding,
/// Delete before cursor.
#[serde(default = "default::editor_op::backspace")]
#[serde(default = "default::editor_action::backspace")]
pub backspace: KeyBinding,
/// Delete after cursor.
#[serde(default = "default::editor_op::delete")]
#[serde(default = "default::editor_action::delete")]
pub delete: KeyBinding,
/// Clear editor contents.
#[serde(default = "default::editor_op::clear")]
#[serde(default = "default::editor_action::clear")]
pub clear: KeyBinding,
}
impl Default for EditorOp {
impl Default for EditorAction {
fn default() -> Self {
Self {
newline: default::editor_op::newline(),
backspace: default::editor_op::backspace(),
delete: default::editor_op::delete(),
clear: default::editor_op::clear(),
newline: default::editor_action::newline(),
backspace: default::editor_action::backspace(),
delete: default::editor_action::delete(),
clear: default::editor_action::clear(),
}
}
}
@ -261,7 +261,7 @@ pub struct Editor {
#[serde(default)]
#[document(no_default)]
pub action: EditorOp,
pub action: EditorAction,
}
#[derive(Debug, Deserialize, Document, Group)]
@ -308,40 +308,40 @@ impl Default for TreeCursor {
}
#[derive(Debug, Deserialize, Document, Group)]
pub struct TreeOp {
pub struct TreeAction {
/// Reply to message (inline if possible).
#[serde(default = "default::tree_op::reply")]
#[serde(default = "default::tree_action::reply")]
pub reply: KeyBinding,
/// Reply to message, opposite of normal reply.
#[serde(default = "default::tree_op::reply_alternate")]
#[serde(default = "default::tree_action::reply_alternate")]
pub reply_alternate: KeyBinding,
/// Start a new thread.
#[serde(default = "default::tree_op::new_thread")]
#[serde(default = "default::tree_action::new_thread")]
pub new_thread: KeyBinding,
/// Fold current message's subtree.
#[serde(default = "default::tree_op::fold_tree")]
#[serde(default = "default::tree_action::fold_tree")]
pub fold_tree: KeyBinding,
/// Toggle current message's seen status.
#[serde(default = "default::tree_op::toggle_seen")]
#[serde(default = "default::tree_action::toggle_seen")]
pub toggle_seen: KeyBinding,
/// Mark all visible messages as seen.
#[serde(default = "default::tree_op::mark_visible_seen")]
#[serde(default = "default::tree_action::mark_visible_seen")]
pub mark_visible_seen: KeyBinding,
/// Mark all older messages as seen.
#[serde(default = "default::tree_op::mark_older_seen")]
#[serde(default = "default::tree_action::mark_older_seen")]
pub mark_older_seen: KeyBinding,
}
impl Default for TreeOp {
impl Default for TreeAction {
fn default() -> Self {
Self {
reply: default::tree_op::reply(),
reply_alternate: default::tree_op::reply_alternate(),
new_thread: default::tree_op::new_thread(),
fold_tree: default::tree_op::fold_tree(),
toggle_seen: default::tree_op::toggle_seen(),
mark_visible_seen: default::tree_op::mark_visible_seen(),
mark_older_seen: default::tree_op::mark_older_seen(),
reply: default::tree_action::reply(),
reply_alternate: default::tree_action::reply_alternate(),
new_thread: default::tree_action::new_thread(),
fold_tree: default::tree_action::fold_tree(),
toggle_seen: default::tree_action::toggle_seen(),
mark_visible_seen: default::tree_action::mark_visible_seen(),
mark_older_seen: default::tree_action::mark_older_seen(),
}
}
}
@ -354,7 +354,7 @@ pub struct Tree {
#[serde(default)]
#[document(no_default)]
pub action: TreeOp,
pub action: TreeAction,
}
#[derive(Debug, Default, Deserialize, Document)]

View file

@ -7,7 +7,7 @@ pub use input::*;
pub use keys::*;
pub trait Group {
type Action;
type Event;
fn action(&self, input: &mut Input) -> Option<Self::Action>;
fn event(&self, input: &mut Input) -> Option<Self::Event>;
}

View file

@ -21,7 +21,7 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
};
let struct_ident = input.ident;
let enum_ident = format_ident!("{}Action", struct_ident);
let enum_ident = format_ident!("{}Event", struct_ident);
let mut enum_variants = vec![];
let mut match_cases = vec![];
@ -38,7 +38,7 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
let description = decapitalize(&docstring);
let description = description.strip_suffix('.').unwrap_or(&description);
match_cases.push(quote!{
() if input.matches(&self.#field_ident, #description) => Some(Self::Action::#variant_ident),
() if input.matches(&self.#field_ident, #description) => Some(Self::Event::#variant_ident),
});
}
}
@ -50,9 +50,9 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
}
impl ::cove_input::Group for #struct_ident {
type Action = #enum_ident;
type Event = #enum_ident;
fn action(&self, input: &mut ::cove_input::Input) -> Option<Self::Action> {
fn event(&self, input: &mut ::cove_input::Input) -> Option<Self::Event> {
match () {
#( #match_cases )*
() => None,