MCPcopy Create free account
hub / github.com/GCWing/BitFun / update_with_commands

Method update_with_commands

src/apps/cli/src/ui/command_menu.rs:39–76  ·  view source on GitHub ↗
(
        &mut self,
        input: &str,
        cursor: usize,
        commands: &'static [CommandSpec],
    )

Source from the content-addressed store, hash-verified

37 }
38
39 pub fn update_with_commands(
40 &mut self,
41 input: &str,
42 cursor: usize,
43 commands: &'static [CommandSpec],
44 ) {
45 if self.suppressed && input == self.last_input {
46 return;
47 }
48
49 if self.suppressed && input != self.last_input {
50 self.suppressed = false;
51 }
52
53 self.last_input = input.to_string();
54
55 if !input.starts_with('/') || !self.cursor_in_command(input, cursor) {
56 self.hide();
57 return;
58 }
59
60 let query = input.split_whitespace().next().unwrap_or("");
61 if query == "/" {
62 self.items = commands.iter().collect();
63 } else {
64 self.items = match_substring_in(query, commands);
65 }
66 self.items.sort_by_key(|spec| spec.name);
67
68 self.visible = !self.items.is_empty();
69 if self.visible {
70 let selected = self.list_state.selected().unwrap_or(0);
71 let clamped = selected.min(self.items.len().saturating_sub(1));
72 self.list_state.select(Some(clamped));
73 } else {
74 self.list_state.select(None);
75 }
76 }
77
78 pub fn is_visible(&self) -> bool {
79 self.visible

Callers 3

updateMethod · 0.80
handle_keyMethod · 0.80
refresh_command_menuMethod · 0.80

Calls 9

match_substring_inFunction · 0.85
cursor_in_commandMethod · 0.80
nextMethod · 0.80
collectMethod · 0.80
iterMethod · 0.80
hideMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected