anyhow used
This commit is contained in:
@@ -7,13 +7,14 @@ use crossterm::{
|
||||
};
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use std::io::{self, stdout, Write};
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
pub struct TerminalCore {
|
||||
terminal: Terminal<CrosstermBackend<io::Stdout>>,
|
||||
}
|
||||
|
||||
impl TerminalCore {
|
||||
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
||||
pub fn new() -> Result<Self> {
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = stdout();
|
||||
execute!(
|
||||
@@ -27,7 +28,7 @@ impl TerminalCore {
|
||||
Ok(Self { terminal })
|
||||
}
|
||||
|
||||
pub fn draw<F>(&mut self, f: F) -> Result<(), Box<dyn std::error::Error>>
|
||||
pub fn draw<F>(&mut self, f: F) -> Result<()>
|
||||
where
|
||||
F: FnOnce(&mut ratatui::Frame),
|
||||
{
|
||||
@@ -35,7 +36,7 @@ impl TerminalCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cleanup(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn cleanup(&mut self) -> Result<()> {
|
||||
let backend = self.terminal.backend_mut();
|
||||
execute!(
|
||||
backend,
|
||||
@@ -56,7 +57,7 @@ impl TerminalCore {
|
||||
pub fn set_cursor_style(
|
||||
&mut self,
|
||||
style: SetCursorStyle,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
) -> Result<()> {
|
||||
execute!(
|
||||
self.terminal.backend_mut(),
|
||||
style,
|
||||
@@ -65,7 +66,7 @@ impl TerminalCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn show_cursor(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn show_cursor(&mut self) -> Result<()> {
|
||||
execute!(
|
||||
self.terminal.backend_mut(),
|
||||
Show
|
||||
@@ -73,7 +74,7 @@ impl TerminalCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn hide_cursor(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn hide_cursor(&mut self) -> Result<()> {
|
||||
execute!(
|
||||
self.terminal.backend_mut(),
|
||||
Hide
|
||||
|
||||
Reference in New Issue
Block a user