usability improvements to env and def
* env prints variables and functions in seperate columns * run/stl seperation of concerns significantly better * def doesnt store lists or lambdas in the environment
This commit is contained in:
parent
825854fd42
commit
6969ea63bc
7 changed files with 309 additions and 131 deletions
143
src/stl.rs
143
src/stl.rs
|
|
@ -20,6 +20,7 @@ use crate::run::{run_callback, RUN_DOCSTRING};
|
|||
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
use std::env::vars;
|
||||
|
||||
pub mod posix;
|
||||
pub mod append;
|
||||
|
|
@ -29,6 +30,29 @@ pub mod decl;
|
|||
pub mod math;
|
||||
pub mod strings;
|
||||
|
||||
pub const CONSOLE_XDIM_VNAME: &str = "_RELISH_WIDTH";
|
||||
pub const CONSOLE_YDIM_VNAME: &str = "_RELISH_HEIGHT";
|
||||
pub const POSIX_CFG_VNAME: &str = "CFG_RELISH_POSIX";
|
||||
pub const MODENV_CFG_VNAME: &str = "CFG_RELISH_ENV";
|
||||
pub const L_PROMPT_VNAME: &str = "CFG_RELISH_L_PROMPT";
|
||||
pub const R_PROMPT_VNAME: &str = "CFG_RELISH_R_PROMPT";
|
||||
pub const PROMPT_DELIM_VNAME: &str = "CFG_RELISH_PROMPT_DELIMITER";
|
||||
pub const CFG_FILE_VNAME: &str = "RELISH_CFG_FILE";
|
||||
pub const RELISH_DEFAULT_CONS_HEIGHT: i16 = 24;
|
||||
pub const RELISH_DEFAULT_CONS_WIDTH: i16 = 80;
|
||||
|
||||
fn l_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||
Ok(Ctr::String(">".to_string()))
|
||||
}
|
||||
|
||||
fn r_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||
Ok(Ctr::String(String::new()))
|
||||
}
|
||||
|
||||
fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||
Ok(Ctr::String("λ ".to_string()))
|
||||
}
|
||||
|
||||
/// static_stdlib
|
||||
/// inserts all stdlib functions that can be inserted without
|
||||
/// any kind of further configuration data into a symtable
|
||||
|
|
@ -618,11 +642,12 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::ShellState>>>) -> Result<(), String> {
|
||||
//get CFG_RELISH_ENV from syms
|
||||
let env_cfg_user_form = syms
|
||||
.call_symbol(&"CFG_RELISH_ENV".to_string(), &Seg::new(), true)
|
||||
.call_symbol(&MODENV_CFG_VNAME.to_string(), &Seg::new(), true)
|
||||
.unwrap_or_else(|_: String| Box::new(Ctr::None))
|
||||
.to_string()
|
||||
.eq("true");
|
||||
|
||||
// this also depends on the value of CFG_RELISH_ENV
|
||||
syms.insert(
|
||||
"def".to_string(),
|
||||
Symbol {
|
||||
|
|
@ -639,9 +664,10 @@ pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::Shell
|
|||
},
|
||||
);
|
||||
|
||||
// This should be replaced by actual compiler conditionals in the future
|
||||
if let Some(shell_state) = shell {
|
||||
let posix_cfg_user_form = syms
|
||||
.call_symbol(&"CFG_RELISH_POSIX".to_string(), &Seg::new(), true)
|
||||
.call_symbol(&POSIX_CFG_VNAME.to_string(), &Seg::new(), true)
|
||||
.unwrap_or_else(|_: String| Box::new(Ctr::None))
|
||||
.to_string()
|
||||
.eq("true");
|
||||
|
|
@ -664,3 +690,116 @@ pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::Shell
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_environment(syms: &mut SymTable) {
|
||||
for (key, value) in vars() {
|
||||
syms.insert(
|
||||
key.clone(),
|
||||
Symbol{
|
||||
name: key,
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: String::from("from env vars at time of load"),
|
||||
value: ValueType::VarForm(Box::new(Ctr::String(value))),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_defaults(syms: &mut SymTable) {
|
||||
syms.insert(
|
||||
POSIX_CFG_VNAME.to_string(),
|
||||
Symbol {
|
||||
name: String::from(POSIX_CFG_VNAME),
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "variable holding whether or not POSIX job control functions are to be loaded.
|
||||
checked at shell startup by configuration daemon. not used afterwards.
|
||||
|
||||
default value: false".to_string(),
|
||||
value: ValueType::VarForm(Box::new(Ctr::Bool(false))),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
MODENV_CFG_VNAME.to_string(),
|
||||
Symbol {
|
||||
name: String::from(MODENV_CFG_VNAME),
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "variable holding whether or not vars and other symbols should be linked to process environment variables.
|
||||
If set/defined all calls to def will result in additions or subtractions from user environment variables.
|
||||
checked at shell startup by configuration daemon. not used afterwards.
|
||||
|
||||
default value: 1 (set)
|
||||
".to_string(),
|
||||
value: ValueType::VarForm(Box::new(Ctr::Bool(true))),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
L_PROMPT_VNAME.to_string(),
|
||||
Symbol {
|
||||
name: String::from(L_PROMPT_VNAME),
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "function called to output prompt on left hand. this function is called with no arguments."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(l_prompt_default_callback)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
R_PROMPT_VNAME.to_string(),
|
||||
Symbol {
|
||||
name: String::from(R_PROMPT_VNAME),
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "function called to output prompt on right hand. this function is called with no arguments."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(r_prompt_default_callback)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
PROMPT_DELIM_VNAME.to_string(),
|
||||
Symbol {
|
||||
name: String::from(PROMPT_DELIM_VNAME),
|
||||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "function called to output prompt delimiter. this function is called with no arguments."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(prompt_delimiter_default_callback)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
String::from(CONSOLE_XDIM_VNAME),
|
||||
Symbol::from_ast(
|
||||
&String::from(CONSOLE_XDIM_VNAME),
|
||||
&String::from("Length of current console"),
|
||||
&Seg::from_mono(Box::new(
|
||||
Ctr::Integer(RELISH_DEFAULT_CONS_WIDTH.into())
|
||||
)),
|
||||
None,
|
||||
)
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
String::from(CONSOLE_YDIM_VNAME),
|
||||
Symbol::from_ast(
|
||||
&String::from(CONSOLE_YDIM_VNAME),
|
||||
&String::from("Height of current console"),
|
||||
&Seg::from_mono(Box::new(
|
||||
Ctr::Integer(RELISH_DEFAULT_CONS_HEIGHT.into())
|
||||
)),
|
||||
None,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue