-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtui.py
More file actions
76 lines (61 loc) · 2.67 KB
/
tui.py
File metadata and controls
76 lines (61 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from collections.abc import Generator
from prompt_toolkit import print_formatted_text
from prompt_toolkit.completion import CompleteEvent, Completer, Completion
from prompt_toolkit.document import Document
from prompt_toolkit.formatted_text import HTML
from openhands_cli import __version__
from openhands_cli.pt_style import get_cli_style
DEFAULT_STYLE = get_cli_style()
# Available commands with descriptions
COMMANDS = {
"/exit": "Exit the application",
"/help": "Display available commands",
"/clear": "Clear the screen",
"/status": "Display conversation details",
"/new": "Create a new conversation",
}
class CommandCompleter(Completer):
"""Custom completer for commands with interactive dropdown."""
def get_completions(
self, document: Document, complete_event: CompleteEvent
) -> Generator[Completion, None, None]:
text = document.text_before_cursor.lstrip()
if text.startswith("/"):
for command, description in COMMANDS.items():
if command.startswith(text):
yield Completion(
command,
start_position=-len(text),
display_meta=description,
style="bg:ansidarkgray fg:gold",
)
def display_banner(session_id: str) -> None:
print_formatted_text(
HTML(r"""<gold>
___ _ _ _
/ _ \ _ __ ___ _ __ | | | | __ _ _ __ __| |___
| | | | '_ \ / _ \ '_ \| |_| |/ _` | '_ \ / _` / __|
| |_| | |_) | __/ | | | _ | (_| | | | | (_| \__ \
\___ /| .__/ \___|_| |_|_| |_|\__,_|_| |_|\__,_|___/
|_|
</gold>"""),
style=DEFAULT_STYLE,
)
print_formatted_text(HTML(f"<grey>OpenHands CLI v{__version__}</grey>"))
print_formatted_text("")
print_formatted_text(HTML(f"<grey>Initialized conversation {session_id}</grey>"))
print_formatted_text("")
def display_help() -> None:
"""Display help information about available commands."""
print_formatted_text("")
print_formatted_text(HTML("<gold>🤖 OpenHands CLI Help</gold>"))
print_formatted_text(HTML("<grey>Available commands:</grey>"))
print_formatted_text("")
for command, description in COMMANDS.items():
print_formatted_text(HTML(f" <white>{command}</white> - {description}"))
print_formatted_text("")
print_formatted_text(HTML("<grey>Tips:</grey>"))
print_formatted_text(" • Type / and press Tab to see command suggestions")
print_formatted_text(" • Use arrow keys to navigate through suggestions")
print_formatted_text(" • Press Enter to select a command")
print_formatted_text("")