MCPcopy
hub / github.com/Textualize/textual / _select_or_command

Method _select_or_command

src/textual/command.py:1213–1245  ·  view source on GitHub ↗

Depending on context, select or execute a command.

(
        self, event: Input.Submitted | Button.Pressed | None = None
    )

Source from the content-addressed store, hash-verified

1211 @on(Input.Submitted)
1212 @on(Button.Pressed)
1213 def _select_or_command(
1214 self, event: Input.Submitted | Button.Pressed | None = None
1215 ) -> None:
1216 """Depending on context, select or execute a command."""
1217 # If the list is visible, that means we're in "pick a command"
1218 # mode...
1219 if event is not None:
1220 event.stop()
1221 if self._list_visible:
1222 command_list = self.query_one(CommandList)
1223 # ...so if nothing in the list is highlighted yet...
1224 if command_list.highlighted is None:
1225 # ...cause the first completion to be highlighted.
1226 self._action_cursor_down()
1227 # If there is one option, assume the user wants to select it
1228 if command_list.option_count == 1:
1229 # Call after a short delay to provide a little visual feedback
1230 self._action_command_list("select")
1231 else:
1232 # The list is visible, something is highlighted, the user
1233 # made a selection "gesture"; let's go select it!
1234 self._action_command_list("select")
1235 else:
1236 # The list isn't visible, which means that if we have a
1237 # command...
1238 if self._selected_command is not None:
1239 # ...we should return it to the parent screen and let it
1240 # decide what to do with it (hopefully it'll run it).
1241 self._cancel_gather_commands()
1242 self.app.post_message(CommandPalette.Closed(option_selected=True))
1243 self.app.delay_update()
1244 self.dismiss()
1245 self.app.call_later(self._selected_command.command)
1246
1247 @on(OptionList.OptionHighlighted)
1248 def _stop_event_leak(self, event: OptionList.OptionHighlighted) -> None:

Callers 1

_select_commandMethod · 0.95

Calls 9

_action_cursor_downMethod · 0.95
_action_command_listMethod · 0.95
query_oneMethod · 0.80
delay_updateMethod · 0.80
dismissMethod · 0.80
call_laterMethod · 0.80
stopMethod · 0.45
post_messageMethod · 0.45

Tested by

no test coverage detected