mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Rename render to surface
This commit is contained in:
parent
7925af1bdc
commit
4a80f06ce6
@ -7,7 +7,7 @@ mod char;
|
|||||||
mod fill;
|
mod fill;
|
||||||
mod vec;
|
mod vec;
|
||||||
mod array;
|
mod array;
|
||||||
mod render;
|
mod surface;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")]
|
#[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")]
|
||||||
|
@ -6,16 +6,16 @@ use crossterm::terminal::{Clear, ClearType};
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use crate::array::Array2D;
|
use crate::array::Array2D;
|
||||||
|
|
||||||
pub trait Renderer {
|
pub trait Surface {
|
||||||
fn width(&self) -> usize;
|
fn width(&self) -> usize;
|
||||||
fn height(&self) -> usize;
|
fn height(&self) -> usize;
|
||||||
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
||||||
fn clear(&mut self, x: usize, y: usize);
|
fn clear(&mut self, x: usize, y: usize);
|
||||||
fn render(&mut self) -> Result<(), Error>;
|
fn present(&mut self) -> Result<(), Error>;
|
||||||
fn purge(&mut self) -> Result<(), Error>;
|
fn purge(&mut self) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WriteRenderer<T> {
|
pub struct WriteSurface<T> {
|
||||||
out: T,
|
out: T,
|
||||||
array: Array2D<Cell>,
|
array: Array2D<Cell>,
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ impl Default for Cell {
|
|||||||
fn default() -> Self { Cell::Keep }
|
fn default() -> Self { Cell::Keep }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> WriteRenderer<T> {
|
impl<T> WriteSurface<T> {
|
||||||
pub fn new(out: T, width: usize, height: usize) -> Self {
|
pub fn new(out: T, width: usize, height: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
out,
|
out,
|
||||||
@ -40,7 +40,7 @@ impl<T> WriteRenderer<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Write> Renderer for WriteRenderer<T> {
|
impl<T: Write> Surface for WriteSurface<T> {
|
||||||
fn width(&self) -> usize {
|
fn width(&self) -> usize {
|
||||||
self.array.width()
|
self.array.width()
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ impl<T: Write> Renderer for WriteRenderer<T> {
|
|||||||
self.array[(x, y)] = Cell::Draw { char: ' ', color: Color::Reset };
|
self.array[(x, y)] = Cell::Draw { char: ' ', color: Color::Reset };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self) -> Result<(), Error> {
|
fn present(&mut self) -> Result<(), Error> {
|
||||||
let mut needs_move;
|
let mut needs_move;
|
||||||
let mut last_color = None;
|
let mut last_color = None;
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ mod test {
|
|||||||
fn width() {
|
fn width() {
|
||||||
let data = Data::new();
|
let data = Data::new();
|
||||||
let mock = MockWrite::new(data);
|
let mock = MockWrite::new(data);
|
||||||
let renderer = WriteRenderer::new(mock, 10, 2);
|
let renderer = WriteSurface::new(mock, 10, 2);
|
||||||
|
|
||||||
assert_eq!(10, renderer.width());
|
assert_eq!(10, renderer.width());
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ mod test {
|
|||||||
fn height() {
|
fn height() {
|
||||||
let data = Data::new();
|
let data = Data::new();
|
||||||
let mock = MockWrite::new(data);
|
let mock = MockWrite::new(data);
|
||||||
let renderer = WriteRenderer::new(mock, 5, 8);
|
let renderer = WriteSurface::new(mock, 5, 8);
|
||||||
|
|
||||||
assert_eq!(8, renderer.height());
|
assert_eq!(8, renderer.height());
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ mod test {
|
|||||||
// Execute
|
// Execute
|
||||||
let data = Data::new();
|
let data = Data::new();
|
||||||
let mock = MockWrite::new(data.clone());
|
let mock = MockWrite::new(data.clone());
|
||||||
let mut renderer = WriteRenderer::new(mock, 4, 4);
|
let mut renderer = WriteSurface::new(mock, 4, 4);
|
||||||
|
|
||||||
renderer.purge().unwrap();
|
renderer.purge().unwrap();
|
||||||
|
|
||||||
@ -177,16 +177,16 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn render() {
|
fn present() {
|
||||||
// Execute
|
// Execute
|
||||||
let data = Data::new();
|
let data = Data::new();
|
||||||
let mock = MockWrite::new(data.clone());
|
let mock = MockWrite::new(data.clone());
|
||||||
let mut renderer = WriteRenderer::new(mock, 3, 2);
|
let mut renderer = WriteSurface::new(mock, 3, 2);
|
||||||
|
|
||||||
renderer.draw(0, 0, 'A', Color::Green);
|
renderer.draw(0, 0, 'A', Color::Green);
|
||||||
renderer.draw(1, 0, 'x', Color::Green);
|
renderer.draw(1, 0, 'x', Color::Green);
|
||||||
renderer.clear(1, 1);
|
renderer.clear(1, 1);
|
||||||
renderer.render().unwrap();
|
renderer.present().unwrap();
|
||||||
|
|
||||||
// Recreate expectation
|
// Recreate expectation
|
||||||
let expected = Data::new();
|
let expected = Data::new();
|
Loading…
Reference in New Issue
Block a user