Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.rs
- // Standard Library Imports
- use std::env::args;
- use std::fs;
- // Local Imports
- mod display;
- mod run;
- mod footer;
- struct Coordinates {
- x: usize,
- y: usize,
- }
- struct DisplayableFile {
- // Coordinates
- terminal_size: Coordinates,
- cursor_pos: Coordinates,
- // Debug
- error: String,
- // Document Stat
- file_name: String,
- footer: String,
- contents: Vec<String>,
- saved: bool,
- command: String,
- mode: Mode
- }
- #[derive(Debug)]
- enum Mode {
- Normal,
- Insert,
- Command
- }
- impl Mode {
- fn as_str(&self) -> &str {
- match self {
- Mode::Normal => "Normal",
- Mode::Insert => "Insert",
- Mode::Command => "Command"
- }
- }
- }
- fn main() {
- let args: Vec<String> = args().collect();
- let mut buffer: Vec<String> = vec![];
- // If file is specified, load the file into the buffer.
- // Otherwise, leave buffer empty.
- let mut file_name = "Buffer";
- if args.len() > 2 {
- if !std::path::Path::new(&args[1]).exists() {
- println!("File does not exist");
- std::process::exit(0);
- }
- file_name = &args[1];
- let file_string = fs::read_to_string(&args[1]);
- for line in file_string.unwrap().split('\n') {
- buffer.push(String::from(line));
- }
- } else {
- buffer.push(String::from(""));
- }
- let size = termion::terminal_size().unwrap();
- let terminal_size = Coordinates {
- x: size.0.into(),
- y: size.1.into(),
- };
- let cursor_pos = Coordinates { x: 0, y: 0 };
- let mut file = DisplayableFile {
- file_name: String::from(file_name),
- terminal_size: terminal_size,
- cursor_pos: cursor_pos,
- footer: String::from("File Footer"),
- contents: buffer,
- saved: true,
- error: String::from(""),
- command: String::new(),
- mode: Mode::Insert,
- };
- file.display();
- loop {
- file.run_off_mode();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment