Skip to content

Commit

Permalink
refactor: simplify to io::Result (#1016)
Browse files Browse the repository at this point in the history
Simplifies the code, logic stays exactly the same.
  • Loading branch information
EdJoPaTo authored Apr 3, 2024
1 parent 14461c3 commit 359204c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
Ok(Rect::new(0, 0, width, height))
}

fn window_size(&mut self) -> Result<WindowSize, io::Error> {
fn window_size(&mut self) -> io::Result<WindowSize> {
let crossterm::terminal::WindowSize {
columns,
rows,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ where
Ok(Rect::new(0, 0, terminal.0, terminal.1))
}

fn window_size(&mut self) -> Result<WindowSize, io::Error> {
fn window_size(&mut self) -> io::Result<WindowSize> {
Ok(WindowSize {
columns_rows: termion::terminal_size()?.into(),
pixels: termion::terminal_size_pixels()?.into(),
Expand Down
14 changes: 7 additions & 7 deletions src/backend/termwiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl TermwizBackend {
}

impl Backend for TermwizBackend {
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
Expand Down Expand Up @@ -181,13 +181,13 @@ impl Backend for TermwizBackend {
Ok(())
}

fn hide_cursor(&mut self) -> Result<(), io::Error> {
fn hide_cursor(&mut self) -> io::Result<()> {
self.buffered_terminal
.add_change(Change::CursorVisibility(CursorVisibility::Hidden));
Ok(())
}

fn show_cursor(&mut self) -> Result<(), io::Error> {
fn show_cursor(&mut self) -> io::Result<()> {
self.buffered_terminal
.add_change(Change::CursorVisibility(CursorVisibility::Visible));
Ok(())
Expand All @@ -207,18 +207,18 @@ impl Backend for TermwizBackend {
Ok(())
}

fn clear(&mut self) -> Result<(), io::Error> {
fn clear(&mut self) -> io::Result<()> {
self.buffered_terminal
.add_change(Change::ClearScreen(termwiz::color::ColorAttribute::Default));
Ok(())
}

fn size(&self) -> Result<Rect, io::Error> {
fn size(&self) -> io::Result<Rect> {
let (cols, rows) = self.buffered_terminal.dimensions();
Ok(Rect::new(0, 0, u16_max(cols), u16_max(rows)))
}

fn window_size(&mut self) -> Result<WindowSize, io::Error> {
fn window_size(&mut self) -> io::Result<WindowSize> {
let ScreenSize {
cols,
rows,
Expand All @@ -241,7 +241,7 @@ impl Backend for TermwizBackend {
})
}

fn flush(&mut self) -> Result<(), io::Error> {
fn flush(&mut self) -> io::Result<()> {
self.buffered_terminal
.flush()
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
Expand Down
18 changes: 9 additions & 9 deletions src/backend/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Display for TestBackend {
}

impl Backend for TestBackend {
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
Expand All @@ -125,26 +125,26 @@ impl Backend for TestBackend {
Ok(())
}

fn hide_cursor(&mut self) -> Result<(), io::Error> {
fn hide_cursor(&mut self) -> io::Result<()> {
self.cursor = false;
Ok(())
}

fn show_cursor(&mut self) -> Result<(), io::Error> {
fn show_cursor(&mut self) -> io::Result<()> {
self.cursor = true;
Ok(())
}

fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
Ok(self.pos)
}

fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
self.pos = (x, y);
Ok(())
}

fn clear(&mut self) -> Result<(), io::Error> {
fn clear(&mut self) -> io::Result<()> {
self.buffer.reset();
Ok(())
}
Expand Down Expand Up @@ -214,11 +214,11 @@ impl Backend for TestBackend {
Ok(())
}

fn size(&self) -> Result<Rect, io::Error> {
fn size(&self) -> io::Result<Rect> {
Ok(Rect::new(0, 0, self.width, self.height))
}

fn window_size(&mut self) -> Result<WindowSize, io::Error> {
fn window_size(&mut self) -> io::Result<WindowSize> {
// Some arbitrary window pixel size, probably doesn't need much testing.
static WINDOW_PIXEL_SIZE: Size = Size {
width: 640,
Expand All @@ -230,7 +230,7 @@ impl Backend for TestBackend {
})
}

fn flush(&mut self) -> Result<(), io::Error> {
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
Expand Down

0 comments on commit 359204c

Please sign in to comment.