Skip to main content

Fidelity

Enum Fidelity 

Source
pub enum Fidelity {
    Ansi16,
    Ansi256,
    TrueColor,
}
Expand description

How many colours the terminal can actually show.

Only Fidelity::Ansi16 changes what this crate draws. Above it, colour separates a raised surface from a well on every shipped theme, and the glyph fallback below never fires. Recorded rather than inferred, because a caller that quantised its palette knows the answer and this crate cannot recover it from the colours afterwards.

Variants§

§

Ansi16

Sixteen colours. Depth cannot be carried by colour: a well collapses onto its face on 18 of 31 themes and a bevel loses an edge on all 31.

§

Ansi256

The 6x6x6 cube and the grey ramp. Enough on 27 of 31 themes.

§

TrueColor

24-bit. The only failures left belong to the theme, not the terminal.

Implementations§

Source§

impl Fidelity

Source

pub fn detect() -> Self

Read the terminal’s own claim, from COLORTERM then TERM.

Deliberately credulous, and the fall-through is where that is decided. An unrecognised TERM is assumed capable, because the two wrong answers do not cost the same: guessing TrueColor on a limited terminal costs some fidelity, and guessing Ansi16 on a capable one throws away colour the user paid for — and, for a caller that quantises its palette off this answer, throws away the whole theme. COLORTERM is routinely stripped by ssh and by multiplexers, so an unrecognised name is the common case rather than the exotic one: foot, xterm and screen all land here.

So sixteen colours is reached by naming the terminals that really have them. The list is short and it does not grow: these are the fixed consoles, and TERM=linux is the case this exists for — the Linux virtual console, which is what an installer and a machine with no desktop draw on.

Source

pub fn from_env(colorterm: &str, term: &str) -> Self

detect with the environment passed in, so the decision can be tested without mutating a process-wide variable from a parallel test.

Source

pub const fn separates_depth(self) -> bool

Whether colour alone can tell a raised surface from a well here.

Trait Implementations§

Source§

impl Clone for Fidelity

Source§

fn clone(&self) -> Fidelity

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 Fidelity

Source§

impl Debug for Fidelity

Source§

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

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

impl Default for Fidelity

Source§

fn default() -> Fidelity

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

impl Eq for Fidelity

Source§

impl PartialEq for Fidelity

Source§

fn eq(&self, other: &Fidelity) -> 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 Fidelity

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.