Skip to main content

Env

Struct Env 

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

Everything widgets need to know about how to draw and label themselves.

Implementations§

Source§

impl Env

Source

pub fn builtin() -> Self

Built-in files only, the monochrome theme, Unicode glyphs, English and 24-bit colour. Deterministic, which makes it the environment for tests.

Source

pub fn load(dirs: &AssetDirs) -> Result<Self>

Loads the application’s files over the built-ins and detects colour depth, glyphs, language and the kind of connection from the process environment.

§Errors

Returns an I/O error when a configured directory or file cannot be read and no text was given for that kind of file; with text given, an unreadable path is a diagnostic and the text stands in for it. Problems inside files are never errors; they are collected in Env::diagnostics.

Source

pub fn load_with( dirs: &AssetDirs, lookup: impl Fn(&str) -> Option<String>, ) -> Result<Self>

Loads the application’s files like load, reading the variables it would read from the process environment (LANG, LC_ALL, LC_TIME, TERM, COLORTERM, SSH_CONNECTION and the rest) through lookup instead.

For a test that runs an application with its real files: the machine’s language and region would otherwise reach it, so the first day of the week, a number’s decimal mark or the language itself would change from one machine to the next. |_| None is a machine with nothing set. Unlike load, the operating system’s own language setting is never asked: only lookup answers.

§Errors

As for load.

Source

pub fn theme(&self) -> &Theme

The active theme.

Source

pub fn themes(&self) -> Vec<(String, String)>

(id, name) of every theme.

Source

pub fn icon_sets(&self) -> Vec<(String, String)>

(id, name) of every icon set, the way Env::themes lists the themes. A theme names the set it draws with, so this tells which sets a theme may name.

Source

pub fn icons(&self) -> &Icons

The icons in the active glyph mode.

Source

pub fn icon_mode(&self) -> IconMode

The chosen icon mode.

Source

pub fn glyph_mode(&self) -> GlyphMode

The glyph column actually drawn.

Source

pub fn i18n(&self) -> &I18n

The translator.

Source

pub fn keymap(&self) -> &Keymap

The keymap.

Source

pub fn keymap_mut(&mut self) -> &mut Keymap

The keymap, to bind actions in code, e.g. before handing the environment to a Harness.

Source

pub fn depth(&self) -> ColorDepth

The terminal’s colour depth.

Source

pub fn remote(&self) -> bool

Whether the terminal is at the other end of a remote connection, so every drawn frame travels over a network.

True when SSH_CONNECTION or SSH_TTY is set and not empty, which is how an SSH server marks the session it started; an empty value counts as unset, the way an empty variable left over from another program does. Detected once by Env::load, so it cannot change under a running application; Env::builtin, the environment of tests, is never remote until Harness::set_remote says so.

The runtime already uses it for the FrameLimit an application does not set. An application reads it to spend less on a slow link: fewer animations, smaller pictures, a plainer screen.

Source

pub fn remote_session() -> bool

Whether this process runs in a remote session, by the rule Env::remote uses, without loading an environment.

It reads SSH_CONNECTION and SSH_TTY and nothing else, so it costs no file reads. An application calls it before Runtime::run, where no Env is handed out yet, to choose what depends on the connection between frames, such as the size a picture is decoded at. In a view, Env::remote gives the same answer, and Harness::set_remote sets it in a test.

Source

pub fn graphics(&self) -> Graphics

The way a picture can be drawn in this terminal.

The runtime asks the terminal once, as it starts: a kitty graphics query and a request for its device attributes, with a wait of 150 ms at most that the attributes end, so a local terminal answers in milliseconds and starting never waits on the network. A kitty OK gives Graphics::Kitty, attributes that list sixel give Graphics::Sixel, and anything else, silence included, gives Graphics::HalfBlock. A kitty OK that arrives after the wait, over a very slow link, still gives Graphics::Kitty from then on. The answers never reach the application as keys. The terminal is not asked when its answer could not change the result, and never when it is not a terminal.

Then the environment has its say:

  • 16 colours or ASCII glyphs give Graphics::None: no picture is drawn.
  • Inside tmux or GNU screen (TMUX or STY set and not empty) kitty and sixel become half blocks, because the multiplexer does not pass them through.
  • The QUVYTA_GRAPHICS environment variable, set to kitty, sixel, halfblock or none, wins over all of it, for a terminal the probe misjudges or a person who wants something else. Any other value is ignored and becomes a diagnostic.

Env::builtin, the environment of tests, asks nothing and gives half blocks; see Harness::set_graphics for the others.

Source

pub fn reduced_motion(&self) -> bool

Whether animations are reduced: layers appear at once, nothing breathes or spins.

The QUVYTA_REDUCED_MOTION environment variable, read by Env::load, decides when it is set: 0 keeps motion, any other non-empty value reduces it. It wins over a saved reduced-motion setting and over Command::set_reduced_motion, because a choice made in the user’s shell is the stronger signal, the way accessibility overrides work. Unset or empty, the saved setting and the application decide.

Source

pub fn reduced_motion_forced(&self) -> bool

Whether the QUVYTA_REDUCED_MOTION environment variable decides reduced motion, so neither a saved setting nor Command::set_reduced_motion can change it. A settings screen uses it to show its reduced-motion switch as decided by the environment instead of letting the switch snap back when pressed.

Source

pub fn pillar_style(&self) -> Option<PillarStyle>

The pillar the user chose over the theme’s, if any.

Source

pub fn slide(&self) -> bool

Whether list structures (lists, menus, trees, tables, tab strips and rails, dropdown options) slide the leading text of hovered and selected rows one cell; buttons and fields never do. The user’s choice when made, otherwise the theme’s motion.slide.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Problems found in theme, icon, locale and keymap files, including theme switches that fell back to the default.

Trait Implementations§

Source§

impl Clone for Env

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 Env

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Env

§

impl RefUnwindSafe for Env

§

impl Send for Env

§

impl Sync for Env

§

impl Unpin for Env

§

impl UnsafeUnpin for Env

§

impl UnwindSafe for Env

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> 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 = !

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.