load-to-string pulls out newline, also fix issue with nested calls
This commit is contained in:
parent
ee1ef9700d
commit
d7864ee628
3 changed files with 27 additions and 21 deletions
|
|
@ -483,9 +483,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
|
|
||||||
** TODO Pre-alpha tasks
|
** TODO Pre-alpha tasks
|
||||||
- Shell module
|
- Shell module
|
||||||
- strip final newline from load-to-string
|
|
||||||
- cd with no args goes home
|
|
||||||
- cd sets . symbol
|
|
||||||
- ignore job control signals (if needed)
|
- ignore job control signals (if needed)
|
||||||
- background processes
|
- background processes
|
||||||
- be able to list all background processes with j function
|
- be able to list all background processes with j function
|
||||||
|
|
|
||||||
|
|
@ -53,15 +53,6 @@
|
||||||
(set (q bat-iter) (pop rem))))
|
(set (q bat-iter) (pop rem))))
|
||||||
display)))
|
display)))
|
||||||
|
|
||||||
(def getcwd 'gets pwd basename'
|
|
||||||
(lambda ()
|
|
||||||
(let ((cwd (load-to-string pwd))
|
|
||||||
(dir-raw (load-to-string basename cwd))
|
|
||||||
;; pull out newlines
|
|
||||||
(dir (dq (cdr (dq (cdr (dq (split dir-raw ""))))))))
|
|
||||||
(reduce (lambda (x y) (concat x y))
|
|
||||||
(cdr dir)))))
|
|
||||||
|
|
||||||
(def CFG_RELISH_R_PROMPT 'display battery info'
|
(def CFG_RELISH_R_PROMPT 'display battery info'
|
||||||
()
|
()
|
||||||
(display-batteries))
|
(display-batteries))
|
||||||
|
|
@ -70,6 +61,6 @@
|
||||||
()
|
()
|
||||||
(concat
|
(concat
|
||||||
"[" USER "] "
|
"[" USER "] "
|
||||||
(getcwd) " "
|
(load-to-string basename (load-to-string pwd)) " "
|
||||||
;; add more prompt elements here
|
;; add more prompt elements here
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,10 @@ use {
|
||||||
|
|
||||||
std::{
|
std::{
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
cell::RefCell,
|
cell::{
|
||||||
|
RefCell, RefMut,
|
||||||
|
BorrowMutError,
|
||||||
|
},
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
|
@ -292,9 +295,9 @@ fn load_to_string_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellStat
|
||||||
state.last_exit_code = code;
|
state.last_exit_code = code;
|
||||||
}
|
}
|
||||||
if let Ok(string) = String::from_utf8(output.stdout) {
|
if let Ok(string) = String::from_utf8(output.stdout) {
|
||||||
Ok(Ctr::String(string))
|
Ok(Ctr::String(string.trim_end().to_string()))
|
||||||
} else {
|
} else {
|
||||||
Err(format!("could'nt marshall utf-8 command output into a string"))
|
Err(format!("couldn't marshall utf-8 command output into a string"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(format!("{}", res.err().unwrap()))
|
Err(format!("{}", res.err().unwrap()))
|
||||||
|
|
@ -558,7 +561,7 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
|
||||||
conditional_branches: true,
|
conditional_branches: true,
|
||||||
docs: String::from(BG_DOCSTRING),
|
docs: String::from(BG_DOCSTRING),
|
||||||
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
bg_callback(ast, symtable, &mut bg_ss.clone().borrow_mut())
|
bg_callback(ast, symtable, &mut bg_ss.borrow_mut())
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -572,7 +575,7 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
|
||||||
conditional_branches: false,
|
conditional_branches: false,
|
||||||
docs: String::from(Q_DOCSTRING),
|
docs: String::from(Q_DOCSTRING),
|
||||||
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
q_callback(ast, symtable, &mut q_ss.clone().borrow_mut())
|
q_callback(ast, symtable, &mut q_ss.borrow_mut())
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -586,7 +589,7 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
|
||||||
conditional_branches: true,
|
conditional_branches: true,
|
||||||
docs: String::from(LOAD_WITH_DOCSTRING),
|
docs: String::from(LOAD_WITH_DOCSTRING),
|
||||||
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
load_with_callback(ast, symtable, &mut lw_ss.clone().borrow_mut())
|
load_with_callback(ast, symtable, &mut lw_ss.borrow_mut())
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -600,7 +603,22 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
|
||||||
conditional_branches: true,
|
conditional_branches: true,
|
||||||
docs: String::from(LOAD_TO_STRING_DOCSTRING),
|
docs: String::from(LOAD_TO_STRING_DOCSTRING),
|
||||||
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
load_to_string_callback(ast, symtable, &mut lts_ss.clone().borrow_mut())
|
// extra nonsense needed to allow nested calls
|
||||||
|
load_to_string_callback(
|
||||||
|
ast,
|
||||||
|
symtable,
|
||||||
|
&mut lts_ss
|
||||||
|
.try_borrow_mut()
|
||||||
|
.or(Ok::<RefMut<'_, ShellState>, BorrowMutError>(
|
||||||
|
RefCell::from(ShellState{
|
||||||
|
parent_pid: pid,
|
||||||
|
parent_pgid: pgid,
|
||||||
|
children: vec![],
|
||||||
|
last_exit_code: 0,
|
||||||
|
}).borrow_mut()
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
)
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -614,7 +632,7 @@ pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>
|
||||||
conditional_branches: true,
|
conditional_branches: true,
|
||||||
docs: String::from(PIPE_DOCSTRING),
|
docs: String::from(PIPE_DOCSTRING),
|
||||||
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
pipe_callback(ast, symtable, &mut p_ss.clone().borrow_mut())
|
pipe_callback(ast, symtable, &mut p_ss.borrow_mut())
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue