Skip to content

Commit

Permalink
save to file added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed May 19, 2024
1 parent 4e9a5f2 commit bcbe39b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 122 deletions.
121 changes: 0 additions & 121 deletions ]

This file was deleted.

7 changes: 6 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::error;
use std::{error, fs};

use ratatui::layout::Rect;

Expand Down Expand Up @@ -73,6 +73,11 @@ impl App {
self.quit_times = QUIT_TIMES;
}

pub fn save_to_file(&mut self, filename: String) {
self.dirty = false;
let _ = fs::write(filename, self.content.join("\n"));
}

pub fn insert_char(&mut self, c: char) {
while self.cursor_position.y >= self.content.len() {
self.content.push(String::new());
Expand Down
3 changes: 3 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
if key_event.code == KeyCode::Char('c') || key_event.code == KeyCode::Char('C') {
app.quit();
}
if key_event.code == KeyCode::Char('s') || key_event.code == KeyCode::Char('S') {
app.save_to_file("text.txt".into());
}
}
_ => match key_event.code {
KeyCode::Enter => {
Expand Down

0 comments on commit bcbe39b

Please sign in to comment.