Struct calypso_base::ui::Emitter
source · pub struct Emitter {
writer: BufferWriter,
buf: Buffer,
}
Expand description
A structure handling emitting messages to the terminal. This Deref
s and
DerefMut
s to a termcolor::Buffer
, so you can use
termcolor::WriteColor
and methods on Buffer
to write custom text.
Note that text is never automatically flushed, so you must manually use
Emitter::flush
.
Fields§
§writer: BufferWriter
§buf: Buffer
Implementations§
source§impl Emitter
impl Emitter
sourcepub fn new(writer: BufferWriter) -> Self
pub fn new(writer: BufferWriter) -> Self
Create a new emitter.
sourcepub fn buffer(&self) -> Buffer ⓘ
pub fn buffer(&self) -> Buffer ⓘ
Create a new buffer based on the color preferences of this emitter.
sourcepub fn flush(&mut self) -> CalResult<&mut Self>
pub fn flush(&mut self) -> CalResult<&mut Self>
Flush the emitter. This will clear the internal buffer.
Errors
This function will error if the emitter could not print the contents of the internal buffer.
sourcepub fn newline(&mut self) -> CalResult<&mut Self>
pub fn newline(&mut self) -> CalResult<&mut Self>
Add a newline to the internal buffer.
Errors
This function will error if the buffer could not be updated.
sourcepub fn print(&mut self, s: &str) -> CalResult<&mut Self>
pub fn print(&mut self, s: &str) -> CalResult<&mut Self>
Add the string provided to the internal buffer verbatim. (Chainable)
Errors
This function will error if the buffer could not be updated.
sourcepub fn error(
&mut self,
code: Option<&str>,
short: &str,
message: Option<&str>
) -> CalResult<&mut Self>
pub fn error(
&mut self,
code: Option<&str>,
short: &str,
message: Option<&str>
) -> CalResult<&mut Self>
Emit an error. Note that this function will reset the existing color of the internal buffer. The emitted text will have a newline.
Forms
Angle brackets (<>
) indicate a string provided to the function.
Without code
or message
error: <short>
With code
but not message
error[<code>]: <short>
With message
but not code
error: <short>: <message>
With code
and message
error[<code>]: <short>: <message>
Color
When color is enabled for the output provided, the segments will be colored as such:
error[<code>]
: Red; bold, intense<short>
: White; bold, intense<message>
: Default color
Errors
This function will error if at any point text could not be written to the internal buffer.
fn message_general(
&mut self,
main: &'static str,
color: Color,
short: &str,
message: Option<&str>
) -> CalResult<&mut Self>
sourcepub fn info(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
pub fn info(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
Emit an informational message. Note that this function will reset the existing color of the internal buffer. The emitted text will have a newline.
Forms
Angle brackets (<>
) indicate a string provided to the function.
Without message
info: <short>
With message
info: <short>: <message>
Color
When color is enabled for the output provided, the segments will be colored as such:
info
: Cyan; bold, intense<short>
: White; bold, intense<message>
: Default color
Errors
This function will error if at any point text could not be written to the internal buffer.
sourcepub fn note(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
pub fn note(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
Emit a note. Note that this function will reset the existing color of the internal buffer. The emitted text will have a newline.
Forms
Angle brackets (<>
) indicate a string provided to the function.
Without message
note: <short>
With message
note: <short>: <message>
Color
When color is enabled for the output provided, the segments will be colored as such:
note
: Green; bold, intense<short>
: White; bold, intense<message>
: Default color
Errors
This function will error if at any point text could not be written to the internal buffer.
sourcepub fn warn(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
pub fn warn(&mut self, short: &str, message: Option<&str>) -> CalResult<&mut Self>
Emit a warning. Note that this function will reset the existing color of the internal buffer. The emitted text will have a newline.
Forms
Angle brackets (<>
) indicate a string provided to the function.
Without message
warn: <short>
With message
warn: <short>: <message>
Color
When color is enabled for the output provided, the segments will be colored as such:
warn
: Yellow; bold, intense<short>
: White; bold, intense<message>
: Default color
Errors
This function will error if at any point text could not be written to the internal buffer.
Methods from Deref<Target = Buffer>§
sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Return the underlying data of the buffer as a mutable slice.