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

Method handle_command

src/apps/cli/src/modes/chat.rs:1634–1774  ·  view source on GitHub ↗

Handle shortcut commands

(
        &mut self,
        command: &str,
        chat_view: &mut ChatView,
        chat_state: &mut ChatState,
        rt_handle: &tokio::runtime::Handle,
    )

Source from the content-addressed store, hash-verified

1632
1633 /// Handle shortcut commands
1634 fn handle_command(
1635 &mut self,
1636 command: &str,
1637 chat_view: &mut ChatView,
1638 chat_state: &mut ChatState,
1639 rt_handle: &tokio::runtime::Handle,
1640 ) -> Result<Option<ChatExitReason>> {
1641 let parts: Vec<&str> = command.split_whitespace().collect();
1642 if parts.is_empty() {
1643 return Ok(None);
1644 }
1645
1646 match parts[0] {
1647 "/help" => {
1648 chat_view.show_info_popup(KEYBOARD_SHORTCUTS_HELP.to_string());
1649 }
1650 "/clear" => {
1651 if chat_state.is_processing {
1652 tracing::info!("User requested cancellation via /clear");
1653 let agent = self.agent.clone();
1654 tokio::task::block_in_place(|| {
1655 rt_handle.block_on(async move {
1656 if let Err(e) = agent.cancel_current_turn().await {
1657 tracing::error!("Failed to cancel turn: {}", e);
1658 }
1659 })
1660 });
1661 }
1662 chat_state.clear_messages();
1663 chat_view.clear_screen();
1664 chat_view.set_status(Some("Conversation cleared".to_string()));
1665 }
1666 "/agents" => {
1667 self.show_agent_selector(chat_view, chat_state, rt_handle);
1668 }
1669 "/models" => {
1670 self.show_model_selector(chat_view, chat_state, rt_handle);
1671 }
1672 "/theme" => {
1673 let themes = self.list_available_themes();
1674 chat_view.begin_theme_preview();
1675 chat_view.show_theme_selector(themes, Some(self.config.ui.theme_id.clone()));
1676 chat_view.set_status(Some(
1677 "Theme selector: ↑↓ preview, Enter apply, Esc cancel".to_string(),
1678 ));
1679 }
1680 "/connect" => {
1681 chat_view.show_provider_selector();
1682 }
1683 "/new" => {
1684 if chat_state.is_processing {
1685 chat_view.set_status(Some(
1686 "Cannot start a new session while processing. Press Ctrl+C to cancel first."
1687 .to_string(),
1688 ));
1689 return Ok(None);
1690 }
1691 return Ok(Some(ChatExitReason::NewSession));

Callers 2

handle_key_eventMethod · 0.45
handle_non_key_eventMethod · 0.45

Calls 15

acp_help_textFunction · 0.85
collectMethod · 0.80
show_info_popupMethod · 0.80
cancel_current_turnMethod · 0.80
clear_messagesMethod · 0.80
clear_screenMethod · 0.80
add_system_messageMethod · 0.80
show_usage_reportMethod · 0.80
send_message_to_agentMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected