Skip to content

Build and run agents you can see, understand and trust.

feat(tui): add right arrow key to switch questions in ask user ui (#3275)

YuYana8e90fa724fa
diff --git a/src/agentscope/tui/_ask_user.py b/src/agentscope/tui/_ask_user.py
index 7ef20d2e6..6b0b91e3b 100644
--- a/src/agentscope/tui/_ask_user.py
+++ b/src/agentscope/tui/_ask_user.py
@@ -284,7 +284,7 @@ class AskUserUI(Vertical):
"Enter submit answer · Esc choices · Ctrl+C interrupt"
if self._editing_other
else (
- "↑/↓ select · Enter choose · ← previous "
+ "↑/↓ select · Enter choose · ←/→ switch "
"· Ctrl+C interrupt"
)
),
@@ -515,3 +515,12 @@ class AskUserUI(Vertical):
self._question_index -= 1
self._render_form()
self.call_later(self.focus_action)
+ elif event.key == "right" and not self._editing_other:
+ answer = self._answers[self._question_index]
+ answered = answer.selected or answer.other is not None
+ if answered and self._question_index + 1 < len(self._answers):
+ event.stop()
+ event.prevent_default()
+ self._question_index += 1
+ self._render_form()
+ self.call_later(self.focus_action)
diff --git a/tests/tui_test.py b/tests/tui_test.py
index 81369693a..927bc2dfb 100644
--- a/tests/tui_test.py
+++ b/tests/tui_test.py
@@ -956,12 +956,23 @@ class ChatUITest(unittest.IsolatedAsyncioTestCase):
app.query_one(".as-ask-user-preview", Static).display,
)
+ await pilot.press("right")
+ await pilot.pause()
+ self.assertEqual(ask_user._question_index, 0)
+ self.assertListEqual(observed, [])
+
await pilot.press("enter")
await pilot.pause()
self.assertIn(
"Enable the render pipeline.",
str(options.get_option_at_index(0).prompt),
)
+ await pilot.press("left")
+ await pilot.pause()
+ self.assertEqual(ask_user._question_index, 0)
+ await pilot.press("right")
+ await pilot.pause()
+ self.assertEqual(ask_user._question_index, 1)
await pilot.press("enter", "down", "down", "down", "enter")
await pilot.pause()