Smarter buffer drawing

Better handling for some/none
This commit is contained in:
Jarkko Toivanen 2024-08-01 04:12:26 +03:00
parent 4c54639518
commit b3f7321b90
Signed by: jt
GPG key ID: 9151B109B73ECAD5

View file

@ -14,6 +14,11 @@ struct Nuudel {
buffer: String, buffer: String,
} }
#[derive(Default)]
struct Buffer {
lines: Vec<String>,
}
fn main() -> Result<()> { fn main() -> Result<()> {
// Setup panic handling // Setup panic handling
let default_panic = panic::take_hook(); let default_panic = panic::take_hook();
@ -113,12 +118,11 @@ impl Nuudel {
let mut lines = self.buffer.lines(); let mut lines = self.buffer.lines();
while y < terminal::size()?.1-1 { while y < terminal::size()?.1-1 {
stdout.execute(terminal::Clear(terminal::ClearType::CurrentLine))?; stdout.execute(terminal::Clear(terminal::ClearType::CurrentLine))?;
let line = lines.next(); if let Some(line) = lines.next() {
if line.is_none() { write!(stdout, "{}", line)?;
} else {
break; break;
} } stdout.execute(cursor::MoveToNextLine(1))?;
write!(stdout, "{}", line.unwrap())?;
stdout.execute(cursor::MoveToNextLine(1))?;
y += 1; y += 1;
} }
print!("Press Q to quit"); print!("Press Q to quit");