Skip to content

Commit

Permalink
added move cursor feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Znackt committed Jul 9, 2024
1 parent 4a9335b commit 5f8e93e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/editor/terminal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crossterm::cursor::MoveTo;
use crossterm::execute;
use crossterm::terminal::{disable_raw_mode, enable_raw_mode, size, Clear, ClearType};
use std::io::stdout;

pub struct Terminal {}

impl Terminal {
pub fn terminate() -> Result<(), std::io::Error> {
disable_raw_mode()?;
Ok(())
}
pub fn initialize() -> Result<(), std::io::Error> {
enable_raw_mode()?;
Self::clear_screen()?;
Self::move_cursor_to(0, 0)?;
Ok(())
}
pub fn clear_screen() -> Result<(), std::io::Error> {
execute!(stdout(), Clear(ClearType::All))?;
Ok(())
}
pub fn move_cursor_to(x: u16, y: u16) -> Result<(), std::io::Error> {
execute!(stdout(), MoveTo(x, y))?;
Ok(())
}
pub fn size() -> Result<(u16, u16), std::io::Error> {
size()
}
}

0 comments on commit 5f8e93e

Please sign in to comment.