Skip to content

Commit

Permalink
title added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Mar 6, 2024
1 parent 19210fc commit 7b72daf
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crossterm::{
cursor::MoveTo,
cursor::{Hide, MoveTo},
event::{read, Event::Key, KeyCode, KeyEvent, KeyModifiers},
terminal::{disable_raw_mode, Clear, ClearType},
};
Expand All @@ -19,15 +19,30 @@ impl Editor {
}

pub fn refresh_screen(&self) {
print!("{} {}", Clear(ClearType::All), MoveTo(0, 0));
print!("{} {}", Hide, MoveTo(0, 0));
self.draw_rows();
print!("{}", MoveTo(0, 0));
print!("{} {}", MoveTo(0, 0), Hide);
}

pub fn draw_rows(&self) {
for _ in 0..self.screen_rows {
print!("~");
if self.screen_rows > 1 {
for i in 0..self.screen_rows {
if i == self.screen_rows / 3 {
let message = "rust-edit v0.1";
let len = message.len();
let padding = (self.screen_cols - len) / 2;
if padding > 0 {
print!("~");
for _ in 0..padding - 1 {
print!(" ");
}
print!("{}", message);
}
} else {
print!("~");
}

print!("{}", Clear(ClearType::UntilNewLine));
if i < self.screen_rows - 1 {
print!("\r\n");
}
}
Expand Down

0 comments on commit 7b72daf

Please sign in to comment.