Coverage for cli/input.py: 67%

1"""

2用户输入模块

3

4负责 prompt_toolkit 键绑定和读取用户输入。

5"""

6 from prompt_toolkit import PromptSession

7 from prompt_toolkit.key_binding import KeyBindings

8

9 _bindings = KeyBindings()

10

11

12@_bindings.add("escape", "enter") # Alt+Enter 或 Esc+Enter 换行

13 def _newline(event):

14 event.current_buffer.insert_text("\n")

15

16

17 def get_input(session_id: str) -> str:

18 """读取一行用户输入，Enter 提交，Alt+Enter 换行。"""

19 prompt_session = PromptSession(key_bindings=_bindings)

20 return prompt_session.prompt(

21 f"[{session_id}] > ",

22 multiline=False,

23 )