POSIX conditional compilation:
* All features related to POSIX environments (env vars, shell stuff) gated by feature flags * Dependencies optional per feature flags * new CI target for non-POSIX build * new CI target for release binary artifact Signed-off-by: Ava Hahn [ava@sunnypup.io](mailto:ava@sunnypup.io)
This commit is contained in:
parent
5e15109b0c
commit
906cb16355
13 changed files with 330 additions and 319 deletions
|
|
@ -28,7 +28,6 @@ use {
|
|||
CONSOLE_XDIM_VNAME, CONSOLE_YDIM_VNAME, CFG_FILE_VNAME,
|
||||
L_PROMPT_VNAME, R_PROMPT_VNAME, PROMPT_DELIM_VNAME,
|
||||
},
|
||||
aux::{ShellState, check_jobs},
|
||||
},
|
||||
std::{
|
||||
cell::RefCell,
|
||||
|
|
@ -46,12 +45,17 @@ use {
|
|||
ColumnarMenu, Emacs, ReedlineMenu,
|
||||
default_emacs_keybindings,
|
||||
},
|
||||
nix::unistd,
|
||||
nu_ansi_term::{Color, Style},
|
||||
dirs::home_dir,
|
||||
termion::terminal_size,
|
||||
};
|
||||
|
||||
#[cfg(feature="posix")]
|
||||
use relish::aux::{ShellState, check_jobs};
|
||||
#[cfg(feature="posix")]
|
||||
use nix::unistd;
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CustomPrompt(String, String, String);
|
||||
#[derive(Clone)]
|
||||
|
|
@ -237,24 +241,16 @@ fn main() {
|
|||
let hist_file_name = home_dir.clone() + HIST_FILE;
|
||||
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
|
||||
|
||||
// TODO: the next two decls should probably be conditional on CFG_RELISH_POSIX
|
||||
// but in both cases the data must live for the whole program
|
||||
let shell_state_bindings = Rc::new(RefCell::from(ShellState {
|
||||
parent_pid: unistd::Pid::from_raw(0),
|
||||
parent_sid: unistd::Pid::from_raw(0),
|
||||
children: vec![],
|
||||
last_exit_code: 0,
|
||||
attr: None,
|
||||
}));
|
||||
let prompt_ss = shell_state_bindings.clone();
|
||||
|
||||
// setup symtable
|
||||
let mut syms = SymTable::new();
|
||||
load_defaults(&mut syms);
|
||||
load_environment(&mut syms);
|
||||
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||
static_stdlib(&mut syms);
|
||||
// reload this later with the state bindings
|
||||
dynamic_stdlib(&mut syms, None).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||
#[cfg(feature="posix")]
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
#[cfg(not(feature="posix"))]
|
||||
dynamic_stdlib(&mut syms);
|
||||
|
||||
// if there are args those are scripts, run them and exit
|
||||
if env::args().count() > 1 {
|
||||
|
|
@ -274,10 +270,23 @@ fn main() {
|
|||
run(cfg_file.clone(), &mut syms)
|
||||
.unwrap_or_else(|err: Traceback| eprintln!("failed to load script {}\n{}", cfg_file, err));
|
||||
}
|
||||
dynamic_stdlib(&mut syms, Some(shell_state_bindings)).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||
|
||||
#[cfg(feature="posix")]
|
||||
let prompt_ss: Rc<RefCell<ShellState>>;
|
||||
#[cfg(feature="posix")]
|
||||
{
|
||||
let shell_state_bindings = Rc::new(RefCell::from(ShellState {
|
||||
parent_pid: unistd::Pid::from_raw(0),
|
||||
parent_sid: unistd::Pid::from_raw(0),
|
||||
children: vec![],
|
||||
last_exit_code: 0,
|
||||
attr: None,
|
||||
}));
|
||||
prompt_ss = shell_state_bindings.clone();
|
||||
dynamic_stdlib(&mut syms, Some(shell_state_bindings));
|
||||
}
|
||||
|
||||
// setup readline
|
||||
|
||||
let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
|
||||
let mut keybindings = default_emacs_keybindings();
|
||||
add_menu_keybindings(&mut keybindings);
|
||||
|
|
@ -305,8 +314,8 @@ fn main() {
|
|||
let mut xdimension: u16 = 0;
|
||||
let mut ydimension: u16 = 0;
|
||||
loop {
|
||||
#[cfg(feature="posix")]
|
||||
{
|
||||
// update state
|
||||
check_jobs(&mut prompt_ss.borrow_mut());
|
||||
}
|
||||
let readline_prompt = make_prompt(&mut syms);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue