pub struct Term {
pub width: usize,
pub color: bool,
pub stream: Stream,
pub interactive: bool,
}Expand description
What the output looks like: layout width, colour and destination.
Construct it once per run with Term::stdout, Term::stderr or Term::stderr_forced
and pass it to every renderer. Tests use Term::plain and Term::ansi, which never touch
the real terminal.
Fields§
§width: usizeColumns available for layout; panels span exactly this many.
color: boolWhether renderers should emit ANSI colour and text attributes.
stream: StreamWhere print_lines writes.
interactive: boolWhether standard output is a terminal, so screen control such as clear_screen is
allowed.
Implementations§
Source§impl Term
impl Term
Sourcepub const MIN_WIDTH: usize = 40
pub const MIN_WIDTH: usize = 40
Narrowest layout width ever used, however small the terminal reports itself.
Sourcepub const FALLBACK_WIDTH: usize = 80
pub const FALLBACK_WIDTH: usize = 80
Layout width when no terminal size is available (output is piped, for example).
Sourcepub fn stdout() -> Self
pub fn stdout() -> Self
A terminal for standard output.
The width is that of the terminal (falling back to Self::FALLBACK_WIDTH, never below
Self::MIN_WIDTH). Colour follows anstream’s auto-detection: on for a terminal,
off when NO_COLOR is set, CLICOLOR=0 or TERM=dumb, and off when output is redirected
(unless CLICOLOR_FORCE is set).
Sourcepub fn stderr() -> Self
pub fn stderr() -> Self
A terminal for standard error with colour auto-detected from stderr itself.
Sourcepub fn stderr_forced() -> Self
pub fn stderr_forced() -> Self
A terminal for standard error whose output is replayed to the terminal later.
The shell wrapper captures stderr into a file and prints it when the command ends, so
stderr itself is not a terminal and auto-detection would turn colour off. Colour is
forced on here unless a terminal that is attached says no: when stdout (or else stderr)
is a terminal, its auto-detection decides, which honours NO_COLOR, CLICOLOR=0 and
TERM=dumb.
Sourcepub fn plain(width: usize) -> Self
pub fn plain(width: usize) -> Self
A colourless terminal of the given width that is never interactive.
Rendered output contains no escape sequences at all. Meant for tests and for output that is known to be consumed by a program.
Sourcepub fn ansi(width: usize) -> Self
pub fn ansi(width: usize) -> Self
Like Term::plain but with colour on, for testing ANSI output.
Sourcepub fn with_width(self, width: usize) -> Self
pub fn with_width(self, width: usize) -> Self
The same terminal with a different layout width, for content that is rendered inside
a container (see Panel::body_width).
Sourcepub fn paint(&self, style: Style, text: &str) -> String
pub fn paint(&self, style: Style, text: &str) -> String
text in style when colour is on, otherwise unchanged. The result is self-contained.
use shellgame::ui::{Term, style};
assert_eq!(Term::plain(80).paint(style::BOLD, "x"), "x");
assert_eq!(Term::ansi(80).paint(style::BOLD, "x"), "\x1b[1mx\x1b[0m");Sourcepub fn paint_lines(&self, style: Style, lines: &[String]) -> Vec<String>
pub fn paint_lines(&self, style: Style, lines: &[String]) -> Vec<String>
Applies Term::paint to every line.
Trait Implementations§
impl Copy for Term
impl Eq for Term
impl StructuralPartialEq for Term
Auto Trait Implementations§
impl Freeze for Term
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnsafeUnpin for Term
impl UnwindSafe for Term
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.