building up buffer

This commit is contained in:
Maddie 2022-11-11 17:25:29 +00:00
parent 6f792ff546
commit 5b49d25d9e
7 changed files with 80 additions and 14 deletions

20
.replit Normal file
View File

@ -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"]

9
replit.nix Normal file
View File

@ -0,0 +1,9 @@
{ pkgs }: {
deps = [
pkgs.rustc
pkgs.rustfmt
pkgs.cargo
pkgs.cargo-edit
pkgs.rust-analyzer
];
}

30
src/core/buffer.rs Normal file
View File

@ -0,0 +1,30 @@
use std::path::Path;
use std::env;
pub struct Buffer<'a> {
pub data: Vec<String>,
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,
}
}
}

View File

@ -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<String>,
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<Buffer<'a>>,
pub cursors: Vec<i32>,
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,
}

View File

@ -1 +1,2 @@
pub mod editor;
pub mod buffer;

View File

@ -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<String> = 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);
}

View File

@ -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