Skip to main content

TerminalInfo

Struct TerminalInfo 

Source
#[non_exhaustive]
pub struct TerminalInfo {
Show 13 fields pub kind: TerminalKind, pub version: Option<String>, pub term_program: Option<String>, pub term_program_version: Option<String>, pub term: Option<String>, pub colorterm: Option<String>, pub raw_name: Option<String>, pub multiplexer: Option<MultiplexerInfo>, pub color: ColorInfo, pub detected_via: Vec<DetectionSource>, pub identifiers: Vec<Identifier>, pub raw_env_subset: BTreeMap<String, String>, pub command_probes: Vec<CommandProbe>,
}
Expand description

Terminal identity, multiplexer metadata, inferred color support, and their evidence.

Obtain this result with detect, detect_from_env, or detect_with_options. An unknown terminal is a valid result, and a known multiplexer does not imply a known terminal application.

§Reading the result

Start with kind, version, and multiplexer. A kind can identify an emulation family rather than an application, and version metadata may be absent even for a known kind.

For unexpected or unknown results, inspect detected_via and identifiers. The raw term_program, term_program_version, term, and colorterm fields preserve the input hints even when they do not affect the result. raw_name is a convenience fallback label, not the detected application’s name.

raw_env_subset contains consulted variables when capture is enabled; command_probes contains attempted commands when probing is enabled. These diagnostics can contain private values. See Diagnostics and privacy and Detection logic.

§Example

let info = detect_terminal::detect();
println!("Terminal: {}", info.kind);
if let Some(version) = &info.version {
    println!("Version: {version}");
}
for source in &info.detected_via {
    println!("Selected using: {source}");
}
// Debug formatting escapes control characters in raw environment values.
println!(
    "Program hint: {:?}; emulation hint: {:?}",
    info.term_program, info.term
);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§kind: TerminalKind

Application or emulation family selected from the available hints.

See Edge cases and likely mismatches when a marker may be inherited or a TERM name is shared by multiple applications.

§version: Option<String>

TERM_PROGRAM_VERSION only when TERM_PROGRAM identified the selected kind.

A fallback match never borrows a version belonging to another application or multiplexer.

§term_program: Option<String>

Raw TERM_PROGRAM, including unknown or empty values.

§term_program_version: Option<String>

Raw TERM_PROGRAM_VERSION, including when its owner is unknown.

§term: Option<String>

Raw TERM describing the emulation environment.

§colorterm: Option<String>

Raw COLORTERM, including unrecognized or empty values. It can be inherited.

§raw_name: Option<String>

Raw TERM_PROGRAM if present, otherwise TERM.

This convenience label can name something different from the selected kind.

§multiplexer: Option<MultiplexerInfo>

One selected multiplexer, independently of the terminal match.

§color: ColorInfo

Color support inferred from the hints, with evidence separate from terminal identity.

§detected_via: Vec<DetectionSource>

Evidence for the terminal match, empty when the kind is unknown.

§identifiers: Vec<Identifier>

Matching environment key/value pairs, empty for unknown or command-derived matches.

§raw_env_subset: BTreeMap<String, String>

Existing variables consulted during detection, when diagnostic capture is enabled.

Absent keys and unrelated variables are omitted. Disabling capture does not redact the other fields in this result. Values may contain session identifiers and paths.

§command_probes: Vec<CommandProbe>

All attempted probes, empty when command execution is disabled or no mux marker matches.

Trait Implementations§

Source§

impl Clone for TerminalInfo

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 TerminalInfo

Source§

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

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

impl Eq for TerminalInfo

Source§

impl PartialEq for TerminalInfo

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 TerminalInfo

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
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> 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.