Skip to content

Commit a5a9222

Browse files
committed
refactor: delegate to ui_state
1 parent 8ce299b commit a5a9222

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/agent_chat_cli/core/actions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from agent_chat_cli.components.messages import RoleType
55
from agent_chat_cli.components.chat_history import ChatHistory
66
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
7-
from agent_chat_cli.components.model_selection_menu import ModelSelectionMenu
87
from agent_chat_cli.utils.logger import log_json
98
from agent_chat_cli.utils.save_conversation import save_conversation
109

@@ -16,9 +15,6 @@ class Actions:
1615
def __init__(self, app: "AgentChatCLIApp") -> None:
1716
self.app = app
1817

19-
def quit(self) -> None:
20-
self.app.exit()
21-
2218
async def post_user_message(self, message: str) -> None:
2319
await self.app.renderer.add_message(RoleType.USER, message)
2420
await self._query(message)
@@ -46,6 +42,9 @@ async def new(self) -> None:
4642
await self.app.agent_loop.query_queue.put(ControlCommand.NEW_CONVERSATION)
4743
await self.clear()
4844

45+
def quit(self) -> None:
46+
self.app.exit()
47+
4948
async def respond_to_tool_permission(self, response: str) -> None:
5049
log_json(
5150
{
@@ -74,8 +73,7 @@ async def save(self) -> None:
7473
)
7574

7675
def show_model_menu(self) -> None:
77-
model_menu = self.app.query_one(ModelSelectionMenu)
78-
model_menu.show()
76+
self.app.ui_state.show_model_menu()
7977

8078
async def change_model(self, model: str) -> None:
8179
await self.app.agent_loop.change_model(model)

src/agent_chat_cli/core/ui_state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
88
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
99
from agent_chat_cli.components.user_input import UserInput
10+
from agent_chat_cli.components.model_selection_menu import ModelSelectionMenu
1011

1112
if TYPE_CHECKING:
1213
from agent_chat_cli.app import AgentChatCLIApp
@@ -76,3 +77,7 @@ async def scroll_to_bottom(self) -> None:
7677
await asyncio.sleep(0.1)
7778
container = self.app.query_one(VerticalScroll)
7879
container.scroll_end(animate=False, immediate=True)
80+
81+
def show_model_menu(self) -> None:
82+
model_menu = self.app.query_one(ModelSelectionMenu)
83+
model_menu.show()

tests/core/test_actions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,15 @@ async def test_does_not_trigger_thinking(
254254

255255
thinking_indicator = app.query_one(ThinkingIndicator)
256256
assert thinking_indicator.is_thinking is False
257+
258+
259+
class TestActionsShowModelMenu:
260+
async def test_delegates_to_ui_state(self, mock_agent_loop, mock_config):
261+
from agent_chat_cli.components.model_selection_menu import ModelSelectionMenu
262+
263+
app = AgentChatCLIApp()
264+
async with app.run_test():
265+
app.actions.show_model_menu()
266+
267+
model_menu = app.query_one(ModelSelectionMenu)
268+
assert model_menu.is_visible is True

tests/core/test_ui_state.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
88
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
99
from agent_chat_cli.components.user_input import UserInput
10+
from agent_chat_cli.components.model_selection_menu import ModelSelectionMenu
1011

1112

1213
@pytest.fixture
@@ -163,3 +164,13 @@ async def test_clear_input(self, mock_agent_loop, mock_config):
163164
app.ui_state.clear_input()
164165

165166
assert text_area.text == ""
167+
168+
169+
class TestUIStateModelMenu:
170+
async def test_show_model_menu_makes_visible(self, mock_agent_loop, mock_config):
171+
app = AgentChatCLIApp()
172+
async with app.run_test():
173+
app.ui_state.show_model_menu()
174+
175+
model_menu = app.query_one(ModelSelectionMenu)
176+
assert model_menu.is_visible is True

0 commit comments

Comments
 (0)