Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

The real terminal: keys from it, paints to standard output or standard error (SessionOptions::output), through the library SessionOptions::backend names.

Implementations§

Source§

impl Session

Source

pub fn start(options: SessionOptions) -> Result<Session>

Turn on raw mode and the options. Fails, changing nothing, when the terminal cannot do raw mode or another session is alive.

Source

pub fn leave(&mut self) -> Result<()>

Restore the terminal. Also done on drop and on panic.

Source

pub fn options(&self) -> SessionOptions

Source

pub fn kitty_keys(&self) -> bool

Whether keys are read with the kitty keyboard protocol: the terminal has it, the backend reads it, and SessionOptions::legacy_keys is off. Every key is then exact, and with crossterm releases arrive.

Source

pub fn releases_reported(&self) -> Releases

Which key releases arrive as Event::KeyUp: with crossterm and the kitty keyboard protocol, every key’s but the text keys’, or every key’s with SessionOptions::all_keys; every key’s on the Windows console; none otherwise.

Source

pub fn synchronized_output(&self) -> bool

Whether frames are written as synchronized updates: forced by SessionOptions::synchronized_output or RICH_SYNC_OUTPUT, or the terminal answered that it knows mode 2026.

Source

pub fn color_system(&self) -> Option<Option<ColorSystem>>

The colours the backend’s own probe of the terminal found, when it has one (termwiz’s: terminfo and COLORTERM); None to leave it to rich’s detection. Some(None) is no colour.

Trait Implementations§

Source§

impl Backend for Session

Source§

fn waker(&mut self) -> Option<Waker>

The session’s Waker: on Unix the terminal and it are waited on in one poll, on every backend; elsewhere a read looks at it every few milliseconds.

Source§

fn size(&self) -> (u16, u16)

(columns, rows).
Source§

fn read(&mut self, timeout: Option<Duration>) -> Result<Option<Event>>

The next event, or None when timeout passes first. None for timeout waits as long as it takes.
Source§

fn write(&mut self, text: &str) -> Result<()>

Write and flush.
Source§

fn releases_reported(&self) -> Releases

Which key releases the backend reports (see Releases). The default: none.
Source§

fn synchronized_output(&self) -> bool

Whether write_frame writes each frame as one synchronized update. The default: no.
Source§

fn clipboard(&self) -> Result<(), String>

Whether copy reaches a clipboard (#488): Ok when it does, or why not. The default: it does not.
Source§

fn copy(&mut self, text: &str) -> Result<()>

Put text on the clipboard. Only called when clipboard is Ok.
Source§

fn elapsed(&self) -> Duration

Time since the backend started (virtual in the headless driver).
Source§

fn handoff(&mut self, command: &mut Command) -> Result<Option<i32>>

Run command with the terminal as it was before the session, then take the terminal back. Returns the exit code.
Source§

fn alternate_screen(&self) -> bool

Whether the region is the alternate screen (painted from the top).
Source§

fn origin(&self) -> u16

The terminal row an inline region started on, for placing mouse events; 0 when unknown. The alternate screen always starts at 0.
Source§

fn can_suspend(&self) -> bool

Whether Ctrl+Z suspends (a real terminal on Unix), rather than reaching the component as a key.
Source§

fn suspend(&mut self) -> Result<()>

Give the terminal back, stop until the shell continues the process, then take the terminal back. Only called when can_suspend.
Source§

fn take_resumed(&mut self) -> bool

Whether the process was suspended from outside (SIGTSTP) and has continued since the last call: the screen is then the shell’s.
Source§

fn write_frame(&mut self, frame: &str) -> Result<()>

Write a frame the painter made: nothing at all when it is empty, and with synchronized_output between CSI ? 2026 h and CSI ? 2026 l, in the one write.
Source§

fn painted(&mut self, text: &str)

The plain text of a view just painted: the headless driver records it.
Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.