Skip to main content

Capabilities

Struct Capabilities 

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

What the terminal told us about itself.

This holds the replies themselves, not a summary of them: the ModeSetting reported for every mode that was asked about, the raw device-attribute lists, the reported colors, and so on. A reply that says “I do not recognize that” is recorded too, so None from an accessor generally means the terminal never answered, which is different from answering no. termcap is the exception, folding both into None; use termcap_reports to separate them.

Capability values are what the terminal reported, not what the facade told it. The two are easy to confuse where both exist: a background_color recorded here stays the terminal’s own default even after set_background_color overrides it.

Capability values come from replies, so questions the environment can also answer are deliberately absent. Direct-color support is the example: COLORTERM and TERM establish it as readily as an XTGETTCAP reply does. The answer is Screen::color_profile, which folds in both, and what remains here is the reply itself via supports_termcap.

The application owns this record. Probe::query_capabilities sends the queries and returns a record for that batch. The record also keeps the modes queried by the probe. Pass events from your own read loop, sync or async, to record. The record keeps each core reply about the terminal. The application detects the final Primary DA event, then calls apply_defaults to act on the record.

The record accepts every reply that describes the terminal, whichever way the question was put. An individual request_* method fills a single entry, and a few reports arrive unprompted once their mode is on, such as a color-scheme change under DEC mode 2031. A Default record has no pending measurement, so it collects identified replies.

Implementations§

Source§

impl Capabilities

Source

pub fn record(&mut self, event: &Event)

Update the core results from event.

The event is only read, so your loop still handles it as usual. Pass each relevant event once, in arrival order. The application owns the deadline and detects Primary DA. Pass Primary DA here before ending initial collection so it closes the pending width measurement.

Cursor and Primary DA replies carry no request ID. The record takes the first cursor report routed here as the pending width measurement. The caller routes cursor reports according to its query order. See Probe::query_capabilities for the request order that this needs.

Keep calling this after the batch is complete to record late replies, mid-session request_* replies, and unprompted reports. A DECRPSS Event::SettingReport is not recorded: it does not say which setting it answers, so match it against your own DECRQSS request.

Source

pub fn eaw_width(&self) -> Option<u8>

Measured East Asian Ambiguous width: one or two terminal columns.

None means the probe has not returned a valid width. Probe::query_capabilities measures U+2026 (HORIZONTAL ELLIPSIS) when selected. Program::apply_defaults applies the result to Screen::set_ambiguous_wide.

Source

pub fn queried_modes(&self) -> &[Mode]

Modes queried by the probe that created this record, in request order.

This list includes duplicates and contains only this probe’s mode queries. Apple Terminal skips the probe’s mode queries, so its list is empty. A default record has an empty list. Recording later replies does not change this list.

Source

pub fn mode(&self, mode: Mode) -> Option<ModeSetting>

The ModeSetting the terminal reported for mode, or None if it never reported on that mode.

Use this when the distinction matters: ModeSetting::Set means the mode is currently on, ModeSetting::PermanentlySet means it cannot be turned off, and ModeSetting::NotRecognized is a definite “no” rather than silence.

Source

pub fn supports(&self, mode: Mode) -> bool

Whether the terminal reported mode as available, in any state.

ⓘ
use uncurses::ansi::mode::Mode;

if caps.supports(Mode::MOUSE_SGR_PIXEL) {
    // pixel-accurate mouse reporting is available
}
Source

pub fn modes(&self) -> &BTreeMap<Mode, ModeSetting>

Every mode report recorded so far, keyed by mode.

Source

pub fn primary_device_attributes(&self) -> Option<&[Option<u32>]>

The raw Primary DA (CSI c) attribute list, or None if the terminal never answered. Entries are None where the terminal sent an empty parameter.

The first parameter is the terminal’s architectural service class, not a capability: 6 identifies a VT102 and 64 a VT420. Capability numbers live in the parameters after it in modern replies. VT100-style replies use different meanings for those parameters. Modern terminals may also report extensions with class 61.

The capability numbers are assigned by DEC and extended by terminal authors, so they are reported unparsed.

Source

pub fn clipboard_write(&self) -> bool

Whether a Primary DA reply with class 61 or greater reports OSC 52 writes.

This reports the clipboard extension for the system clipboard or an empty selector. It does not confirm clipboard reads. false means support is unconfirmed.

Source

pub fn secondary_device_attributes(&self) -> Option<&[Option<u32>]>

The raw Secondary DA (CSI > c) attribute list, or None if the terminal never answered. Conventionally terminal type, firmware version, and hardware option, but the meaning of each entry varies by terminal, so it is reported unparsed.

Source

pub fn tertiary_device_attributes(&self) -> Option<&str>

The Tertiary DA (CSI = c) terminal unit ID, or None if the terminal never answered.

Source

pub fn program_status(&self) -> Option<&ProgramStatusCapabilities>

Accepted OSC 7501 states and kinds, or None before a reply.

None means support remains unconfirmed. A reply confirms support even when both lists are empty. The decoder supplies fixed defaults for absent fields and preserves names from protocol extensions.

Send a query with Program::request_program_status.

Source

pub fn kitty_keyboard(&self) -> Option<KittyKeyboardFlags>

The Kitty keyboard enhancements the terminal reported, or None if it never answered CSI ? u. An answer of empty means the protocol is supported with no enhancements currently active.

Source

pub fn modify_other_keys(&self) -> Option<ModifyOtherKeysMode>

The xterm modifyOtherKeys mode the terminal reported, or None if it never answered CSI ? 4 m.

Source

pub fn terminal_name(&self) -> Option<&str>

The terminal’s self-reported name from XTVERSION (for example "XTerm(380)"), or None if it never answered.

Source

pub fn termcap(&self, name: &str) -> Option<&str>

The value the terminal reported for the XTGETTCAP capability name, or None if it reported the capability as unsupported or was never asked. Boolean capabilities report an empty string, so use supports_termcap to test for presence.

Source

pub fn supports_termcap(&self, name: &str) -> bool

Whether the terminal reported the XTGETTCAP capability name as supported. false both for a capability reported unsupported and for one never asked about; tell them apart with termcap_reports.

Source

pub fn termcap_reports(&self) -> &BTreeMap<String, Option<String>>

Every XTGETTCAP reply recorded so far, keyed by capability name. A value of None is the terminal reporting that capability as unsupported, which is different from the key being absent.

Source

pub fn foreground_color(&self) -> Option<Color>

The terminal’s default foreground color (OSC 10), or None if it never answered.

Source

pub fn background_color(&self) -> Option<Color>

The terminal’s default background color (OSC 11), or None if it never answered.

Source

pub fn cursor_color(&self) -> Option<Color>

The terminal’s cursor color (OSC 12), or None if it never answered.

Source

pub fn palette_color(&self, index: u8) -> Option<Color>

The color the terminal reported for palette entry index (OSC 4 ; index ; ?), or None if it never answered for that entry.

Source

pub fn palette(&self) -> &BTreeMap<u8, Color>

Every palette color reported so far, keyed by index.

Source

pub fn color_scheme(&self) -> Option<ColorScheme>

Whether the terminal is in its dark or light scheme (DEC mode 2031), or None if it never reported one. Updated as the scheme changes while enable_color_scheme_updates is on. This is the terminal’s own preference flag, which a terminal can report independently of the colors it uses; when it is absent, background_color is the fallback.

Trait Implementations§

Source§

impl Clone for Capabilities

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Capabilities

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Capabilities

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Capabilities

Source§

impl PartialEq for Capabilities

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Capabilities

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.