chiark / gitweb /
Make the Examine prompt chain to another activity.
authorSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 09:13:38 +0000 (09:13 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 09:13:38 +0000 (09:13 +0000)
Doesn't _work_, because I haven't actually implemented that activity
yet. We now panic in a FIXME in tui.rs. But it's a start.

src/editor.rs

index 43c11f86d56aeeaa76f0da1a9f010c6f1bf1ab35..5d3c5e67ba5f0a387f3e82a0dc71a64a8efe4dc9 100644 (file)
@@ -1,5 +1,6 @@
 use unicode_width::UnicodeWidthChar;
 
+use super::activity_stack::UtilityActivity;
 use super::client::Client;
 use super::coloured_string::ColouredString;
 use super::tui::{
@@ -526,15 +527,19 @@ struct BottomLineEditorOverlay {
     prompt: ColouredString,
     promptwidth: usize,
     ed: SingleLineEditor,
+    result: Box<dyn Fn(&str) -> LogicalAction>,
 }
 
 impl BottomLineEditorOverlay {
-    fn new(prompt: ColouredString) -> Self {
+    fn new(prompt: ColouredString, result: Box<dyn Fn(&str) -> LogicalAction>)
+           -> Self
+    {
         let promptwidth = prompt.width();
         BottomLineEditorOverlay {
             prompt: prompt,
             promptwidth,
             ed: SingleLineEditor::new(),
+            result: result,
         }
     }
 }
@@ -562,7 +567,7 @@ impl ActivityState for BottomLineEditorOverlay {
         LogicalAction
     {
         if self.ed.handle_keypress(key) {
-            LogicalAction::Beep // FIXME: do something!
+            (self.result)(&self.ed.core.text)
         } else {
             LogicalAction::Nothing
         }
@@ -571,5 +576,8 @@ impl ActivityState for BottomLineEditorOverlay {
 
 pub fn get_user_to_examine() -> Box<dyn ActivityState> {
     Box::new(BottomLineEditorOverlay::new(
-        ColouredString::plain("Examine User: ")))
+        ColouredString::plain("Examine User: "),
+        Box::new(move |s| LogicalAction::Goto(
+            UtilityActivity::ExamineUser(s.to_owned()).into()))
+    ))
 }