Compare commits

...

2 Commits

Author SHA1 Message Date
Mark 599c9742d2
Added a few more commands and arguments 2023-09-21 12:50:16 -07:00
Mark 9f9cc5d084
Added character limits 2023-09-21 12:35:59 -07:00
2 changed files with 53 additions and 6 deletions

View File

@ -16,6 +16,7 @@ pub fn is_command(
| "vars"
| "consts" | "constants"
| "del" | "delete"
| "flags"
=> true,
_ => false
}
@ -81,6 +82,27 @@ pub fn do_command(
return t;
},
"flags" => {
return FormattedText::new(
concat!(
"\n",
"A list of command-line arguments is below\n",
"\n",
"╞════ [t]Flag[n] ════╪════════════════ [t]Function[n] ════════════════╡\n",
" [c]--help[n] Show help\n",
" [c]--version[n] Show version\n",
" [c]--info[n] Show system information\n",
" [c]--256color[n] Use full color support (default)\n",
" [c]--8color[n] Use reduced colors (ANSI, no styling)\n",
" [c]--nocolor[n] Do not use colors\n",
" [c]--nosub[n] Disable inline substitution\n",
" [c]--nosuper[n] Disable superscript powers\n",
" [c]--nooneover[n] Disable \"one-over\" fractions as -1 power\n",
"\n\n"
).to_string()
);
},
"clear" => {
return FormattedText::new("[clear]".to_string());
},

View File

@ -29,7 +29,9 @@ pub fn main() -> Result<(), std::io::Error> {
let mut pb: PromptBuffer = PromptBuffer::new(64);
let mut context = Context::new();
// Set color compatibilty
// Detect color compatibilty
// Currently unused, this is slow.
/*
let term_colors = stdout.available_colors().unwrap_or(0);
if term_colors >= 256 {
context.config.term_color_type = 2;
@ -38,9 +40,7 @@ pub fn main() -> Result<(), std::io::Error> {
} else {
context.config.term_color_type = 0;
}
context.config.check();
*/
// Handle command-line arguments
@ -48,6 +48,8 @@ pub fn main() -> Result<(), std::io::Error> {
if args.iter().any(|s| s == "--help") {
let t = command::do_command(&mut context, &String::from("help"));
t.write(&context, &mut stdout)?;
let t = command::do_command(&mut context, &String::from("flags"));
t.write(&context, &mut stdout)?;
return Ok(());
} else if args.iter().any(|s| s == "--version") {
let t = FormattedText::new(format!(
@ -62,12 +64,27 @@ pub fn main() -> Result<(), std::io::Error> {
"Your terminal supports {} colors.\n"
),
env!("CARGO_PKG_VERSION"),
term_colors
stdout.available_colors().unwrap_or(0)
));
t.write(&context, &mut stdout)?;
return Ok(());
} else if args.iter().any(|s| s == "--256color") {
context.config.term_color_type = 2;
} else if args.iter().any(|s| s == "--8color") {
context.config.term_color_type = 1;
} else if args.iter().any(|s| s == "--0color") {
context.config.term_color_type = 0;
} else if args.iter().any(|s| s == "--nosub") {
context.config.enable_substituion = false;
} else if args.iter().any(|s| s == "--nosuper") {
context.config.enable_super_powers = false;
} else if args.iter().any(|s| s == "--nooneover") {
context.config.enable_one_over_power = false;
}
context.config.check();
'outer: loop {
pb.write_prompt(&mut context, &mut stdout)?;
@ -98,7 +115,15 @@ pub fn main() -> Result<(), std::io::Error> {
break;
},
_ => { pb.add_char(*q); }
// Only process sane characters
'a'..='z' | 'A'..='Z' | '0'..='9'
|'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'('|')'
|'?'|'~'|','|'.'|'['|']'
|'<'|'>'|'/'|'_'|'-'|':'|'|'|'='|'+'|';'
=> { pb.add_char(*q); },
_ => {}
};
} else {
match c.unwrap() {