|
|
@ -2,8 +2,14 @@ use std::str::FromStr;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{Directory, State};
|
|
|
|
use crate::{Directory, State};
|
|
|
|
|
|
|
|
|
|
|
|
static PROJECTS_DIR: &'static str = "stuff";
|
|
|
|
static PROJECTS_DIR: &'static str = "~ashe ashe.gay tempest.dev";
|
|
|
|
static HOME_DIR: &'static str = "projects";
|
|
|
|
static HOME_DIR: &'static str = "about.md contact.md \x1b[0;36mprojects\x1b[0m";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ABOUT: &'static str = include_str!("../res/about.md");
|
|
|
|
|
|
|
|
static CONTACT: &'static str = include_str!("../res/contact.md");
|
|
|
|
|
|
|
|
static ASHE_GAY: &'static str = include_str!("../res/ashe.gay.md");
|
|
|
|
|
|
|
|
static TEMPEST_DEV: &'static str = include_str!("../res/tempest.dev.md");
|
|
|
|
|
|
|
|
static TILDE_ASHE: &'static str = include_str!("../res/~ashe.md");
|
|
|
|
|
|
|
|
|
|
|
|
pub fn handle_command(command_string : String, state : &mut State) {
|
|
|
|
pub fn handle_command(command_string : String, state : &mut State) {
|
|
|
|
let mut words = command_string.split(' ');
|
|
|
|
let mut words = command_string.split(' ');
|
|
|
@ -79,8 +85,53 @@ pub fn handle_command(command_string : String, state : &mut State) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"cat" => match args.len() {
|
|
|
|
|
|
|
|
0 => state.output.push_back(format!("bash: cat: too few arguments")),
|
|
|
|
|
|
|
|
1 => match state.current_working_directory {
|
|
|
|
|
|
|
|
Directory::Home => match args[0] {
|
|
|
|
|
|
|
|
"about.md" => output_file(ABOUT, args[0], state),
|
|
|
|
|
|
|
|
"contact.md" => output_file(CONTACT, args[0], state),
|
|
|
|
|
|
|
|
"projects/ashe.gay" => output_file(ASHE_GAY, args[0], state),
|
|
|
|
|
|
|
|
"projects/tempest.dev" => output_file(TEMPEST_DEV, args[0], state),
|
|
|
|
|
|
|
|
"projects/~ashe" => output_file(TILDE_ASHE, args[0], state),
|
|
|
|
|
|
|
|
_ => state.output.push_back(format!("bash: cat: {}: No such file or directory", args[0]))
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Directory::Projects => match args[0] {
|
|
|
|
|
|
|
|
"../about.md" => output_file(ABOUT, args[0], state),
|
|
|
|
|
|
|
|
"../contact.md" => output_file(CONTACT, args[0], state),
|
|
|
|
|
|
|
|
"ashe.gay" => output_file(ASHE_GAY, args[0], state),
|
|
|
|
|
|
|
|
"tempest.dev" => output_file(TEMPEST_DEV, args[0], state),
|
|
|
|
|
|
|
|
"~ashe" => output_file(TILDE_ASHE, args[0], state),
|
|
|
|
|
|
|
|
_ => state.output.push_back(format!("bash: cat: {}: No such file or directory", args[0]))
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => state.output.push_back(format!("bash: cat: too many arguments"))
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
_ => {
|
|
|
|
state.output.push_back(format!("bash: {}: command not found", command));
|
|
|
|
state.output.push_back(format!("bash: {}: command not found", command));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn output_file(file_string : &str, path : &str, state : &mut State) {
|
|
|
|
|
|
|
|
let header = "───────┬───────────────────────────────────────────────────────";
|
|
|
|
|
|
|
|
let divider = "───────┼───────────────────────────────────────────────────────";
|
|
|
|
|
|
|
|
let footer = "───────┴───────────────────────────────────────────────────────";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.print(String::from_str(header).unwrap());
|
|
|
|
|
|
|
|
state.print(format!(" │ File: {}", path));
|
|
|
|
|
|
|
|
state.print(String::from_str(divider).unwrap());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let lines = file_string.split('\n');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (index, line) in lines.enumerate() {
|
|
|
|
|
|
|
|
if index == 0 && line == "" {
|
|
|
|
|
|
|
|
state.print(format!(" {:<2} │ {}", index + 1, "\x1b[0;33m<empty>\x1b[0m"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
state.print(format!(" {:<2} │ {}", index + 1, line));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.print(String::from_str(footer).unwrap());
|
|
|
|
|
|
|
|
}
|