Skip to main content

tui/app/
tag_hints.rs

1//! Completions for the tag lists: looked up through `form-options` as the
2//! cursor reaches a name or value cell, each answer dropped when superseded.
3
4use cli_core::forms::parse_suggestions;
5use forms::escape_str;
6
7use crate::app::App;
8use crate::modal::Modal;
9use crate::route::RouteCtx;
10use crate::widgets::Hint;
11
12impl App {
13    /// Asks for the lookup the open form's focused tag cell needs.
14    pub fn fetch_tag_hints(&mut self) {
15        if self.console_eval.is_none() {
16            return;
17        }
18        let Some(Modal::Form(form)) = self.overlays.top() else {
19            return;
20        };
21        let Some(hint) = form.wanted_hint() else {
22            return;
23        };
24        let seq = self.suggest_seq.advance();
25        let call = format!("(form-options {})", escape_str(&hint.source()));
26        let ctx = RouteCtx::Suggestion {
27            seq,
28            hint: hint.clone(),
29        };
30        if self.dispatch_app_eval(ctx, call).is_some()
31            && let Some(Modal::Form(form)) = self.overlays.top_mut()
32        {
33            form.hint_asked(&hint, seq);
34        }
35    }
36
37    pub(super) fn deliver_tag_hints(&mut self, seq: u64, hint: &Hint, wire: &str) {
38        let Some(strings) = parse_suggestions(wire) else {
39            return;
40        };
41        if let Some(form) = self.form_mut(|_| true) {
42            form.hint_arrived(hint, seq, strings);
43        }
44    }
45}