Crate surf_n_term
source · [−]Expand description
This crate is used to interact with Posix terminal. It can be used to
- Read events from the terminal
- Send commands to the terminal
- Render on a surface which will be reconciled with current content of the terminal
- Issue direct commends to the terminal
- Supports kitty/sixel image protocol
Simple example
use surf_n_term::{Terminal, TerminalEvent, TerminalAction, SystemTerminal, Error};
fn main() -> Result<(), Error> {
let ctrl_c = TerminalEvent::Key("ctrl+c".parse()?);
let mut term = SystemTerminal::new()?;
term.run_render(|term, event, mut view| -> Result<_, Error> {
// This function will be executed on each event from terminal
// - term - implements Terminal trait
// - event - is a TerminalEvent
// - view - is a Surface that can be used to render on, see render module for details
match event {
Some(event) if &event == &ctrl_c => {
// exit if 'ctrl+c' is pressed
Ok(TerminalAction::Quit(()))
}
_ => {
// do some rendering by updating the view
Ok(TerminalAction::Wait)
},
}
})?;
Ok(())
}
Re-exports
pub use error::Error;
pub use face::Face;
pub use face::FaceAttrs;
pub use glyph::Glyph;
pub use image::ColorPalette;
pub use image::Image;
pub use image::ImageHandler;
pub use image::KittyImageHandler;
pub use image::SixelImageHandler;
pub use keys::Key;
pub use keys::KeyMap;
pub use keys::KeyMod;
pub use keys::KeyName;
pub use render::Cell;
pub use render::TerminalSurface;
pub use render::TerminalSurfaceExt;
pub use render::TerminalWriter;
pub use surface::Shape;
pub use surface::Surface;
pub use surface::SurfaceIter;
pub use surface::SurfaceMut;
pub use surface::SurfaceMutIter;
pub use surface::SurfaceMutView;
pub use surface::SurfaceOwned;
pub use surface::SurfaceOwnedView;
pub use surface::SurfaceView;
pub use terminal::DecMode;
pub use terminal::DecModeStatus;
pub use terminal::Position;
pub use terminal::Size;
pub use terminal::Terminal;
pub use terminal::TerminalAction;
pub use terminal::TerminalCaps;
pub use terminal::TerminalColor;
pub use terminal::TerminalCommand;
pub use terminal::TerminalEvent;
pub use terminal::TerminalSize;
pub use terminal::TerminalWaker;
Modules
NFA and DFA
Common utility functions used across different modules
Decoders
Encoders
Error type
Type describing foreground/background/style-attrs of the terminal cell
Handling everything to do with images.
Terminal rendering logic
Surface object
Main interface to interact with terminal
Structs
Bounding box with sides directed along the axes
Alpha premultiplied RGBA color in the linear color space (no gamma correction)
sRGBA color packed as [u8; 4]
Enums
The algorithm to use to determine the inside part of a shape, when filling it.
Traits
Common interface to all color representations
Type Definitions
System specific terminal