use mumu::parser::types::{Value, FunctionValue};
use std::fs;
use std::path::Path;
pub fn runner_list_bridge(_interp: &mut mumu::parser::interpreter::Interpreter, args: Vec<Value>) -> Result<Value, String> {
if !args.is_empty() {
return Err(format!("test:list => expected 0 args, got {}", args.len()));
}
let mut names: Vec<String> = fs::read_dir(Path::new("tests"))
.map_err(|e| format!("test:list => {}", e))?
.filter_map(|entry_res| {
let entry = entry_res.ok()?;
let fname = entry.file_name().to_string_lossy().into_owned();
if fname.starts_with('.') {
return None;
}
if !fname.ends_with(".mu") {
return None;
}
Some(fname)
})
.collect();
names.sort();
Ok(Value::StrArray(names))
}
pub const HRULE: &str = "\x1b[1;30m----------------------------------\x1b[0m";
pub const HRULE_PLAIN: &str = "----------------------------------";
use arboard::Clipboard;
pub fn copy_to_clipboard(s: &str) {
if let Ok(mut clipboard) = Clipboard::new() {
let _ = clipboard.set_text(s);
}
}
pub trait CloneFunction {
fn clone_function(&self) -> Option<Box<FunctionValue>>;
}
impl CloneFunction for Value {
fn clone_function(&self) -> Option<Box<FunctionValue>> {
if let Value::Function(fb) = self {
Some(Box::new((**fb).clone()))
} else {
None
}
}
}