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,
DrawAppendedText(usize, usize, AppendStyle),
SetUpperMark(usize),
#[cfg(feature = "search")]
FetchSearchQuery,
}
#[non_exhaustive]
#[allow(private_interfaces)]
pub enum Command {
UserInput(InputEvent),
AppendData(String),
SetData(String),
SendMessage(String),
ShowPrompt(bool),
SetPrompt(String),
LineWrapping(bool),
SetLineNumbers(LineNumbers),
FollowOutput(bool),
SetOutputSink(Box<dyn OutputSink>),
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:?})"),
}
}
}