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:
Ava Apples Affine 2023-05-21 23:53:00 +00:00
parent 825854fd42
commit 6969ea63bc
7 changed files with 309 additions and 131 deletions

View file

@ -18,24 +18,11 @@
use crate::eval::eval;
use crate::lex::lex;
use crate::segment::{Ctr, Seg};
use crate::sym::{Args, SymTable, Symbol, ValueType};
use std::path::{Path};
use crate::sym::SymTable;
use std::path::Path;
use std::fs;
use std::iter::FromIterator;
use std::env::{vars, var, current_dir};
use std::rc::Rc;
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()))
}
use std::env::{var, current_dir};
fn get_paths() -> Vec<String> {
Vec::from_iter(var("PATH")
@ -44,95 +31,6 @@ fn get_paths() -> Vec<String> {
.map(String::from))
}
pub fn load_defaults(syms: &mut SymTable) {
syms.insert(
"CFG_RELISH_POSIX".to_string(),
Symbol {
name: String::from("CFG_RELISH_POSIX"),
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(
"CFG_RELISH_ENV".to_string(),
Symbol {
name: String::from("CFG_RELISH_ENV"),
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(
"CFG_RELISH_L_PROMPT".to_string(),
Symbol {
name: String::from("default relish left prompt"),
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(
"CFG_RELISH_R_PROMPT".to_string(),
Symbol {
name: String::from("default relish right prompt"),
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(
"CFG_RELISH_PROMPT_DELIMITER".to_string(),
Symbol {
name: String::from("default relish prompt delimiter"),
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()
},
);
}
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 find_on_path(filename: String) -> Option<String> {
let mut prefixes = get_paths();
if let Ok(s) = current_dir() {