diff --git a/TODO.md b/TODO.md index 05e298e..43d7cab 100644 --- a/TODO.md +++ b/TODO.md @@ -1,2 +1,2 @@ -- [ ] Modularise functions -- [ ] Make components (i.e statusbar) modular +- [ ] Add scratch buffers +- [ ] Add read only buffers diff --git a/src/core/buffer.rs b/src/core/buffer.rs index 86be39e..805b90f 100644 --- a/src/core/buffer.rs +++ b/src/core/buffer.rs @@ -1,30 +1,23 @@ -use std::path::Path; -use std::env; +use std::path::PathBuf; pub struct Buffer<'a> { pub data: Vec, + pub path: PathBuf, pub name: &'a str, - pub path: &'a Path, } impl<'a> Buffer<'a> { - pub fn new(file_path: &'a str) -> Self { - let name = if file_path.len() > 0 { - Path::new(file_path).file_name().unwrap().to_str().unwrap() + pub fn new(dir_path: PathBuf, file_name: &'a str) -> Self { + let name = if file_name.len() > 0 { + file_name } else { "[No Name]" }; - let path = if file_path.len() > 1 { - Path::new(file_path) - } else { - env::current_dir().unwrap().parent().unwrap().to_str() - }; - Self { data: vec![String::from("")], + path: dir_path, name, - path, } } -} \ No newline at end of file +} diff --git a/src/core/editor.rs b/src/core/editor.rs index 8a3bfa3..4f95161 100644 --- a/src/core/editor.rs +++ b/src/core/editor.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::core::buffer::Buffer; pub struct Config<'a> { @@ -41,10 +43,10 @@ pub struct Editor<'a> { } impl<'a> Editor<'a> { - pub fn new(file_path: &'a str) -> Self { + pub fn new(dir_path: PathBuf, file_name: &'a str) -> Self { Editor { config: Config::new(), - buffer: Box::new(Buffer::new(file_path)), + buffer: Box::new(Buffer::new(dir_path, file_name)), cursors: Vec::from([0]), mode: Mode::Normal, } diff --git a/src/main.rs b/src/main.rs index 03a61fa..bda93b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,29 @@ mod core; mod terminal; mod tui; -use std::env; +use std::{env, path::PathBuf}; fn main() { - // Collect cli arguments + // Collect command line arguments let args: Vec = env::args().collect(); - let file_path = if args.len() > 1 { - // Collect the file path - &args[1] - } else { - "" - }; + // Collect the file path + let current_dir = env::current_dir().unwrap(); + let file_path = if args.len() > 1 { PathBuf::from(&args[1]) } else { current_dir.to_path_buf() }; - + // Collect the file name + let file_name = file_path.clone(); + let file_name = if args.len() > 1 { file_name.file_name().unwrap().to_str().unwrap() } else { "" }; - let lambda = core::editor::Editor::new(file_path); + // Collect the directory path + let dir_path = file_path.parent().unwrap().to_path_buf(); + + // Create a new editor + let lambda = core::editor::Editor::new(dir_path, file_name); + + // Initalise a screen let mut screen = terminal::screen::Screen::new().unwrap(); + + // Begin lambda tui::ui::start(&mut screen, lambda); }