multiline shell, yay!
This commit is contained in:
parent
5bdf409a1f
commit
67af8bbd47
8 changed files with 76 additions and 48 deletions
|
|
@ -1,21 +1,6 @@
|
||||||
default:
|
default:
|
||||||
image: rust:latest
|
image: rust:latest
|
||||||
|
|
||||||
fmt:
|
|
||||||
stage: build
|
|
||||||
script:
|
|
||||||
- rustup component add rustfmt
|
|
||||||
- rustfmt --check tests/*
|
|
||||||
- rustfmt --check src/*.rs
|
|
||||||
- rustfmt --check src/stl/*
|
|
||||||
- rustfmt --check src/bin/*
|
|
||||||
|
|
||||||
lint:
|
|
||||||
stage: build
|
|
||||||
script:
|
|
||||||
- cargo clippy
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
compile:
|
compile:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,6 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dirs = "3.0"
|
dirs = "3.0"
|
||||||
rustyline = "8.2.0"
|
nu-ansi-term = "0.47.0"
|
||||||
|
reedline = "0.17.0"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ Overload Load function to call a binary too
|
||||||
**** TODO Foreground process TTY (fg function)
|
**** TODO Foreground process TTY (fg function)
|
||||||
**** TODO list jobs (j function)
|
**** TODO list jobs (j function)
|
||||||
**** TODO ESSENTIAL: DOCUMENT POSIX MODULE
|
**** TODO ESSENTIAL: DOCUMENT POSIX MODULE
|
||||||
*** TODO Can enter multiple lines of text, with formatting in repl
|
*** TODO Configurable RPROMPT
|
||||||
*** TODO Rename to Flesh
|
*** TODO Rename to Flesh
|
||||||
*** TODO Create a dedicated community channel on matrix.sunnypup.io
|
*** TODO Create a dedicated community channel on matrix.sunnypup.io
|
||||||
*** TODO Post to relevant channels
|
*** TODO Post to relevant channels
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,60 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
use nu_ansi_term::{Color, Style};
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
use relish::ast::{eval, lex, Ctr, Seg, SymTable};
|
use relish::ast::{eval, lex, Ctr, Seg, SymTable};
|
||||||
use relish::aux::configure;
|
use relish::aux::configure;
|
||||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||||
use rustyline::error::ReadlineError;
|
use reedline::{
|
||||||
use rustyline::Editor;
|
FileBackedHistory, DefaultHinter, DefaultValidator, Reedline, Signal,
|
||||||
|
Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus,
|
||||||
|
};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
fn main() {
|
#[derive(Clone)]
|
||||||
let mut rl = Editor::<()>::new();
|
pub struct CustomPrompt<'a>(&'a str);
|
||||||
|
impl Prompt for CustomPrompt<'_> {
|
||||||
|
fn render_prompt_left(&self) -> Cow<str> {
|
||||||
|
{
|
||||||
|
Cow::Owned(self.0.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_prompt_right(&self) -> Cow<str> {
|
||||||
|
{
|
||||||
|
Cow::Owned(format!(" <"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_prompt_indicator(&self, _edit_mode: PromptEditMode) -> Cow<str> {
|
||||||
|
Cow::Owned("> ".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_prompt_multiline_indicator(&self) -> Cow<str> {
|
||||||
|
Cow::Borrowed("++++")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_prompt_history_search_indicator(
|
||||||
|
&self,
|
||||||
|
history_search: PromptHistorySearch,
|
||||||
|
) -> Cow<str> {
|
||||||
|
let prefix = match history_search.status {
|
||||||
|
PromptHistorySearchStatus::Passing => "",
|
||||||
|
PromptHistorySearchStatus::Failing => "failing ",
|
||||||
|
};
|
||||||
|
|
||||||
|
Cow::Owned(format!(
|
||||||
|
"({}reverse-search: {}) ",
|
||||||
|
prefix, history_search.term
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> ! {
|
||||||
const HIST_FILE: &str = "/.relish_hist";
|
const HIST_FILE: &str = "/.relish_hist";
|
||||||
const CONFIG_FILE_DEFAULT: &str = "/.relishrc";
|
const CONFIG_FILE_DEFAULT: &str = "/.relishrc";
|
||||||
|
|
||||||
|
|
@ -33,11 +75,19 @@ fn main() {
|
||||||
let hist_file_name = home_dir.clone() + HIST_FILE;
|
let hist_file_name = home_dir.clone() + HIST_FILE;
|
||||||
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
|
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
|
||||||
|
|
||||||
|
let mut rl = Reedline::create();
|
||||||
|
let maybe_hist: Box<FileBackedHistory>;
|
||||||
if !hist_file_name.is_empty() {
|
if !hist_file_name.is_empty() {
|
||||||
rl.load_history(&hist_file_name)
|
maybe_hist = Box::new(FileBackedHistory::with_file(5, hist_file_name.into())
|
||||||
.unwrap_or_else(|err: ReadlineError| eprintln!("{}", err));
|
.expect("error reading history!"));
|
||||||
|
rl = rl.with_history(maybe_hist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rl = rl.with_hinter(Box::new(
|
||||||
|
DefaultHinter::default()
|
||||||
|
.with_style(Style::new().italic().fg(Color::LightGray)),
|
||||||
|
)).with_validator(Box::new(DefaultValidator));
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||||
dynamic_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
dynamic_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||||
|
|
@ -56,12 +106,12 @@ fn main() {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
Box::new(Ctr::String("<prompt broken!>".to_string()))
|
Box::new(Ctr::String("<prompt broken!>".to_string()))
|
||||||
});
|
});
|
||||||
let readline_prompt = s.to_string();
|
let p_str = s.to_string();
|
||||||
|
let readline_prompt = CustomPrompt(p_str.as_str());
|
||||||
|
|
||||||
let user_doc = rl.readline(&readline_prompt);
|
let user_doc = rl.read_line(&readline_prompt).unwrap();
|
||||||
match user_doc {
|
match user_doc {
|
||||||
Ok(line) => {
|
Signal::Success(line) => {
|
||||||
rl.add_history_entry(line.as_str());
|
|
||||||
let l = line.as_str().to_owned();
|
let l = line.as_str().to_owned();
|
||||||
|
|
||||||
match lex(&l) {
|
match lex(&l) {
|
||||||
|
|
@ -71,17 +121,16 @@ fn main() {
|
||||||
},
|
},
|
||||||
Err(s) => println!("{}", s),
|
Err(s) => println!("{}", s),
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
Err(ReadlineError::Interrupted) => break,
|
Signal::CtrlD => {
|
||||||
Err(ReadlineError::Eof) => return,
|
println!("EOF!");
|
||||||
Err(err) => {
|
panic!();
|
||||||
eprintln!("Prompt error: {:?}", err);
|
},
|
||||||
break;
|
|
||||||
|
Signal::CtrlC => {
|
||||||
|
println!("Interrupted!");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hist_file_name.is_empty() {
|
|
||||||
rl.save_history(&hist_file_name).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,6 @@ default value (<lambda>)"
|
||||||
config_document = "(".to_string() + &config_document;
|
config_document = "(".to_string() + &config_document;
|
||||||
|
|
||||||
let config_tree = lex(&config_document)?;
|
let config_tree = lex(&config_document)?;
|
||||||
let config_result = eval(&config_tree, syms)?;
|
eval(&config_tree, syms)?;
|
||||||
|
|
||||||
println!("config result: {config_result}");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ use crate::sym::{SymTable, call_lambda};
|
||||||
* representing the simplest possible form of the input
|
* representing the simplest possible form of the input
|
||||||
*/
|
*/
|
||||||
pub fn eval(ast: &Seg, syms: &mut SymTable) -> Result<Box<Ctr>, String> {
|
pub fn eval(ast: &Seg, syms: &mut SymTable) -> Result<Box<Ctr>, String> {
|
||||||
println!("E: {}", ast);
|
|
||||||
// data to return
|
// data to return
|
||||||
let mut ret = Box::from(Ctr::None);
|
let mut ret = Box::from(Ctr::None);
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,6 @@ pub const STORE_DOCSTRING: &str = "allows user to define functions and variables
|
||||||
(def useless-var)";
|
(def useless-var)";
|
||||||
|
|
||||||
pub fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr, String> {
|
pub fn store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr, String> {
|
||||||
println!("def: {}", ast);
|
|
||||||
let is_var = ast.len() == 3;
|
let is_var = ast.len() == 3;
|
||||||
if let Ctr::Symbol(ref identifier) = *ast.car {
|
if let Ctr::Symbol(ref identifier) = *ast.car {
|
||||||
match &*ast.cdr {
|
match &*ast.cdr {
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,6 @@ impl Symbol {
|
||||||
evaluated_args = args;
|
evaluated_args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("args: {}", evaluated_args);
|
|
||||||
self.args.validate_inputs(evaluated_args)?;
|
self.args.validate_inputs(evaluated_args)?;
|
||||||
match &self.value {
|
match &self.value {
|
||||||
ValueType::VarForm(ref f) => Ok(Box::new(*f.clone())),
|
ValueType::VarForm(ref f) => Ok(Box::new(*f.clone())),
|
||||||
|
|
@ -362,18 +361,15 @@ impl Symbol {
|
||||||
let value: ValueType;
|
let value: ValueType;
|
||||||
|
|
||||||
if let Some(ref arg_syms) = arg_list {
|
if let Some(ref arg_syms) = arg_list {
|
||||||
println!("def a func form");
|
|
||||||
value = ValueType::FuncForm(UserFn{
|
value = ValueType::FuncForm(UserFn{
|
||||||
ast: Box::new(ast.clone()),
|
ast: Box::new(ast.clone()),
|
||||||
arg_syms: arg_syms.clone(),
|
arg_syms: arg_syms.clone(),
|
||||||
});
|
});
|
||||||
args = Args::Lazy(arg_syms.len() as u128);
|
args = Args::Lazy(arg_syms.len() as u128);
|
||||||
} else if let Ctr::Lambda(ref l) = *ast.car {
|
} else if let Ctr::Lambda(ref l) = *ast.car {
|
||||||
println!("def a func form (lambda)");
|
|
||||||
args = Args::Lazy(l.arg_syms.len() as u128);
|
args = Args::Lazy(l.arg_syms.len() as u128);
|
||||||
value = ValueType::FuncForm(l.clone());
|
value = ValueType::FuncForm(l.clone());
|
||||||
} else {
|
} else {
|
||||||
println!("def a var form");
|
|
||||||
args = Args::None;
|
args = Args::None;
|
||||||
value = ValueType::VarForm(ast.car.clone());
|
value = ValueType::VarForm(ast.car.clone());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue