Rename Group to KeyGroup

This commit is contained in:
Joscha 2023-04-27 20:55:26 +02:00
parent 6c99f7a53a
commit fdc46aa3b8
4 changed files with 15 additions and 14 deletions

View file

@ -1,4 +1,4 @@
use cove_input::{Group, KeyBinding}; use cove_input::{KeyBinding, KeyGroup};
use serde::Deserialize; use serde::Deserialize;
use crate::doc::Document; use crate::doc::Document;
@ -86,7 +86,7 @@ default_bindings! {
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct General { pub struct General {
/// Quit cove. /// Quit cove.
#[serde(default = "default::general::exit")] #[serde(default = "default::general::exit")]
@ -117,7 +117,7 @@ impl Default for General {
} }
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct Scroll { pub struct Scroll {
/// Scroll up one line. /// Scroll up one line.
#[serde(default = "default::scroll::up_line")] #[serde(default = "default::scroll::up_line")]
@ -152,7 +152,7 @@ impl Default for Scroll {
} }
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct Cursor { pub struct Cursor {
/// Move cursor up. /// Move cursor up.
#[serde(default = "default::cursor::up")] #[serde(default = "default::cursor::up")]
@ -183,7 +183,7 @@ impl Default for Cursor {
} }
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct EditorCursor { pub struct EditorCursor {
/// Move cursor left. /// Move cursor left.
#[serde(default = "default::editor_cursor::left")] #[serde(default = "default::editor_cursor::left")]
@ -226,7 +226,7 @@ impl Default for EditorCursor {
} }
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct EditorAction { pub struct EditorAction {
/// Insert newline. /// Insert newline.
#[serde(default = "default::editor_action::newline")] #[serde(default = "default::editor_action::newline")]
@ -264,7 +264,7 @@ pub struct Editor {
pub action: EditorAction, pub action: EditorAction,
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct TreeCursor { pub struct TreeCursor {
/// Move cursor to above sibling. /// Move cursor to above sibling.
#[serde(default = "default::tree_cursor::to_above_sibling")] #[serde(default = "default::tree_cursor::to_above_sibling")]
@ -307,7 +307,7 @@ impl Default for TreeCursor {
} }
} }
#[derive(Debug, Deserialize, Document, Group)] #[derive(Debug, Deserialize, Document, KeyGroup)]
pub struct TreeAction { pub struct TreeAction {
/// Reply to message (inline if possible). /// Reply to message (inline if possible).
#[serde(default = "default::tree_action::reply")] #[serde(default = "default::tree_action::reply")]

View file

@ -1,12 +1,13 @@
mod input; mod input;
mod keys; mod keys;
pub use cove_macro::Group; pub use cove_macro::KeyGroup;
pub use input::*; pub use input::*;
pub use keys::*; pub use keys::*;
pub trait Group { /// A group of related key bindings.
pub trait KeyGroup {
type Event; type Event;
fn event(&self, input: &mut Input) -> Option<Self::Event>; fn event(&self, input: &mut Input) -> Option<Self::Event>;

View file

@ -49,7 +49,7 @@ pub fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
#( #enum_variants )* #( #enum_variants )*
} }
impl ::cove_input::Group for #struct_ident { impl ::cove_input::KeyGroup for #struct_ident {
type Event = #enum_ident; type Event = #enum_ident;
fn event(&self, input: &mut ::cove_input::Input) -> Option<Self::Event> { fn event(&self, input: &mut ::cove_input::Input) -> Option<Self::Event> {

View file

@ -12,7 +12,7 @@
use syn::{parse_macro_input, DeriveInput}; use syn::{parse_macro_input, DeriveInput};
mod document; mod document;
mod group; mod key_group;
mod util; mod util;
#[proc_macro_derive(Document, attributes(document))] #[proc_macro_derive(Document, attributes(document))]
@ -24,10 +24,10 @@ pub fn derive_document(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
} }
} }
#[proc_macro_derive(Group)] #[proc_macro_derive(KeyGroup)]
pub fn derive_group(input: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn derive_group(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput); let input = parse_macro_input!(input as DeriveInput);
match group::derive_impl(input) { match key_group::derive_impl(input) {
Ok(tokens) => tokens.into(), Ok(tokens) => tokens.into(),
Err(err) => err.into_compile_error().into(), Err(err) => err.into_compile_error().into(),
} }