Smarter buffer drawing
Better handling for some/none
This commit is contained in:
parent
4c54639518
commit
b3f7321b90
1 changed files with 9 additions and 5 deletions
14
src/main.rs
14
src/main.rs
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue