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