From ed686f7c7fdce0c3062a2859e32e974c096246df Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Fri, 19 Jan 2024 19:56:39 -0600 Subject: Add notes to eval output. --- src/commands/discocaml.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/commands/discocaml.rs b/src/commands/discocaml.rs index a24276d..2c34c81 100644 --- a/src/commands/discocaml.rs +++ b/src/commands/discocaml.rs @@ -56,12 +56,14 @@ pub enum DiscocamlCommand { /// [ "Expr" /// , { "expr": "1 + 2" /// , "has_redex": true +/// , "note": null /// } /// ] /// "#; /// let expected = DiscocamlResponse::Expr(DiscocamlResponseExpr { /// expr: "1 + 2".to_string(), /// has_redex: true, +/// note: None, /// }); /// /// let mut de = Deserializer::from_str(&example); @@ -83,6 +85,7 @@ pub enum DiscocamlResponse { pub struct DiscocamlResponseExpr { pub expr: String, pub has_redex: bool, + pub note: Option, } impl DiscocamlResponseExpr { @@ -291,9 +294,18 @@ async fn run_dot(dot: &str) -> Result { } fn expr_response_message(expr: &DiscocamlResponseExpr) -> CreateInteractionResponseMessage { - // TODO: Real escaping + let mut msg = String::new(); + if let Some(note) = &expr.note { + msg.push_str(note); + msg.push('\n'); + } + msg.push_str("```ocaml\n"); + // TODO: Escaping + msg.push_str(&expr.expr); + msg.push_str("```\n"); + CreateInteractionResponseMessage::new() - .content(format!("```ocaml\n{}\n```", expr.expr)) + .content(msg) .button(CreateButton::new("draw-tree").label("Draw Tree")) .button( CreateButton::new("step-cbv") -- cgit v1.2.3