• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wllfaria / glyph / 16432406946

22 Jul 2025 01:43AM UTC coverage: 11.519% (-0.8%) from 12.321%
16432406946

push

github

wllfaria
command handler draft

0 of 55 new or added lines in 7 files covered. (0.0%)

1 existing line in 1 file now uncovered.

69 of 599 relevant lines covered (11.52%)

3.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/glyph-core/src/command_handler/mod.rs
1
pub mod buffer_command_handler;
2

3
use std::collections::{BTreeMap, VecDeque};
4
use std::fmt::Debug;
5

6
use crate::buffer_manager::{Buffer, BufferId};
7
use crate::key_mapper::Command;
8
use crate::view_manager::{View, ViewManager};
9

10
pub enum CommandHandlerResult {
11
    Consumed,
12
    NotConsumed,
13
}
14

15
pub struct CommandContext<'ctx> {
16
    pub commands: &'ctx [Command],
17
    pub buffers: &'ctx mut BTreeMap<BufferId, Buffer>,
18
    pub views: &'ctx mut ViewManager,
19
    pub should_quit: &'ctx mut bool,
20
}
21

22
pub trait CommandHandler: Debug {
23
    fn handle_commands(&mut self, ctx: &mut CommandContext<'_>) -> CommandHandlerResult;
24
}
25

26
#[derive(Debug, Default)]
27
pub struct CommandHandlerChain {
28
    handlers: VecDeque<Box<dyn CommandHandler>>,
29
}
30

31
impl CommandHandlerChain {
NEW
32
    pub fn new() -> Self {
×
33
        Self {
NEW
34
            handlers: VecDeque::new(),
×
35
        }
36
    }
37

NEW
38
    pub fn add_handler<H>(&mut self, handler: H)
×
39
    where
40
        H: CommandHandler + 'static,
41
    {
NEW
42
        self.handlers.push_front(Box::new(handler));
×
43
    }
44
}
45

46
impl CommandHandler for CommandHandlerChain {
NEW
47
    fn handle_commands(&mut self, ctx: &mut CommandContext<'_>) -> CommandHandlerResult {
×
NEW
48
        for handler in self.handlers.iter_mut() {
×
NEW
49
            if let CommandHandlerResult::Consumed = handler.handle_commands(ctx) {
×
NEW
50
                return CommandHandlerResult::Consumed;
×
51
            }
52
        }
53

NEW
54
        CommandHandlerResult::NotConsumed
×
55
    }
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc