TerminalMode

Enum TerminalMode 

Source
pub enum TerminalMode {
    Full,
    Basic,
    None,
}
Expand description

Terminal capability mode for streaming output.

Determines what level of ANSI escape sequences are appropriate for the current output destination.

Variants§

§

Full

Full ANSI support: cursor positioning, colors, all escapes

Used when stdout is a TTY with capable terminal (xterm, vt100, etc.)

§

Basic

Basic TTY: colors without cursor positioning

Used when:

  • TERM=dumb (basic terminal with color support)
  • Terminal type is unknown but TTY is detected
§

None

Non-TTY output: no ANSI sequences

Used when:

  • Output is piped (ralph | tee log.txt)
  • Output is redirected (ralph > output.txt)
  • CI environment (no TTY detected)
  • NO_COLOR=1 is set

Implementations§

Source§

impl TerminalMode

Source

pub fn detect() -> Self

Detect the current terminal mode from environment.

This checks:

  1. NO_COLOR environment variable (respects user preference)
  2. CLICOLOR_FORCE (forces colors even in non-TTY)
  3. CLICOLOR (macOS color disable)
  4. TERM environment variable for capability detection
  5. Whether stdout is a terminal using IsTerminal trait
§Environment Variables
  • NO_COLOR=1: Disables all ANSI output
  • NO_COLOR=0 or unset: No effect
  • CLICOLOR_FORCE=1: Forces colors even in non-TTY
  • CLICOLOR_FORCE=0 or unset: No effect
  • CLICOLOR=0: Disables colors on macOS
  • CLICOLOR=1 or unset: No effect on macOS
  • TERM=xterm-256color: Full ANSI support
  • TERM=dumb: Basic TTY with colors but no cursor positioning
  • TERM=vt100, TERM=screen: Full ANSI support
§Returns
  • Full: stdout is TTY with capable terminal
  • Basic: stdout is TTY but terminal is basic or TERM is unknown
  • None: stdout is not a TTY or colors are disabled
§Examples
use ralph::json_parser::TerminalMode;

let mode = TerminalMode::detect();
match mode {
    TerminalMode::Full => println!("Full terminal support"),
    TerminalMode::Basic => println!("Basic terminal (colors only)"),
    TerminalMode::None => println!("Non-TTY output"),
}

Trait Implementations§

Source§

impl Clone for TerminalMode

Source§

fn clone(&self) -> TerminalMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TerminalMode

Source§

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

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

impl Default for TerminalMode

Source§

fn default() -> Self

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

impl PartialEq for TerminalMode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TerminalMode

Source§

impl Eq for TerminalMode

Source§

impl StructuralPartialEq for TerminalMode

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

Checks if this value is equivalent to the given key. 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.