1
0
This commit is contained in:
Jeff 2023-08-28 17:24:15 -04:00
parent fad8d97212
commit 0a16edbc97

View File

@ -1,24 +1,17 @@
//! Command line interface for the whale programming language. //! Command line interface for the whale programming language.
use clap::Parser; use clap::Parser;
use eframe::epaint::ahash::HashSet;
use rustyline::{ use rustyline::{
completion::FilenameCompleter, completion::FilenameCompleter,
error::ReadlineError, error::ReadlineError,
highlight::Highlighter, highlight::Highlighter,
hint::{Hint, Hinter, HistoryHinter}, hint::{Hint, Hinter, HistoryHinter},
history::DefaultHistory, history::DefaultHistory,
validate::MatchingBracketValidator, Completer, Context, Editor, Helper, Validator,
Completer, Context, DefaultEditor, Editor, Helper, Hinter, Validator,
}; };
use std::{ use std::{borrow::Cow, fs::read_to_string};
borrow::Cow,
collections::BTreeSet,
fs::{self, read_to_string},
path::PathBuf,
};
use dust_lib::{eval, eval_with_context, Tool, ToolInfo, Value, VariableMap, TOOL_LIST}; use dust_lib::{eval, eval_with_context, Value, VariableMap, TOOL_LIST};
/// Command-line arguments to be parsed. /// Command-line arguments to be parsed.
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -63,14 +56,14 @@ struct DustReadline {
tool_hints: Vec<ToolHint>, tool_hints: Vec<ToolHint>,
#[rustyline(Hinter)] #[rustyline(Hinter)]
hinter: HistoryHinter, _hinter: HistoryHinter,
} }
impl DustReadline { impl DustReadline {
fn new() -> Self { fn new() -> Self {
Self { Self {
completer: FilenameCompleter::new(), completer: FilenameCompleter::new(),
hinter: HistoryHinter {}, _hinter: HistoryHinter {},
tool_hints: TOOL_LIST tool_hints: TOOL_LIST
.iter() .iter()
.map(|tool| ToolHint { .map(|tool| ToolHint {
@ -147,7 +140,7 @@ fn run_cli_shell() {
} }
loop { loop {
let readline = rl.readline(">> "); let readline = rl.readline("* ");
match readline { match readline {
Ok(line) => { Ok(line) => {
let line = line.as_str(); let line = line.as_str();
@ -157,22 +150,17 @@ fn run_cli_shell() {
let eval_result = eval_with_context(line, &mut context); let eval_result = eval_with_context(line, &mut context);
match eval_result { match eval_result {
Ok(value) => println!("{value}"), Ok(_) => {}
Err(error) => eprintln!("{error}"), Err(error) => eprintln!("{error}"),
} }
} }
Err(ReadlineError::Interrupted) => { Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
break; break;
} }
Err(ReadlineError::Eof) => { Err(ReadlineError::Eof) => {
println!("CTRL-D");
break;
}
Err(err) => {
println!("Error: {:?}", err);
break; break;
} }
Err(error) => eprintln!("{error}"),
} }
} }