[][src]Macro mortal::term_write

macro_rules! term_write {
    ( $term:expr , $first:tt $($rest:tt)* ) => { ... };
    ( @_INTERNAL main: $term:expr ; $result:expr ; ) => { ... };
    ( @_INTERNAL main: $term:expr ; $result:expr ; [ $($tt:tt)* ] $($rest:tt)* ) => { ... };
    ( @_INTERNAL main: $term:expr ; $result:expr ; ( $($tt:tt)* ) $($rest:tt)* ) => { ... };
    ( @_INTERNAL main: $term:expr ; $result:expr ; $tt:tt $($rest:tt)* ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; black ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; blue ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; cyan ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; green ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; magenta ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; red ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; white ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; yellow ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # black ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # blue ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # cyan ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # green ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # magenta ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # red ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # white ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; # yellow ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; bold ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; italic ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; reverse ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; underline ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! bold ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! italic ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! reverse ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! underline ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; reset ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! fg ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! bg ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; ! style ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; fg = $e:expr ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; bg = $e:expr ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; style = $e:expr ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; style += $e:expr ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; style -= $e:expr ) => { ... };
    ( @_INTERNAL style: $term:expr ; $result:expr ; theme = $e:expr ) => { ... };
    ( @_INTERNAL format: $term:expr ; $result:expr ; : $e:expr ) => { ... };
    ( @_INTERNAL format: $term:expr ; $result:expr ; ? $e:expr ) => { ... };
    ( @_INTERNAL format: $term:expr ; $result:expr ; $($tt:tt)* ) => { ... };
    ( @_INTERNAL literal: $term:expr ; $result:expr ; $lit:tt ) => { ... };
}

Writes attributes and formatted text to a Terminal or Screen.

Usage

term_write! accepts a series of attribute elements and formatted text elements.

term_writeln! is equivalent, but writes a newline character to the end of the formatted text.

Attribute elements are enclosed in square brackets and take one of the following forms:

ElementEquivalent
[red]term.set_fg(Color::Red)
[#blue]term.set_bg(Color::Blue)
[bold]term.add_style(Style::BOLD)
[!bold]term.remove_style(Style::BOLD)
[reset]term.clear_attributes()
[!fg]term.set_fg(None)
[!bg]term.set_bg(None)
[!style]term.set_style(None)
[fg=expr]term.set_fg(expr)
[bg=expr]term.set_bg(expr)
[style=expr]term.set_style(expr)
[style+=expr]term.add_style(expr)
[style-=expr]term.remove_style(expr)
[theme=expr]term.set_theme(expr)

Formatted text elements are enclosed in parentheses and use Rust std::fmt functions to write formatted text to the terminal. Additionally, a bare string literal may be given and will be written directly to the terminal.

ElementEquivalent
(: expr)write!(term, "{}", expr)
(? expr)write!(term, "{:?}", expr)
("format", ...)write!(term, "format", ...)
"literal str"term.write_str("literal str")

Examples

#[macro_use] extern crate mortal;
use mortal::{Color, Style, Theme, Terminal};

let term = Terminal::new()?;

term_writeln!(term, [red] "red text" [reset])?;

let color = Color::Green;
term_writeln!(term, [fg=color] "green text" [reset])?;

let style = Style::BOLD;
term_writeln!(term, [style=style] "bold text" [reset])?;

let value = 42;
term_writeln!(term, "The answer is: " [bold] (: value) [reset])?;

let theme = Theme::new(color, None, style);
term_writeln!(term, [theme=theme] "Green, bold text" [reset])?;