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
|
- [ ] Add scratch buffers
|
||||||
- [ ] Make components (i.e statusbar) modular
|
- [ ] Add read only buffers
|
||||||
|
@ -1,30 +1,23 @@
|
|||||||
use std::path::Path;
|
use std::path::PathBuf;
|
||||||
use std::env;
|
|
||||||
|
|
||||||
pub struct Buffer<'a> {
|
pub struct Buffer<'a> {
|
||||||
pub data: Vec<String>,
|
pub data: Vec<String>,
|
||||||
|
pub path: PathBuf,
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
pub path: &'a Path,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Buffer<'a> {
|
impl<'a> Buffer<'a> {
|
||||||
pub fn new(file_path: &'a str) -> Self {
|
pub fn new(dir_path: PathBuf, file_name: &'a str) -> Self {
|
||||||
let name = if file_path.len() > 0 {
|
let name = if file_name.len() > 0 {
|
||||||
Path::new(file_path).file_name().unwrap().to_str().unwrap()
|
file_name
|
||||||
} else {
|
} else {
|
||||||
"[No Name]"
|
"[No Name]"
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = if file_path.len() > 1 {
|
|
||||||
Path::new(file_path)
|
|
||||||
} else {
|
|
||||||
env::current_dir().unwrap().parent().unwrap().to_str()
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
data: vec![String::from("")],
|
data: vec![String::from("")],
|
||||||
|
path: dir_path,
|
||||||
name,
|
name,
|
||||||
path,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::core::buffer::Buffer;
|
use crate::core::buffer::Buffer;
|
||||||
|
|
||||||
pub struct Config<'a> {
|
pub struct Config<'a> {
|
||||||
@ -41,10 +43,10 @@ pub struct Editor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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 {
|
Editor {
|
||||||
config: Config::new(),
|
config: Config::new(),
|
||||||
buffer: Box::new(Buffer::new(file_path)),
|
buffer: Box::new(Buffer::new(dir_path, file_name)),
|
||||||
cursors: Vec::from([0]),
|
cursors: Vec::from([0]),
|
||||||
mode: Mode::Normal,
|
mode: Mode::Normal,
|
||||||
}
|
}
|
||||||
|
23
src/main.rs
23
src/main.rs
@ -1,22 +1,29 @@
|
|||||||
mod core;
|
mod core;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
mod tui;
|
mod tui;
|
||||||
use std::env;
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Collect cli arguments
|
// Collect command line arguments
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
let file_path = if args.len() > 1 {
|
|
||||||
// Collect the file path
|
// Collect the file path
|
||||||
&args[1]
|
let current_dir = env::current_dir().unwrap();
|
||||||
} else {
|
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();
|
let mut screen = terminal::screen::Screen::new().unwrap();
|
||||||
|
|
||||||
|
// Begin lambda
|
||||||
tui::ui::start(&mut screen, lambda);
|
tui::ui::start(&mut screen, lambda);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user