Skip to main content

minus/core/
mod.rs

1use std::collections::VecDeque;
2
3pub mod commands;
4pub mod ev_handler;
5#[cfg(any(feature = "dynamic_output", feature = "static_output"))]
6pub mod init;
7#[cfg(any(feature = "dynamic_output", feature = "static_output"))]
8mod panic_hook;
9pub mod utils;
10
11// Tests must reset this process-global state between pager runs.
12pub static RUNMODE: parking_lot::Mutex<RunMode> = parking_lot::Mutex::new(RunMode::Uninitialized);
13
14use commands::Command;
15
16pub struct CommandQueue(VecDeque<Command>);
17
18impl CommandQueue {
19    pub fn new() -> Self {
20        Self(VecDeque::with_capacity(10))
21    }
22    pub const fn new_zero() -> Self {
23        Self(VecDeque::new())
24    }
25    pub fn is_empty(&self) -> bool {
26        self.0.is_empty()
27    }
28
29    pub fn push_back(&mut self, value: Command) {
30        self.0.push_back(value);
31    }
32
33    pub fn pop_front(&mut self) -> Option<Command> {
34        self.0.pop_front()
35    }
36}
37
38/// Define the modes in which minus can run
39#[derive(Copy, Clone, PartialEq, Eq, Debug)]
40pub enum RunMode {
41    #[cfg(feature = "static_output")]
42    Static,
43    #[cfg(feature = "dynamic_output")]
44    Dynamic,
45    Uninitialized,
46}
47
48impl RunMode {
49    /// Returns whether no pager is running.
50    #[must_use]
51    pub fn is_uninitialized(self) -> bool {
52        self == Self::Uninitialized
53    }
54}