1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
pub mod eval; pub mod io; pub mod parser; pub mod prelude; pub mod tokens; pub use eval::eval; pub use io::{clear, input, warn}; pub use prelude::prelude; use xmachine::{Machine, Value}; use std::collections::HashMap; #[macro_use] extern crate lazy_static; use swears::Terminal; lazy_static! { pub static ref TERMINAL: Terminal = { let term = Terminal::with_color(); term.show_cursor(); term.enable_scrolling(); term.clear(); term }; } pub fn get_cwd(m: &mut Machine) -> String { m.push(Value::string("cwd")); m.load(); m.get_arg().to_string() } pub fn get_aliases(m: &mut Machine) -> HashMap<String, String> { m.push(Value::string("aliases")); m.load(); let mut result = HashMap::new(); if let Value::Tree(t) = m.get_arg() { for (key, value) in t.into_iter() { result.insert(key, value.to_string()); } } return result; } pub fn get_snippets(m: &mut Machine) -> HashMap<String, (String, usize)> { m.push(Value::string("snippets")); m.load(); let mut result = HashMap::new(); if let Value::Tree(t) = m.get_arg() { for (key, value) in t.into_iter() { if let Value::List(l) = (*value).clone() { result.insert(key, (l[0].to_string(), i32::from((*l[1]).clone()) as usize)); } } } return result; }