| 29 | use crate::VERSION_STRING; |
| 30 | |
| 31 | async fn process_input(ctx: &Ctx<'_>, input: &str, tty: bool) -> String { |
| 32 | // First try to evaluate and format the input |
| 33 | |
| 34 | let mut options: EvalOptions = EvalOptions::default(); |
| 35 | options.promise = true; |
| 36 | |
| 37 | match async { |
| 38 | let promise = ctx.eval_with_options::<Promise, _>(input.as_bytes(), options)?; |
| 39 | let future = promise.into_future::<Object>(); |
| 40 | let value = future.await?.get(PredefinedAtom::Value)?; |
| 41 | format_values(ctx, Rest(vec![value]), tty, true) |
| 42 | } |
| 43 | .await |
| 44 | .catch(ctx) |
| 45 | { |
| 46 | Ok(v) => v, |
| 47 | Err(error) => { |
| 48 | match (|| { |
| 49 | let error_value = error.into_value(ctx)?; |
| 50 | format_values(ctx, Rest(vec![error_value]), tty, true) |
| 51 | })() { |
| 52 | Ok(s) => s, |
| 53 | Err(err) => err.to_string(), |
| 54 | } |
| 55 | }, |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | pub(crate) async fn run_repl(ctx: &AsyncContext) { |
| 60 | let is_tty = stdout().is_terminal(); |