bin: update for repline 0.0.12
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -62,9 +62,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.179"
|
||||
version = "0.2.180"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f"
|
||||
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
@@ -121,9 +121,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "repline"
|
||||
version = "0.0.10"
|
||||
version = "0.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e60dec4cc94ec6dd0cdb58428304d471cf50588357e20f30f449c2c1a8504ee"
|
||||
checksum = "6fc8bb58aab0cf230c95d2649cd54d23b5520e44abdc3f1d420ae844a619d9ef"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
]
|
||||
|
||||
@@ -22,65 +22,14 @@ fn clear() {
|
||||
print!("\x1b[H\x1b[2J\x1b[3J");
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
enum Verbosity {
|
||||
#[default]
|
||||
Pretty,
|
||||
Debug,
|
||||
Frob,
|
||||
Quiet,
|
||||
}
|
||||
impl From<&str> for Verbosity {
|
||||
fn from(value: &str) -> Self {
|
||||
match value {
|
||||
"quiet" | "false" | "0" | "no" => Verbosity::Quiet,
|
||||
"debug" | "d" => Verbosity::Debug,
|
||||
"frob" => Verbosity::Frob,
|
||||
"pretty" => Verbosity::Pretty,
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
enum ParseMode {
|
||||
#[default]
|
||||
Expr,
|
||||
Pat,
|
||||
Bind,
|
||||
Use,
|
||||
Tokens,
|
||||
}
|
||||
impl From<&str> for ParseMode {
|
||||
fn from(value: &str) -> Self {
|
||||
match value {
|
||||
"expr" => Self::Expr,
|
||||
"pat" => Self::Pat,
|
||||
"bind" => Self::Bind,
|
||||
"use" => Self::Use,
|
||||
"tokens" => Self::Tokens,
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ParseMode {
|
||||
fn with<'a>(&self) -> fn(&'a str, Verbosity) {
|
||||
match self {
|
||||
Self::Expr => parse::<'a, Expr>,
|
||||
Self::Pat => parse::<'a, Pat>,
|
||||
Self::Bind => parse::<'a, Bind>,
|
||||
Self::Use => parse::<'a, Use>,
|
||||
Self::Tokens => tokens::<'a, dyn Parse<'a, Prec = ()>>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut verbose = Verbosity::from(std::env::var("DO_VERBOSE").as_deref().unwrap_or_default());
|
||||
let mut parsing = ParseMode::from(std::env::var("DO_PARSING").as_deref().unwrap_or_default());
|
||||
let color = parsing.color();
|
||||
let begin = verbose.begin();
|
||||
|
||||
if stdin().is_terminal() {
|
||||
read_and("\x1b[32m", ".>", " >", |line| match line.trim_end() {
|
||||
read_and_mut(color, begin, " > ", |rl, line| match line.trim_end() {
|
||||
"" => Ok(Response::Continue),
|
||||
"exit" => Ok(Response::Break),
|
||||
"help" => {
|
||||
@@ -101,11 +50,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
line @ ("tokens" | "expr" | "pat" | "bind" | "use") => {
|
||||
parsing = ParseMode::from(line);
|
||||
println!("Parse mode set to '{parsing:?}'");
|
||||
rl.set_color(parsing.color());
|
||||
Ok(Response::Accept)
|
||||
}
|
||||
line @ ("quiet" | "debug" | "frob" | "pretty") => {
|
||||
verbose = Verbosity::from(line);
|
||||
println!("Verbosity set to '{verbose:?}'");
|
||||
rl.set_begin(verbose.begin());
|
||||
Ok(Response::Accept)
|
||||
}
|
||||
_ if line.ends_with("\n\n") => {
|
||||
@@ -241,3 +192,79 @@ fn parse<'t, T: Parse<'t> + Annotation + for<'a> Walk<'a, DefaultTypes>>(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
enum Verbosity {
|
||||
#[default]
|
||||
Pretty,
|
||||
Debug,
|
||||
Frob,
|
||||
Quiet,
|
||||
}
|
||||
|
||||
impl From<&str> for Verbosity {
|
||||
fn from(value: &str) -> Self {
|
||||
match value {
|
||||
"quiet" | "false" | "0" | "no" => Verbosity::Quiet,
|
||||
"debug" | "d" => Verbosity::Debug,
|
||||
"frob" => Verbosity::Frob,
|
||||
"pretty" => Verbosity::Pretty,
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Verbosity {
|
||||
fn begin(self) -> &'static str {
|
||||
match self {
|
||||
Self::Pretty => ".> ",
|
||||
Self::Debug => "?> ",
|
||||
Self::Frob => "#> ",
|
||||
Self::Quiet => "_> ",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
enum ParseMode {
|
||||
#[default]
|
||||
Expr,
|
||||
Pat,
|
||||
Bind,
|
||||
Use,
|
||||
Tokens,
|
||||
}
|
||||
|
||||
impl From<&str> for ParseMode {
|
||||
fn from(value: &str) -> Self {
|
||||
match value {
|
||||
"expr" => Self::Expr,
|
||||
"pat" => Self::Pat,
|
||||
"bind" => Self::Bind,
|
||||
"use" => Self::Use,
|
||||
"tokens" => Self::Tokens,
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ParseMode {
|
||||
fn with<'a>(&self) -> fn(&'a str, Verbosity) {
|
||||
match self {
|
||||
Self::Expr => parse::<'a, Expr>,
|
||||
Self::Pat => parse::<'a, Pat>,
|
||||
Self::Bind => parse::<'a, Bind>,
|
||||
Self::Use => parse::<'a, Use>,
|
||||
Self::Tokens => tokens::<'a, dyn Parse<'a, Prec = ()>>,
|
||||
}
|
||||
}
|
||||
|
||||
fn color(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Expr => "\x1b[36m",
|
||||
Self::Pat => "\x1b[35m",
|
||||
Self::Bind => "\x1b[34m",
|
||||
Self::Use => "\x1b[33m",
|
||||
Self::Tokens => "\x1b[32m",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user