MCPcopy Create free account
hub / github.com/awslabs/llrt / process_input

Function process_input

llrt/src/repl.rs:31–57  ·  view source on GitHub ↗
(ctx: &Ctx<'_>, input: &str, tty: bool)

Source from the content-addressed store, hash-verified

29use crate::VERSION_STRING;
30
31async 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
59pub(crate) async fn run_repl(ctx: &AsyncContext) {
60 let is_tty = stdout().is_terminal();

Callers 2

run_replFunction · 0.85
test_process_inputFunction · 0.85

Calls 5

format_valuesFunction · 0.85
as_bytesMethod · 0.45
getMethod · 0.45
into_valueMethod · 0.45
to_stringMethod · 0.45

Tested by 1

test_process_inputFunction · 0.68