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" | "vars"
| "consts" | "constants" | "consts" | "constants"
| "del" | "delete" | "del" | "delete"
| "flags"
=> true, => true,
_ => false _ => false
} }
@ -81,6 +82,27 @@ pub fn do_command(
return t; 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" => { "clear" => {
return FormattedText::new("[clear]".to_string()); 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 pb: PromptBuffer = PromptBuffer::new(64);
let mut context = Context::new(); 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); let term_colors = stdout.available_colors().unwrap_or(0);
if term_colors >= 256 { if term_colors >= 256 {
context.config.term_color_type = 2; context.config.term_color_type = 2;
@ -38,9 +40,7 @@ pub fn main() -> Result<(), std::io::Error> {
} else { } else {
context.config.term_color_type = 0; context.config.term_color_type = 0;
} }
*/
context.config.check();
// Handle command-line arguments // Handle command-line arguments
@ -48,6 +48,8 @@ pub fn main() -> Result<(), std::io::Error> {
if args.iter().any(|s| s == "--help") { if args.iter().any(|s| s == "--help") {
let t = command::do_command(&mut context, &String::from("help")); let t = command::do_command(&mut context, &String::from("help"));
t.write(&context, &mut stdout)?; t.write(&context, &mut stdout)?;
let t = command::do_command(&mut context, &String::from("flags"));
t.write(&context, &mut stdout)?;
return Ok(()); return Ok(());
} else if args.iter().any(|s| s == "--version") { } else if args.iter().any(|s| s == "--version") {
let t = FormattedText::new(format!( let t = FormattedText::new(format!(
@ -62,12 +64,27 @@ pub fn main() -> Result<(), std::io::Error> {
"Your terminal supports {} colors.\n" "Your terminal supports {} colors.\n"
), ),
env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_VERSION"),
term_colors stdout.available_colors().unwrap_or(0)
)); ));
t.write(&context, &mut stdout)?; t.write(&context, &mut stdout)?;
return Ok(()); 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 { 'outer: loop {
pb.write_prompt(&mut context, &mut stdout)?; pb.write_prompt(&mut context, &mut stdout)?;
@ -98,7 +115,15 @@ pub fn main() -> Result<(), std::io::Error> {
break; break;
}, },
_ => { pb.add_char(*q); }
// Only process sane characters
'a'..='z' | 'A'..='Z' | '0'..='9'
|'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'('|')'
|'?'|'~'|','|'.'|'['|']'
|'<'|'>'|'/'|'_'|'-'|':'|'|'|'='|'+'|';'
=> { pb.add_char(*q); },
_ => {}
}; };
} else { } else {
match c.unwrap() { match c.unwrap() {