Module conciliator::core
source · Expand description
Core functionality: dealing with buffers of colored terminal output
Text is never written directly to the terminal, it is written into a buffer first, which then get printed.
The buffer is just a simple Vec<u8>
(and a boolean to store whether colors are enabled), implementing Write
and Paint
to allow printing colored text.
Dealing with the buffers is somewhat unidiomatic, so it bears some explanation. Here are four different ways to write the same status message to the terminal:
use std::io::Write;
use conciliator::Conciliator;
let con = conciliator::init();
let hello = "Hello";
con.status("Hello!");
con.status(format_args!("{hello}!"));
write!(con.status(..), "{hello}!").unwrap();
con.status(hello).push("!");
The con.status( … )
method returns a Line
, which:
- contains the status tag (e.g.
[ > ]
) and whatever was passed into it (..
is used to specify “nothing”, seeInitialContent
), - implements
Paint
(and thusWrite
), - automatically appends a newline (
\n
) character when it gets printed (unless overridden withLine::no_newline
),
Finally, to avoid having to explicitly print every Line
, it holds a reference to the Stream
it was obtained from, and the destructor uses this reference to print the buffer to the terminal.
Structs§
- Buffer for colored text
- Wrap a
Buffer
to print it and a newline when dropped - Wrap a
Buffer
to print it without a newline when dropped - Wrapper around a standard output stream (
stdout
orstderr
)
Traits§
- Helper trait for implementing the
Conciliator
- Initial content for a buffer