1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use crate::com::send::{sendc, sendstr};
impl super::Console {
/// Print to the extern console.
///
/// To guarantee that the console is flushed one may call the
/// the flush function when done printing.
///
/// ## Examples
///
/// ```rust
/// use pipedconsole::Console;
/// # fn main() -> Result<(), pipedconsole::Error> {
/// let my_console = Console::new()?;
///
/// // Produces "Hello world!" as an output.
/// my_console.print("Hello ")?;
/// my_console.print("world!")?;
/// my_console.flush()?;
/// # Ok(())
/// # }
/// ```
pub fn print<T: ToString>(&self, message: T) -> Result<usize, crate::Error> {
unsafe { sendc(self.pipe, 2)? };
let written = unsafe { sendstr(self.pipe, message.to_string())? };
Ok(written as usize)
}
}