line struct ha
parent
ef41b94d2d
commit
d1c379c755
@ -0,0 +1,36 @@
|
||||
use crate::{error::Error, stdout_handle};
|
||||
|
||||
use anyhow::Result;
|
||||
use windows::Win32::System::Console;
|
||||
|
||||
pub struct Line {
|
||||
chars: Vec<char>,
|
||||
}
|
||||
|
||||
impl Line {
|
||||
pub fn new() -> Self {
|
||||
Self { chars: Vec::new() }
|
||||
}
|
||||
|
||||
/// adds a character to the end of the line
|
||||
pub fn append(&mut self, c: char) {
|
||||
self.chars.push(c)
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.chars.clear()
|
||||
}
|
||||
|
||||
pub fn print(&self) -> Result<()> {
|
||||
let s: String = self.chars.iter().collect();
|
||||
unsafe {
|
||||
Error::check(Console::WriteConsoleA(
|
||||
stdout_handle()?,
|
||||
s.as_bytes(),
|
||||
None,
|
||||
None,
|
||||
))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue