Skip to content

Commit 0815f1b

Browse files
authored
Merge pull request #12 from damassi/chore/morestuff
fix: Add ability to scroll up and copy
2 parents 51db292 + c4d33b5 commit 0815f1b

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
- Use `asyncio` features, if such is needed
99
- Prefer early returns
1010
- Absolutely no useless comments! Every class and method does not need to be documented (unless it is legitimetly complex or "lib-ish")
11+
- Imports belong at the top of files, not inside functions (unless needed to avoid circular imports)
12+
13+
## Testing Rules
14+
15+
- **Never delete behavior tests to make things pass.** Fix the code or update the tests to reflect new behavior

src/agent_chat_cli/components/user_input.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from textual.app import ComposeResult
33
from textual.widgets import TextArea
44
from textual.binding import Binding
5+
from textual.events import DescendantBlur
56

67
from agent_chat_cli.components.caret import Caret
78
from agent_chat_cli.components.flex import Flex
@@ -10,8 +11,6 @@
1011

1112

1213
class UserInput(Widget):
13-
first_boot = True
14-
1514
BINDINGS = [
1615
Binding("enter", "submit", "Submit", priority=True),
1716
]
@@ -33,6 +32,10 @@ def on_mount(self) -> None:
3332
input_widget = self.query_one(TextArea)
3433
input_widget.focus()
3534

35+
def on_descendant_blur(self, event: DescendantBlur) -> None:
36+
if isinstance(event.widget, TextArea):
37+
event.widget.focus(scroll_visible=False)
38+
3639
async def on_key(self, event) -> None:
3740
if event.key == "ctrl+j":
3841
event.stop()

src/agent_chat_cli/core/ui_state.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
66
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
7+
from agent_chat_cli.components.user_input import UserInput
78

89
if TYPE_CHECKING:
910
from agent_chat_cli.app import AgentChatCLIApp
@@ -39,8 +40,6 @@ def stop_thinking(self, show_cursor: bool = True) -> None:
3940
def show_permission_prompt(
4041
self, tool_name: str, tool_input: dict[str, Any]
4142
) -> None:
42-
from agent_chat_cli.components.user_input import UserInput
43-
4443
thinking_indicator = self.app.query_one(ThinkingIndicator)
4544
thinking_indicator.is_thinking = False
4645

@@ -53,13 +52,20 @@ def show_permission_prompt(
5352
user_input.display = False
5453

5554
def hide_permission_prompt(self) -> None:
56-
from agent_chat_cli.components.user_input import UserInput
57-
5855
permission_prompt = self.app.query_one(ToolPermissionPrompt)
5956
permission_prompt.is_visible = False
6057

6158
user_input = self.app.query_one(UserInput)
6259
user_input.display = True
6360

64-
input_widget = self.app.query_one(TextArea)
61+
self.focus_input()
62+
63+
def focus_input(self) -> None:
64+
user_input = self.app.query_one(UserInput)
65+
input_widget = user_input.query_one(TextArea)
6566
input_widget.focus()
67+
68+
def clear_input(self) -> None:
69+
user_input = self.app.query_one(UserInput)
70+
input_widget = user_input.query_one(TextArea)
71+
input_widget.clear()

tests/core/test_ui_state.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,27 @@ async def test_hide_permission_prompt(self, mock_agent_loop, mock_config):
139139

140140
assert prompt.is_visible is False
141141
assert user_input.display is True
142+
143+
144+
class TestUIStateInput:
145+
async def test_focus_input(self, mock_agent_loop, mock_config):
146+
app = AgentChatCLIApp()
147+
async with app.run_test():
148+
user_input = app.query_one(UserInput)
149+
text_area = user_input.query_one(TextArea)
150+
text_area.blur()
151+
152+
app.ui_state.focus_input()
153+
154+
assert text_area.has_focus is True
155+
156+
async def test_clear_input(self, mock_agent_loop, mock_config):
157+
app = AgentChatCLIApp()
158+
async with app.run_test():
159+
user_input = app.query_one(UserInput)
160+
text_area = user_input.query_one(TextArea)
161+
text_area.insert("some text")
162+
163+
app.ui_state.clear_input()
164+
165+
assert text_area.text == ""

0 commit comments

Comments
 (0)