mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
diagrams
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Callable, Iterable
|
||||
|
||||
from prompt_toolkit import PromptSession, HTML
|
||||
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
||||
from prompt_toolkit.completion import Completer, Completion, CompleteEvent
|
||||
from prompt_toolkit.completion import Completer, Completion, CompleteEvent, ThreadedCompleter
|
||||
from prompt_toolkit.document import Document
|
||||
from prompt_toolkit.formatted_text import StyleAndTextTuples
|
||||
from prompt_toolkit.history import History, ThreadedHistory, FileHistory, InMemoryHistory
|
||||
@@ -97,34 +97,36 @@ class AutoCompleter:
|
||||
|
||||
def _(event: KeyPressEvent) -> None:
|
||||
buff = event.app.current_buffer
|
||||
|
||||
if buff.complete_state:
|
||||
buff.complete_next()
|
||||
else:
|
||||
completions = list(buff.completer.get_completions(buff.document, CompleteEvent()))
|
||||
if len(completions) == 1:
|
||||
buff.apply_completion(completions[0])
|
||||
else:
|
||||
buff.start_completion(select_first=False)
|
||||
return
|
||||
comps_gen = buff.completer.get_completions(buff.document, CompleteEvent())
|
||||
try:
|
||||
first = next(comps_gen)
|
||||
except StopIteration:
|
||||
return
|
||||
try:
|
||||
_ = next(comps_gen)
|
||||
buff.start_completion(select_first=False)
|
||||
except StopIteration:
|
||||
buff.apply_completion(first)
|
||||
|
||||
kb.add(self.autocomplete_button)(_)
|
||||
|
||||
history: InMemoryHistory | ThreadedHistory
|
||||
|
||||
if self.history_filename:
|
||||
history = ThreadedHistory(FileHistory(self.history_filename))
|
||||
else:
|
||||
history = InMemoryHistory()
|
||||
|
||||
style = Style.from_dict({'valid': '#00ff00', 'invalid': '#ff0000'})
|
||||
|
||||
self._session = PromptSession(
|
||||
history=history,
|
||||
completer=HistoryCompleter(history, all_commands),
|
||||
completer=ThreadedCompleter(HistoryCompleter(history, all_commands)),
|
||||
complete_while_typing=False,
|
||||
key_bindings=kb,
|
||||
auto_suggest=AutoSuggestFromHistory() if self.auto_suggestions else None,
|
||||
style=style if self.command_highlighting else style,
|
||||
style=style if self.command_highlighting else None,
|
||||
lexer=CommandLexer(all_commands) if self.command_highlighting else None,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user