finished loading buffer names
This commit is contained in:
parent
5b49d25d9e
commit
cb005ef441
4
TODO.md
4
TODO.md
@ -1,2 +1,2 @@
|
||||
- [ ] Modularise functions
|
||||
- [ ] Make components (i.e statusbar) modular
|
||||
- [ ] Add scratch buffers
|
||||
- [ ] Add read only buffers
|
||||
|
@ -1,30 +1,23 @@
|
||||
use std::path::Path;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Buffer<'a> {
|
||||
pub data: Vec<String>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
@ -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,
|
||||
}
|
||||
|
25
src/main.rs
25
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<String> = 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 { "" };
|
||||
|
||||
// Collect the directory path
|
||||
let dir_path = file_path.parent().unwrap().to_path_buf();
|
||||
|
||||
let lambda = core::editor::Editor::new(file_path);
|
||||
// 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user