diff --git a/.replit b/.replit new file mode 100644 index 0000000..c71897c --- /dev/null +++ b/.replit @@ -0,0 +1,20 @@ +run = "cargo run" +hidden = ["target"] + +[packager] +language = "rust" + +[packager.features] +packageSearch = true + +[languages.rust] +pattern = "**/*.rs" + +[languages.rust.languageServer] +start = "rust-analyzer" + +[nix] +channel = "stable-22_05" + +[gitHubImport] +requiredFiles = [".replit", "replit.nix"] diff --git a/replit.nix b/replit.nix new file mode 100644 index 0000000..f0e8e08 --- /dev/null +++ b/replit.nix @@ -0,0 +1,9 @@ +{ pkgs }: { + deps = [ + pkgs.rustc + pkgs.rustfmt + pkgs.cargo + pkgs.cargo-edit + pkgs.rust-analyzer + ]; +} \ No newline at end of file diff --git a/src/core/buffer.rs b/src/core/buffer.rs new file mode 100644 index 0000000..86be39e --- /dev/null +++ b/src/core/buffer.rs @@ -0,0 +1,30 @@ +use std::path::Path; +use std::env; + +pub struct Buffer<'a> { + pub data: Vec, + 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() + } 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("")], + name, + path, + } + } +} \ No newline at end of file diff --git a/src/core/editor.rs b/src/core/editor.rs index ecb4a2c..8a3bfa3 100644 --- a/src/core/editor.rs +++ b/src/core/editor.rs @@ -1,3 +1,5 @@ +use crate::core::buffer::Buffer; + pub struct Config<'a> { pub logo: &'a str, pub friendly_name: &'a str, @@ -12,12 +14,6 @@ impl<'a> Config<'a> { } } -pub struct Buffer<'a> { - pub data: Vec, - pub name: &'a str, - pub path: &'a str, -} - #[allow(dead_code)] pub enum Mode { Normal, @@ -39,20 +35,16 @@ impl Mode { pub struct Editor<'a> { pub config: Config<'a>, - pub buffer: Buffer<'a>, + pub buffer: Box>, pub cursors: Vec, pub mode: Mode, } impl<'a> Editor<'a> { - pub fn new() -> Self { + pub fn new(file_path: &'a str) -> Self { Editor { config: Config::new(), - buffer: Buffer { - data: Vec::from([String::from("Hello"), String::from("World")]), - name: "[No Name]", - path: "/home/spy", - }, + buffer: Box::new(Buffer::new(file_path)), cursors: Vec::from([0]), mode: Mode::Normal, } diff --git a/src/core/mod.rs b/src/core/mod.rs index 0769981..e9335de 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -1 +1,2 @@ pub mod editor; +pub mod buffer; diff --git a/src/main.rs b/src/main.rs index fa97c4a..03a61fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,22 @@ mod core; mod terminal; mod tui; +use std::env; fn main() { - let lambda = core::editor::Editor::new(); + // Collect cli arguments + let args: Vec = env::args().collect(); + + let file_path = if args.len() > 1 { + // Collect the file path + &args[1] + } else { + "" + }; + + + + let lambda = core::editor::Editor::new(file_path); let mut screen = terminal::screen::Screen::new().unwrap(); tui::ui::start(&mut screen, lambda); } diff --git a/src/tui/components/statusbar.rs b/src/tui/components/statusbar.rs index add3913..74989e2 100644 --- a/src/tui/components/statusbar.rs +++ b/src/tui/components/statusbar.rs @@ -35,6 +35,7 @@ pub fn draw(screen: &mut Screen, editor: &Editor) -> Result<(), ()> { mode_string.green().bold().reverse().to_string(), Coords::from(x, status_height), ); + // Calculate where to write the file name let x = x + mode_string.len(); // Write the current file name