use crate::backend::Input;
use crate::cmd::Handover;
use crate::exec::Item;
use crate::msg::Msg;
pub(super) const fn is_urgent(input: &Input) -> bool {
matches!(
input,
Input::KeyPress(_)
| Input::KeyRelease(_)
| Input::MouseClick(_)
| Input::MouseRelease(_)
| Input::MouseWheel(_)
| Input::MouseMotion(_)
| Input::Paste(_)
)
}
pub(super) fn is_suspend_key(input: &Input) -> bool {
matches!(input, Input::KeyPress(key) if *key == "ctrl+z")
}
pub(super) fn input_item<M>(input: Input) -> Item<M> {
let msg = match input {
Input::KeyPress(key) => Msg::KeyPress(key),
Input::KeyRelease(key) => Msg::KeyRelease(key),
Input::MouseClick(mouse) => Msg::MouseClick(mouse),
Input::MouseRelease(mouse) => Msg::MouseRelease(mouse),
Input::MouseWheel(mouse) => Msg::MouseWheel(mouse),
Input::MouseMotion(mouse) => Msg::MouseMotion(mouse),
Input::Paste(text) => Msg::Paste(text),
input => return focus_item(input),
};
Item::Msg(msg)
}
fn focus_item<M>(input: Input) -> Item<M> {
let msg = match input {
Input::PasteStart => Msg::PasteStart,
Input::PasteEnd => Msg::PasteEnd,
Input::Focus => Msg::Focus,
Input::Blur => Msg::Blur,
Input::CursorPosition { x, y } => Msg::CursorPosition { x, y },
Input::KeyboardEnhancements(report) => Msg::KeyboardEnhancements(report),
Input::ModeReport { mode, value } => Msg::ModeReport { mode, value },
input => return colour_item(input),
};
Item::Msg(msg)
}
fn colour_item<M>(input: Input) -> Item<M> {
let msg = match input {
Input::TerminalVersion(name) => Msg::TerminalVersion(name),
Input::ForegroundColor(c) => Msg::ForegroundColor(c),
Input::BackgroundColor(c) => Msg::BackgroundColor(c),
Input::CursorColor(c) => Msg::CursorColor(c),
Input::ColorScheme(scheme) => Msg::ColorScheme(scheme),
Input::Resize(size) => Msg::WindowSize(size),
Input::PixelSize(size) => Msg::PixelSize(size),
Input::CellSize(size) => Msg::CellSize(size),
input => return reply_item(input),
};
Item::Msg(msg)
}
fn reply_item<M>(input: Input) -> Item<M> {
let msg = match input {
Input::Clipboard { content, selection } => Msg::Clipboard { content, selection },
Input::Capability(capability) => Msg::Capability(capability),
Input::PrimaryDeviceAttributes(attrs) => Msg::PrimaryDeviceAttributes(attrs),
Input::SecondaryDeviceAttributes(attrs) => Msg::SecondaryDeviceAttributes(attrs),
Input::TertiaryDeviceAttributes(id) => Msg::TertiaryDeviceAttributes(id),
input => return signal_item(input),
};
Item::Msg(msg)
}
fn signal_item<M>(input: Input) -> Item<M> {
match input {
Input::Interrupt => Item::Interrupt,
Input::Terminate => Item::Quit,
Input::Suspend => Item::Handover(Handover::Suspend),
Input::Continue => Item::Handover(Handover::Continue),
input => input_item(input),
}
}