pub trait Terminal: Write {
type Output: Write;
Show 13 methods
// Required methods
fn fg(&mut self, color: Color) -> Result<()>;
fn bg(&mut self, color: Color) -> Result<()>;
fn attr(&mut self, attr: Attr) -> Result<()>;
fn supports_attr(&self, attr: Attr) -> bool;
fn reset(&mut self) -> Result<()>;
fn supports_reset(&self) -> bool;
fn supports_color(&self) -> bool;
fn cursor_up(&mut self) -> Result<()>;
fn delete_line(&mut self) -> Result<()>;
fn carriage_return(&mut self) -> Result<()>;
fn get_ref(&self) -> &Self::Output;
fn get_mut(&mut self) -> &mut Self::Output;
fn into_inner(self) -> Self::Output
where Self: Sized;
}
Expand description
A terminal with similar capabilities to an ANSI Terminal (foreground/background colors etc).
Required Associated Types§
Required Methods§
sourcefn fg(&mut self, color: Color) -> Result<()>
fn fg(&mut self, color: Color) -> Result<()>
Sets the foreground color to the given color.
If the color is a bright color, but the terminal only supports 8 colors, the corresponding normal color will be used instead.
Returns Ok(())
if the color change code was sent to the terminal, or Err(e)
if there
was an error.
sourcefn bg(&mut self, color: Color) -> Result<()>
fn bg(&mut self, color: Color) -> Result<()>
Sets the background color to the given color.
If the color is a bright color, but the terminal only supports 8 colors, the corresponding normal color will be used instead.
Returns Ok(())
if the color change code was sent to the terminal, or Err(e)
if there
was an error.
sourcefn attr(&mut self, attr: Attr) -> Result<()>
fn attr(&mut self, attr: Attr) -> Result<()>
Sets the given terminal attribute, if supported. Returns Ok(())
if the attribute is
supported and was sent to the terminal, or Err(e)
if there was an error or the attribute
wasn’t supported.
sourcefn supports_attr(&self, attr: Attr) -> bool
fn supports_attr(&self, attr: Attr) -> bool
Returns whether the given terminal attribute is supported.
sourcefn reset(&mut self) -> Result<()>
fn reset(&mut self) -> Result<()>
Resets all terminal attributes and colors to their defaults.
Returns Ok(())
if the reset code was printed, or Err(e)
if there was an error.
Note: This does not flush.
That means the reset command may get buffered so, if you aren’t planning on doing anything else that might flush stdout’s buffer (e.g. writing a line of text), you should flush after calling reset.
sourcefn supports_reset(&self) -> bool
fn supports_reset(&self) -> bool
Returns true if reset is supported.
sourcefn supports_color(&self) -> bool
fn supports_color(&self) -> bool
Returns true if color is fully supported.
If this function returns true
, bg
, fg
, and reset
will never
return Err(Error::NotSupported)
.
sourcefn cursor_up(&mut self) -> Result<()>
fn cursor_up(&mut self) -> Result<()>
Moves the cursor up one line.
Returns Ok(())
if the cursor movement code was printed, or Err(e)
if there was an
error.
sourcefn delete_line(&mut self) -> Result<()>
fn delete_line(&mut self) -> Result<()>
Deletes the text from the cursor location to the end of the line.
Returns Ok(())
if the deletion code was printed, or Err(e)
if there was an error.
sourcefn carriage_return(&mut self) -> Result<()>
fn carriage_return(&mut self) -> Result<()>
Moves the cursor to the left edge of the current line.
Returns Ok(true)
if the deletion code was printed, or Err(e)
if there was an error.
sourcefn into_inner(self) -> Self::Outputwhere
Self: Sized,
fn into_inner(self) -> Self::Outputwhere
Self: Sized,
Returns the contained stream, destroying the Terminal