Skip to main content

Terminal

Struct Terminal 

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

What is known about one output stream: whether it is a terminal, whether to write colour, at what depth, and how wide the output is.

A terminal is decided once, for the stream the output goes to, before anything renders. The decision reads an environment lookup passed by the caller, so a test hands it a map and touches no process state.

§Colour

The Colour section of the crate docs states the order and the depth rules.

Implementations§

Source§

impl Terminal

Source

pub fn detect( stream: Stream, mode: ColorMode, options: DetectOptions, env: &dyn Fn(&str) -> Option<String>, ) -> Self

Available on crate feature detect only.

What stream is, reading variables through env.

env returns a variable’s value, or None when it is unset. This method asks the stream each time it is called, so two calls can differ after a resize or a redirect. Use from_probe to state the stream. Needs the detect feature.

Source

pub fn from_process( stream: Stream, mode: ColorMode, options: DetectOptions, ) -> Self

Available on crate feature detect only.

detect reading the process environment. A value that is not valid UTF-8 counts as set, with its invalid bytes replaced. Needs the detect feature.

Source

pub fn from_probe( probe: Probe, mode: ColorMode, options: DetectOptions, env: &dyn Fn(&str) -> Option<String>, ) -> Self

The decision for a stream that probe describes.

This is the whole decision as a function of its arguments. The other constructors call it after they probe a stream.

Source

pub fn at_depth(self, depth: ColorDepth) -> Self

This terminal at depth, when colour is on.

The depth otherwise follows COLORTERM, TERM, and FORCE_COLOR. A terminal with colour off stays off: the mode decides whether to write colour, and this only decides how many colours.

Source

pub fn is_attached(self) -> bool

Whether the stream is attached to a terminal, as opposed to a pipe or a file.

Source

pub fn color(self) -> Option<ColorDepth>

The colour depth, or None when no colour is written.

Source

pub fn width(self) -> Option<u16>

The width to lay out to, in cells and at least 1. It is None when the stream gives none, COLUMNS holds no number from 1 to 65535, and the fallback is off.

Trait Implementations§

Source§

impl Clone for Terminal

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 Copy for Terminal

Source§

impl Debug for Terminal

Source§

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

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

impl Eq for Terminal

Source§

impl PartialEq for Terminal

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 Terminal

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.