-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcommands.rs
More file actions
134 lines (121 loc) · 5.36 KB
/
Copy pathcommands.rs
File metadata and controls
134 lines (121 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! Provides the [`Command`] enum and all its related implementations
//!
//! This module only declares the [Command] type. To know how they are handled internally see
//! the [`ev_handler`](super::ev_handler).
use std::fmt::Debug;
use crate::{
ExitStrategy, LineNumbers, OutputSink,
hooks::{Hook, HookCallback},
input::{InputClassifier, InputEvent},
minus_core::utils::display::AppendStyle,
};
#[cfg(feature = "clipboard")]
use crate::state::ClipboardHandler;
#[cfg(feature = "search")]
use crate::search::SearchOpts;
#[derive(Debug, PartialEq, Eq)]
pub enum IoCommand {
RedrawPrompt,
RedrawDisplay,
/// Append text to the screen
///
/// First item corresponds to the value of unterminated lines before the text is formatted while
/// the second value corresponds to the total number of rows before formatting.
DrawAppendedText(usize, usize, AppendStyle),
SetUpperMark(usize),
#[cfg(feature = "search")]
FetchSearchQuery,
}
/// Different events that can be encountered while the pager is running
#[non_exhaustive]
#[allow(private_interfaces)]
pub enum Command {
// User input
UserInput(InputEvent),
// Data related
AppendData(String),
SetData(String),
// Prompt related
SendMessage(String),
ShowPrompt(bool),
SetPrompt(String),
// Screen output configurations
LineWrapping(bool),
SetLineNumbers(LineNumbers),
FollowOutput(bool),
SetOutputSink(Box<dyn OutputSink>),
// Configuration options
SetExitStrategy(ExitStrategy),
SetInputClassifier(Box<dyn InputClassifier + Send + Sync + 'static>),
#[cfg(feature = "clipboard")]
SetClipboardHandler(ClipboardHandler),
AddExitCallback(Box<dyn FnMut() + Send + Sync + 'static>),
AddHook(Hook, u64, HookCallback),
RemoveHook(Hook, u64),
#[cfg(feature = "static_output")]
SetRunNoOverflow(bool),
#[cfg(feature = "search")]
IncrementalSearchCondition(Box<dyn Fn(&SearchOpts) -> bool + Send + Sync + 'static>),
#[cfg(feature = "search")]
SetSmartCase(bool),
Io(IoCommand),
}
impl PartialEq for Command {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::SetData(d1), Self::SetData(d2))
| (Self::AppendData(d1), Self::AppendData(d2))
| (Self::SetPrompt(d1), Self::SetPrompt(d2))
| (Self::SendMessage(d1), Self::SendMessage(d2)) => d1 == d2,
(Self::LineWrapping(d1), Self::LineWrapping(d2)) => d1 == d2,
(Self::SetLineNumbers(d1), Self::SetLineNumbers(d2)) => d1 == d2,
(Self::ShowPrompt(d1), Self::ShowPrompt(d2)) => d1 == d2,
(Self::SetExitStrategy(d1), Self::SetExitStrategy(d2)) => d1 == d2,
#[cfg(feature = "static_output")]
(Self::SetRunNoOverflow(d1), Self::SetRunNoOverflow(d2)) => d1 == d2,
(Self::SetInputClassifier(_), Self::SetInputClassifier(_))
| (Self::AddExitCallback(_), Self::AddExitCallback(_))
| (Self::AddHook(..), Self::AddHook(..))
| (Self::SetOutputSink(_), Self::SetOutputSink(_)) => true,
#[cfg(feature = "clipboard")]
(Self::SetClipboardHandler(_), Self::SetClipboardHandler(_)) => true,
(Self::RemoveHook(h1, id1), Self::RemoveHook(h2, id2)) => h1 == h2 && id1 == id2,
#[cfg(feature = "search")]
(Self::IncrementalSearchCondition(_), Self::IncrementalSearchCondition(_)) => true,
#[cfg(feature = "search")]
(Self::SetSmartCase(s1), Self::SetSmartCase(s2)) => s1 == s2,
(Self::Io(a), Self::Io(b)) => a == b,
_ => false,
}
}
}
impl Debug for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SetData(text) => write!(f, "SetData({text:?})"),
Self::AppendData(text) => write!(f, "AppendData({text:?})"),
Self::SetPrompt(text) => write!(f, "SetPrompt({text:?})"),
Self::SendMessage(text) => write!(f, "SendMessage({text:?})"),
Self::SetLineNumbers(ln) => write!(f, "SetLineNumbers({ln:?})"),
Self::LineWrapping(lw) => write!(f, "LineWrapping({lw:?})"),
Self::SetExitStrategy(es) => write!(f, "SetExitStrategy({es:?})"),
Self::SetInputClassifier(_) => write!(f, "SetInputClassifier"),
#[cfg(feature = "clipboard")]
Self::SetClipboardHandler(_) => write!(f, "SetClipboardHandler"),
Self::ShowPrompt(show) => write!(f, "ShowPrompt({show:?})"),
#[cfg(feature = "search")]
Self::IncrementalSearchCondition(_) => write!(f, "IncrementalSearchCondition"),
#[cfg(feature = "search")]
Self::SetSmartCase(sc) => write!(f, "SetSmartCase({sc:?})"),
Self::AddExitCallback(_) => write!(f, "AddExitCallback"),
Self::AddHook(h, id, _) => write!(f, "AddHook({h:?}, {id})"),
Self::RemoveHook(h, id) => write!(f, "RemoveHook({h:?}, {id})"),
#[cfg(feature = "static_output")]
Self::SetRunNoOverflow(val) => write!(f, "SetRunNoOverflow({val:?})"),
Self::UserInput(input) => write!(f, "UserInput({input:?})"),
Self::FollowOutput(follow_output) => write!(f, "FollowOutput({follow_output:?})"),
Self::SetOutputSink(_) => write!(f, "SetOutputSink"),
Self::Io(c) => write!(f, "Io({c:?})"),
}
}
}