#![warn(missing_docs)]
pub mod caps;
pub mod options;
pub mod probe;
pub mod verbs;
pub mod waker;
#[cfg(unix)]
pub mod unix;
#[cfg_attr(not(windows), allow(dead_code))]
pub(crate) mod win_logic;
#[cfg(windows)]
pub mod windows;
#[cfg(all(unix, test))]
mod tmux_live_tests;
#[cfg(all(unix, test))]
mod rt5_live_tests;
pub use caps::{Capabilities, CapsReply, GraphicsCaps};
pub use options::{EnterOptions, KittyFlags, MouseMode};
pub use probe::{refresh_cell_pixel_size, ActiveProbe};
#[cfg(unix)]
pub use unix::{emergency_restore, have_tty, UnixTerminal};
pub use verbs::{tmux_wrap, CursorStyle, NotifyChannel};
pub use waker::TerminalWaker;
#[cfg(windows)]
pub use windows::{emergency_restore, have_tty, WindowsTerminal};
use crate::base::{Error, PixelSize, Result, Size};
use std::time::Instant;
#[derive(Debug, PartialEq, Eq)]
pub enum TermRead<'a> {
Input(&'a [u8]),
Resize(Size),
Wake,
Idle,
}
pub trait Terminal {
fn enter(&mut self, opts: &EnterOptions) -> Result<()>;
fn leave(&mut self) -> Result<()>;
fn size(&mut self) -> Result<Size>;
fn read(&mut self, deadline: Option<Instant>) -> Result<TermRead<'_>>;
fn write(&mut self, bytes: &[u8]) -> Result<()>;
fn flush(&mut self) -> Result<()>;
fn waker(&self) -> Option<TerminalWaker> {
None
}
fn degraded(&self) -> Option<&'static str> {
None
}
fn cell_pixel_size(&mut self) -> Option<PixelSize> {
None
}
fn is_tty(&self) -> bool {
false
}
fn suspend(&mut self) -> Result<()> {
Err(Error::Unsupported(
"suspend/resume needs unix job control (SIGTSTP) — bind Ctrl+Z \
only on unix, or hide the binding when suspend() errors"
.into(),
))
}
fn set_cursor_style(&mut self, style: CursorStyle) -> Result<()> {
self.write(&verbs::cursor_style_bytes(style))
}
fn set_title(&mut self, title: &str) -> Result<()> {
self.write(&verbs::set_title_bytes(title))
}
fn clipboard_copy(&mut self, text: &str) -> Result<()> {
self.write(&verbs::clipboard_copy_bytes(text))
}
fn set_mouse_reporting(&mut self, on: bool) -> Result<()> {
let _ = on;
Err(Error::Unsupported(
"set_mouse_reporting needs a terminal that tracks its entered mouse \
mode (the platform backends and testing::CaptureTerm do; this \
scripted terminal does not)"
.into(),
))
}
fn set_pixel_mouse(&mut self, on: bool) -> Result<()> {
self.write(if on {
verbs::PIXEL_MOUSE_ON
} else {
verbs::PIXEL_MOUSE_OFF
})
}
fn bell(&mut self) -> Result<()> {
self.write(verbs::BELL)
}
fn notify(&mut self, message: &str, channel: NotifyChannel) -> Result<()> {
match channel {
NotifyChannel::Osc9 => self.write(&verbs::notify_bytes(message)),
NotifyChannel::Osc99 => self.write(&verbs::notify_bytes_osc99(message)),
NotifyChannel::BellOnly => self.bell(),
}
}
}