-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.py
More file actions
69 lines (52 loc) · 1.87 KB
/
Copy pathview.py
File metadata and controls
69 lines (52 loc) · 1.87 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
from pathlib import Path
from prompt_toolkit import PromptSession, HTML
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.history import FileHistory
from prompt_toolkit.styles import Style
from prompt_toolkit import print_formatted_text as cprint
STYLE = Style.from_dict({
"prompt": "ansigreen bold",
"thinking": "orange italic",
"info": "blue",
"error": "red",
"debug": "gray",
"reply": "magenta",
})
class View(object):
def __init__(self):
self._completer = None
self._prompt = None
self._history = FileHistory(Path.home() / ".commit_agent_history")
def set_completer_words(self, words: list[str]):
self._completer = WordCompleter(words)
self._prompt = PromptSession(
[("class:prompt", ">>> ")],
history=self._history,
style=STYLE,
completer=self._completer,
complete_while_typing=True,
)
@staticmethod
def cprint(text: str, tag: str | None = "p", end: str = "\n"):
if tag:
text = HTML(f"<{tag}>{text}</{tag}>")
cprint(text, style=STYLE, flush=True, end=end)
def wait_user_input(self) -> str:
return self._prompt.prompt().strip()
def show_thinking(self):
self.cprint("Думаю...", "thinking")
def show_info(self, text: str):
self.cprint(text, "info")
def show_error(self, text: str):
self.cprint(text, "error")
def show_current_commit_message(self, text: str):
self.show_info("Текущее сообщение коммита:")
self.cprint(text)
def show_reply(self, text: str):
self.cprint(text, "reply")
def stream_write(self, chunk: str):
self.cprint(chunk, None, "")
def stream_end(self):
self.cprint("\n", None)
def show_debug(self, text: str):
self.cprint(text, "debug")