omni-ai-cli 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +615 -2
- package/bin/ai.js +84 -0
- package/docs/README.en.md +615 -0
- package/docs/README.es.md +618 -0
- package/docs/README.fr.md +630 -0
- package/omni_ai/__init__.py +1 -0
- package/omni_ai/__main__.py +6 -0
- package/omni_ai/chat.py +1458 -0
- package/omni_ai/cli.py +991 -0
- package/omni_ai/config.py +531 -0
- package/omni_ai/deepseek.py +57 -0
- package/omni_ai/grok.py +111 -0
- package/omni_ai/onboarding.py +196 -0
- package/omni_ai/openrouter.py +335 -0
- package/omni_ai/osutils.py +86 -0
- package/omni_ai/pii.py +281 -0
- package/omni_ai/profiles.json +69 -0
- package/omni_ai/skills.py +124 -0
- package/omni_ai/sync.py +199 -0
- package/omni_ai/tools.py +75 -0
- package/omni_ai/ui.py +595 -0
- package/omni_ai/usage.py +305 -0
- package/omni_ai/vendor/prompt_toolkit/LICENSE +27 -0
- package/omni_ai/vendor/prompt_toolkit/__init__.py +52 -0
- package/omni_ai/vendor/prompt_toolkit/application/__init__.py +32 -0
- package/omni_ai/vendor/prompt_toolkit/application/application.py +1626 -0
- package/omni_ai/vendor/prompt_toolkit/application/current.py +195 -0
- package/omni_ai/vendor/prompt_toolkit/application/dummy.py +55 -0
- package/omni_ai/vendor/prompt_toolkit/application/run_in_terminal.py +114 -0
- package/omni_ai/vendor/prompt_toolkit/auto_suggest.py +177 -0
- package/omni_ai/vendor/prompt_toolkit/buffer.py +2029 -0
- package/omni_ai/vendor/prompt_toolkit/cache.py +127 -0
- package/omni_ai/vendor/prompt_toolkit/clipboard/__init__.py +17 -0
- package/omni_ai/vendor/prompt_toolkit/clipboard/base.py +109 -0
- package/omni_ai/vendor/prompt_toolkit/clipboard/in_memory.py +44 -0
- package/omni_ai/vendor/prompt_toolkit/clipboard/pyperclip.py +42 -0
- package/omni_ai/vendor/prompt_toolkit/completion/__init__.py +43 -0
- package/omni_ai/vendor/prompt_toolkit/completion/base.py +438 -0
- package/omni_ai/vendor/prompt_toolkit/completion/deduplicate.py +45 -0
- package/omni_ai/vendor/prompt_toolkit/completion/filesystem.py +118 -0
- package/omni_ai/vendor/prompt_toolkit/completion/fuzzy_completer.py +213 -0
- package/omni_ai/vendor/prompt_toolkit/completion/nested.py +109 -0
- package/omni_ai/vendor/prompt_toolkit/completion/word_completer.py +94 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/__init__.py +0 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/completers/__init__.py +5 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/completers/system.py +64 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/__init__.py +80 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/compiler.py +579 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/completion.py +100 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/lexer.py +94 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/regex_parser.py +279 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/regular_languages/validation.py +60 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/ssh/__init__.py +8 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/ssh/server.py +178 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/telnet/__init__.py +7 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/telnet/log.py +13 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/telnet/protocol.py +209 -0
- package/omni_ai/vendor/prompt_toolkit/contrib/telnet/server.py +428 -0
- package/omni_ai/vendor/prompt_toolkit/cursor_shapes.py +117 -0
- package/omni_ai/vendor/prompt_toolkit/data_structures.py +18 -0
- package/omni_ai/vendor/prompt_toolkit/document.py +1182 -0
- package/omni_ai/vendor/prompt_toolkit/enums.py +19 -0
- package/omni_ai/vendor/prompt_toolkit/eventloop/__init__.py +31 -0
- package/omni_ai/vendor/prompt_toolkit/eventloop/async_generator.py +125 -0
- package/omni_ai/vendor/prompt_toolkit/eventloop/inputhook.py +191 -0
- package/omni_ai/vendor/prompt_toolkit/eventloop/utils.py +101 -0
- package/omni_ai/vendor/prompt_toolkit/eventloop/win32.py +72 -0
- package/omni_ai/vendor/prompt_toolkit/filters/__init__.py +71 -0
- package/omni_ai/vendor/prompt_toolkit/filters/app.py +419 -0
- package/omni_ai/vendor/prompt_toolkit/filters/base.py +261 -0
- package/omni_ai/vendor/prompt_toolkit/filters/cli.py +65 -0
- package/omni_ai/vendor/prompt_toolkit/filters/utils.py +41 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/__init__.py +59 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/ansi.py +297 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/base.py +179 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/html.py +145 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/pygments.py +32 -0
- package/omni_ai/vendor/prompt_toolkit/formatted_text/utils.py +103 -0
- package/omni_ai/vendor/prompt_toolkit/history.py +306 -0
- package/omni_ai/vendor/prompt_toolkit/input/__init__.py +14 -0
- package/omni_ai/vendor/prompt_toolkit/input/ansi_escape_sequences.py +344 -0
- package/omni_ai/vendor/prompt_toolkit/input/base.py +153 -0
- package/omni_ai/vendor/prompt_toolkit/input/defaults.py +79 -0
- package/omni_ai/vendor/prompt_toolkit/input/posix_pipe.py +118 -0
- package/omni_ai/vendor/prompt_toolkit/input/posix_utils.py +97 -0
- package/omni_ai/vendor/prompt_toolkit/input/typeahead.py +78 -0
- package/omni_ai/vendor/prompt_toolkit/input/vt100.py +309 -0
- package/omni_ai/vendor/prompt_toolkit/input/vt100_parser.py +250 -0
- package/omni_ai/vendor/prompt_toolkit/input/win32.py +749 -0
- package/omni_ai/vendor/prompt_toolkit/input/win32_pipe.py +156 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/__init__.py +22 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/__init__.py +0 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/auto_suggest.py +66 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/basic.py +257 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/completion.py +206 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/cpr.py +30 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/emacs.py +563 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/focus.py +26 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/mouse.py +348 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/named_commands.py +691 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/open_in_editor.py +52 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/page_navigation.py +85 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/scroll.py +190 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/search.py +96 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/bindings/vi.py +2233 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/defaults.py +63 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/digraphs.py +1378 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/emacs_state.py +36 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/key_bindings.py +670 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/key_processor.py +526 -0
- package/omni_ai/vendor/prompt_toolkit/key_binding/vi_state.py +107 -0
- package/omni_ai/vendor/prompt_toolkit/keys.py +222 -0
- package/omni_ai/vendor/prompt_toolkit/layout/__init__.py +147 -0
- package/omni_ai/vendor/prompt_toolkit/layout/containers.py +2738 -0
- package/omni_ai/vendor/prompt_toolkit/layout/controls.py +945 -0
- package/omni_ai/vendor/prompt_toolkit/layout/dimension.py +220 -0
- package/omni_ai/vendor/prompt_toolkit/layout/dummy.py +40 -0
- package/omni_ai/vendor/prompt_toolkit/layout/layout.py +412 -0
- package/omni_ai/vendor/prompt_toolkit/layout/margins.py +304 -0
- package/omni_ai/vendor/prompt_toolkit/layout/menus.py +748 -0
- package/omni_ai/vendor/prompt_toolkit/layout/mouse_handlers.py +56 -0
- package/omni_ai/vendor/prompt_toolkit/layout/processors.py +1010 -0
- package/omni_ai/vendor/prompt_toolkit/layout/screen.py +323 -0
- package/omni_ai/vendor/prompt_toolkit/layout/scrollable_pane.py +494 -0
- package/omni_ai/vendor/prompt_toolkit/layout/utils.py +80 -0
- package/omni_ai/vendor/prompt_toolkit/lexers/__init__.py +21 -0
- package/omni_ai/vendor/prompt_toolkit/lexers/base.py +85 -0
- package/omni_ai/vendor/prompt_toolkit/lexers/pygments.py +328 -0
- package/omni_ai/vendor/prompt_toolkit/log.py +13 -0
- package/omni_ai/vendor/prompt_toolkit/mouse_events.py +85 -0
- package/omni_ai/vendor/prompt_toolkit/output/__init__.py +15 -0
- package/omni_ai/vendor/prompt_toolkit/output/base.py +332 -0
- package/omni_ai/vendor/prompt_toolkit/output/color_depth.py +64 -0
- package/omni_ai/vendor/prompt_toolkit/output/conemu.py +65 -0
- package/omni_ai/vendor/prompt_toolkit/output/defaults.py +106 -0
- package/omni_ai/vendor/prompt_toolkit/output/flush_stdout.py +87 -0
- package/omni_ai/vendor/prompt_toolkit/output/plain_text.py +143 -0
- package/omni_ai/vendor/prompt_toolkit/output/vt100.py +748 -0
- package/omni_ai/vendor/prompt_toolkit/output/win32.py +683 -0
- package/omni_ai/vendor/prompt_toolkit/output/windows10.py +128 -0
- package/omni_ai/vendor/prompt_toolkit/patch_stdout.py +297 -0
- package/omni_ai/vendor/prompt_toolkit/py.typed +0 -0
- package/omni_ai/vendor/prompt_toolkit/renderer.py +814 -0
- package/omni_ai/vendor/prompt_toolkit/search.py +226 -0
- package/omni_ai/vendor/prompt_toolkit/selection.py +58 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/__init__.py +46 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/dialogs.py +330 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/progress_bar/__init__.py +33 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/progress_bar/base.py +449 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/progress_bar/formatters.py +431 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/prompt.py +1513 -0
- package/omni_ai/vendor/prompt_toolkit/shortcuts/utils.py +239 -0
- package/omni_ai/vendor/prompt_toolkit/styles/__init__.py +67 -0
- package/omni_ai/vendor/prompt_toolkit/styles/base.py +184 -0
- package/omni_ai/vendor/prompt_toolkit/styles/defaults.py +236 -0
- package/omni_ai/vendor/prompt_toolkit/styles/named_colors.py +162 -0
- package/omni_ai/vendor/prompt_toolkit/styles/pygments.py +70 -0
- package/omni_ai/vendor/prompt_toolkit/styles/style.py +401 -0
- package/omni_ai/vendor/prompt_toolkit/styles/style_transformation.py +374 -0
- package/omni_ai/vendor/prompt_toolkit/token.py +9 -0
- package/omni_ai/vendor/prompt_toolkit/utils.py +327 -0
- package/omni_ai/vendor/prompt_toolkit/validation.py +192 -0
- package/omni_ai/vendor/prompt_toolkit/widgets/__init__.py +63 -0
- package/omni_ai/vendor/prompt_toolkit/widgets/base.py +995 -0
- package/omni_ai/vendor/prompt_toolkit/widgets/dialogs.py +108 -0
- package/omni_ai/vendor/prompt_toolkit/widgets/menus.py +374 -0
- package/omni_ai/vendor/prompt_toolkit/widgets/toolbars.py +370 -0
- package/omni_ai/vendor/prompt_toolkit/win32_types.py +229 -0
- package/omni_ai/vendor/wcwidth/LICENSE +27 -0
- package/omni_ai/vendor/wcwidth/__init__.py +29 -0
- package/omni_ai/vendor/wcwidth/table_vs16.py +125 -0
- package/omni_ai/vendor/wcwidth/table_wide.py +1493 -0
- package/omni_ai/vendor/wcwidth/table_zero.py +4843 -0
- package/omni_ai/vendor/wcwidth/unicode_versions.py +38 -0
- package/omni_ai/vendor/wcwidth/wcwidth.py +345 -0
- package/package.json +40 -4
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from prompt_toolkit.application.current import get_app
|
|
6
|
+
from prompt_toolkit.buffer import Buffer
|
|
7
|
+
from prompt_toolkit.enums import SYSTEM_BUFFER
|
|
8
|
+
from prompt_toolkit.filters import (
|
|
9
|
+
Condition,
|
|
10
|
+
FilterOrBool,
|
|
11
|
+
emacs_mode,
|
|
12
|
+
has_arg,
|
|
13
|
+
has_completions,
|
|
14
|
+
has_focus,
|
|
15
|
+
has_validation_error,
|
|
16
|
+
to_filter,
|
|
17
|
+
vi_mode,
|
|
18
|
+
vi_navigation_mode,
|
|
19
|
+
)
|
|
20
|
+
from prompt_toolkit.formatted_text import (
|
|
21
|
+
AnyFormattedText,
|
|
22
|
+
StyleAndTextTuples,
|
|
23
|
+
fragment_list_len,
|
|
24
|
+
to_formatted_text,
|
|
25
|
+
)
|
|
26
|
+
from prompt_toolkit.key_binding.key_bindings import (
|
|
27
|
+
ConditionalKeyBindings,
|
|
28
|
+
KeyBindings,
|
|
29
|
+
KeyBindingsBase,
|
|
30
|
+
merge_key_bindings,
|
|
31
|
+
)
|
|
32
|
+
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
|
|
33
|
+
from prompt_toolkit.key_binding.vi_state import InputMode
|
|
34
|
+
from prompt_toolkit.keys import Keys
|
|
35
|
+
from prompt_toolkit.layout.containers import ConditionalContainer, Container, Window
|
|
36
|
+
from prompt_toolkit.layout.controls import (
|
|
37
|
+
BufferControl,
|
|
38
|
+
FormattedTextControl,
|
|
39
|
+
SearchBufferControl,
|
|
40
|
+
UIContent,
|
|
41
|
+
UIControl,
|
|
42
|
+
)
|
|
43
|
+
from prompt_toolkit.layout.dimension import Dimension
|
|
44
|
+
from prompt_toolkit.layout.processors import BeforeInput
|
|
45
|
+
from prompt_toolkit.lexers import SimpleLexer
|
|
46
|
+
from prompt_toolkit.search import SearchDirection
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"ArgToolbar",
|
|
50
|
+
"CompletionsToolbar",
|
|
51
|
+
"FormattedTextToolbar",
|
|
52
|
+
"SearchToolbar",
|
|
53
|
+
"SystemToolbar",
|
|
54
|
+
"ValidationToolbar",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
E = KeyPressEvent
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class FormattedTextToolbar(Window):
|
|
61
|
+
def __init__(self, text: AnyFormattedText, style: str = "", **kw: Any) -> None:
|
|
62
|
+
# Note: The style needs to be applied to the toolbar as a whole, not
|
|
63
|
+
# just the `FormattedTextControl`.
|
|
64
|
+
super().__init__(
|
|
65
|
+
FormattedTextControl(text, **kw),
|
|
66
|
+
style=style,
|
|
67
|
+
dont_extend_height=True,
|
|
68
|
+
height=Dimension(min=1),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class SystemToolbar:
|
|
73
|
+
"""
|
|
74
|
+
Toolbar for a system prompt.
|
|
75
|
+
|
|
76
|
+
:param prompt: Prompt to be displayed to the user.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
def __init__(
|
|
80
|
+
self,
|
|
81
|
+
prompt: AnyFormattedText = "Shell command: ",
|
|
82
|
+
enable_global_bindings: FilterOrBool = True,
|
|
83
|
+
) -> None:
|
|
84
|
+
self.prompt = prompt
|
|
85
|
+
self.enable_global_bindings = to_filter(enable_global_bindings)
|
|
86
|
+
|
|
87
|
+
self.system_buffer = Buffer(name=SYSTEM_BUFFER)
|
|
88
|
+
|
|
89
|
+
self._bindings = self._build_key_bindings()
|
|
90
|
+
|
|
91
|
+
self.buffer_control = BufferControl(
|
|
92
|
+
buffer=self.system_buffer,
|
|
93
|
+
lexer=SimpleLexer(style="class:system-toolbar.text"),
|
|
94
|
+
input_processors=[
|
|
95
|
+
BeforeInput(lambda: self.prompt, style="class:system-toolbar")
|
|
96
|
+
],
|
|
97
|
+
key_bindings=self._bindings,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
self.window = Window(
|
|
101
|
+
self.buffer_control, height=1, style="class:system-toolbar"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.container = ConditionalContainer(
|
|
105
|
+
content=self.window, filter=has_focus(self.system_buffer)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def _get_display_before_text(self) -> StyleAndTextTuples:
|
|
109
|
+
return [
|
|
110
|
+
("class:system-toolbar", "Shell command: "),
|
|
111
|
+
("class:system-toolbar.text", self.system_buffer.text),
|
|
112
|
+
("", "\n"),
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
def _build_key_bindings(self) -> KeyBindingsBase:
|
|
116
|
+
focused = has_focus(self.system_buffer)
|
|
117
|
+
|
|
118
|
+
# Emacs
|
|
119
|
+
emacs_bindings = KeyBindings()
|
|
120
|
+
handle = emacs_bindings.add
|
|
121
|
+
|
|
122
|
+
@handle("escape", filter=focused)
|
|
123
|
+
@handle("c-g", filter=focused)
|
|
124
|
+
@handle("c-c", filter=focused)
|
|
125
|
+
def _cancel(event: E) -> None:
|
|
126
|
+
"Hide system prompt."
|
|
127
|
+
self.system_buffer.reset()
|
|
128
|
+
event.app.layout.focus_last()
|
|
129
|
+
|
|
130
|
+
@handle("enter", filter=focused)
|
|
131
|
+
async def _accept(event: E) -> None:
|
|
132
|
+
"Run system command."
|
|
133
|
+
await event.app.run_system_command(
|
|
134
|
+
self.system_buffer.text,
|
|
135
|
+
display_before_text=self._get_display_before_text(),
|
|
136
|
+
)
|
|
137
|
+
self.system_buffer.reset(append_to_history=True)
|
|
138
|
+
event.app.layout.focus_last()
|
|
139
|
+
|
|
140
|
+
# Vi.
|
|
141
|
+
vi_bindings = KeyBindings()
|
|
142
|
+
handle = vi_bindings.add
|
|
143
|
+
|
|
144
|
+
@handle("escape", filter=focused)
|
|
145
|
+
@handle("c-c", filter=focused)
|
|
146
|
+
def _cancel_vi(event: E) -> None:
|
|
147
|
+
"Hide system prompt."
|
|
148
|
+
event.app.vi_state.input_mode = InputMode.NAVIGATION
|
|
149
|
+
self.system_buffer.reset()
|
|
150
|
+
event.app.layout.focus_last()
|
|
151
|
+
|
|
152
|
+
@handle("enter", filter=focused)
|
|
153
|
+
async def _accept_vi(event: E) -> None:
|
|
154
|
+
"Run system command."
|
|
155
|
+
event.app.vi_state.input_mode = InputMode.NAVIGATION
|
|
156
|
+
await event.app.run_system_command(
|
|
157
|
+
self.system_buffer.text,
|
|
158
|
+
display_before_text=self._get_display_before_text(),
|
|
159
|
+
)
|
|
160
|
+
self.system_buffer.reset(append_to_history=True)
|
|
161
|
+
event.app.layout.focus_last()
|
|
162
|
+
|
|
163
|
+
# Global bindings. (Listen to these bindings, even when this widget is
|
|
164
|
+
# not focussed.)
|
|
165
|
+
global_bindings = KeyBindings()
|
|
166
|
+
handle = global_bindings.add
|
|
167
|
+
|
|
168
|
+
@handle(Keys.Escape, "!", filter=~focused & emacs_mode, is_global=True)
|
|
169
|
+
def _focus_me(event: E) -> None:
|
|
170
|
+
"M-'!' will focus this user control."
|
|
171
|
+
event.app.layout.focus(self.window)
|
|
172
|
+
|
|
173
|
+
@handle("!", filter=~focused & vi_mode & vi_navigation_mode, is_global=True)
|
|
174
|
+
def _focus_me_vi(event: E) -> None:
|
|
175
|
+
"Focus."
|
|
176
|
+
event.app.vi_state.input_mode = InputMode.INSERT
|
|
177
|
+
event.app.layout.focus(self.window)
|
|
178
|
+
|
|
179
|
+
return merge_key_bindings(
|
|
180
|
+
[
|
|
181
|
+
ConditionalKeyBindings(emacs_bindings, emacs_mode),
|
|
182
|
+
ConditionalKeyBindings(vi_bindings, vi_mode),
|
|
183
|
+
ConditionalKeyBindings(global_bindings, self.enable_global_bindings),
|
|
184
|
+
]
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def __pt_container__(self) -> Container:
|
|
188
|
+
return self.container
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class ArgToolbar:
|
|
192
|
+
def __init__(self) -> None:
|
|
193
|
+
def get_formatted_text() -> StyleAndTextTuples:
|
|
194
|
+
arg = get_app().key_processor.arg or ""
|
|
195
|
+
if arg == "-":
|
|
196
|
+
arg = "-1"
|
|
197
|
+
|
|
198
|
+
return [
|
|
199
|
+
("class:arg-toolbar", "Repeat: "),
|
|
200
|
+
("class:arg-toolbar.text", arg),
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
self.window = Window(FormattedTextControl(get_formatted_text), height=1)
|
|
204
|
+
|
|
205
|
+
self.container = ConditionalContainer(content=self.window, filter=has_arg)
|
|
206
|
+
|
|
207
|
+
def __pt_container__(self) -> Container:
|
|
208
|
+
return self.container
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class SearchToolbar:
|
|
212
|
+
"""
|
|
213
|
+
:param vi_mode: Display '/' and '?' instead of I-search.
|
|
214
|
+
:param ignore_case: Search case insensitive.
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
def __init__(
|
|
218
|
+
self,
|
|
219
|
+
search_buffer: Buffer | None = None,
|
|
220
|
+
vi_mode: bool = False,
|
|
221
|
+
text_if_not_searching: AnyFormattedText = "",
|
|
222
|
+
forward_search_prompt: AnyFormattedText = "I-search: ",
|
|
223
|
+
backward_search_prompt: AnyFormattedText = "I-search backward: ",
|
|
224
|
+
ignore_case: FilterOrBool = False,
|
|
225
|
+
) -> None:
|
|
226
|
+
if search_buffer is None:
|
|
227
|
+
search_buffer = Buffer()
|
|
228
|
+
|
|
229
|
+
@Condition
|
|
230
|
+
def is_searching() -> bool:
|
|
231
|
+
return self.control in get_app().layout.search_links
|
|
232
|
+
|
|
233
|
+
def get_before_input() -> AnyFormattedText:
|
|
234
|
+
if not is_searching():
|
|
235
|
+
return text_if_not_searching
|
|
236
|
+
elif (
|
|
237
|
+
self.control.searcher_search_state.direction == SearchDirection.BACKWARD
|
|
238
|
+
):
|
|
239
|
+
return "?" if vi_mode else backward_search_prompt
|
|
240
|
+
else:
|
|
241
|
+
return "/" if vi_mode else forward_search_prompt
|
|
242
|
+
|
|
243
|
+
self.search_buffer = search_buffer
|
|
244
|
+
|
|
245
|
+
self.control = SearchBufferControl(
|
|
246
|
+
buffer=search_buffer,
|
|
247
|
+
input_processors=[
|
|
248
|
+
BeforeInput(get_before_input, style="class:search-toolbar.prompt")
|
|
249
|
+
],
|
|
250
|
+
lexer=SimpleLexer(style="class:search-toolbar.text"),
|
|
251
|
+
ignore_case=ignore_case,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
self.container = ConditionalContainer(
|
|
255
|
+
content=Window(self.control, height=1, style="class:search-toolbar"),
|
|
256
|
+
filter=is_searching,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
def __pt_container__(self) -> Container:
|
|
260
|
+
return self.container
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class _CompletionsToolbarControl(UIControl):
|
|
264
|
+
def create_content(self, width: int, height: int) -> UIContent:
|
|
265
|
+
all_fragments: StyleAndTextTuples = []
|
|
266
|
+
|
|
267
|
+
complete_state = get_app().current_buffer.complete_state
|
|
268
|
+
if complete_state:
|
|
269
|
+
completions = complete_state.completions
|
|
270
|
+
index = complete_state.complete_index # Can be None!
|
|
271
|
+
|
|
272
|
+
# Width of the completions without the left/right arrows in the margins.
|
|
273
|
+
content_width = width - 6
|
|
274
|
+
|
|
275
|
+
# Booleans indicating whether we stripped from the left/right
|
|
276
|
+
cut_left = False
|
|
277
|
+
cut_right = False
|
|
278
|
+
|
|
279
|
+
# Create Menu content.
|
|
280
|
+
fragments: StyleAndTextTuples = []
|
|
281
|
+
|
|
282
|
+
for i, c in enumerate(completions):
|
|
283
|
+
# When there is no more place for the next completion
|
|
284
|
+
if fragment_list_len(fragments) + len(c.display_text) >= content_width:
|
|
285
|
+
# If the current one was not yet displayed, page to the next sequence.
|
|
286
|
+
if i <= (index or 0):
|
|
287
|
+
fragments = []
|
|
288
|
+
cut_left = True
|
|
289
|
+
# If the current one is visible, stop here.
|
|
290
|
+
else:
|
|
291
|
+
cut_right = True
|
|
292
|
+
break
|
|
293
|
+
|
|
294
|
+
fragments.extend(
|
|
295
|
+
to_formatted_text(
|
|
296
|
+
c.display_text,
|
|
297
|
+
style=(
|
|
298
|
+
"class:completion-toolbar.completion.current"
|
|
299
|
+
if i == index
|
|
300
|
+
else "class:completion-toolbar.completion"
|
|
301
|
+
),
|
|
302
|
+
)
|
|
303
|
+
)
|
|
304
|
+
fragments.append(("", " "))
|
|
305
|
+
|
|
306
|
+
# Extend/strip until the content width.
|
|
307
|
+
fragments.append(("", " " * (content_width - fragment_list_len(fragments))))
|
|
308
|
+
fragments = fragments[:content_width]
|
|
309
|
+
|
|
310
|
+
# Return fragments
|
|
311
|
+
all_fragments.append(("", " "))
|
|
312
|
+
all_fragments.append(
|
|
313
|
+
("class:completion-toolbar.arrow", "<" if cut_left else " ")
|
|
314
|
+
)
|
|
315
|
+
all_fragments.append(("", " "))
|
|
316
|
+
|
|
317
|
+
all_fragments.extend(fragments)
|
|
318
|
+
|
|
319
|
+
all_fragments.append(("", " "))
|
|
320
|
+
all_fragments.append(
|
|
321
|
+
("class:completion-toolbar.arrow", ">" if cut_right else " ")
|
|
322
|
+
)
|
|
323
|
+
all_fragments.append(("", " "))
|
|
324
|
+
|
|
325
|
+
def get_line(i: int) -> StyleAndTextTuples:
|
|
326
|
+
return all_fragments
|
|
327
|
+
|
|
328
|
+
return UIContent(get_line=get_line, line_count=1)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
class CompletionsToolbar:
|
|
332
|
+
def __init__(self) -> None:
|
|
333
|
+
self.container = ConditionalContainer(
|
|
334
|
+
content=Window(
|
|
335
|
+
_CompletionsToolbarControl(), height=1, style="class:completion-toolbar"
|
|
336
|
+
),
|
|
337
|
+
filter=has_completions,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
def __pt_container__(self) -> Container:
|
|
341
|
+
return self.container
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class ValidationToolbar:
|
|
345
|
+
def __init__(self, show_position: bool = False) -> None:
|
|
346
|
+
def get_formatted_text() -> StyleAndTextTuples:
|
|
347
|
+
buff = get_app().current_buffer
|
|
348
|
+
|
|
349
|
+
if buff.validation_error:
|
|
350
|
+
row, column = buff.document.translate_index_to_position(
|
|
351
|
+
buff.validation_error.cursor_position
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
if show_position:
|
|
355
|
+
text = f"{buff.validation_error.message} (line={row + 1} column={column + 1})"
|
|
356
|
+
else:
|
|
357
|
+
text = buff.validation_error.message
|
|
358
|
+
|
|
359
|
+
return [("class:validation-toolbar", text)]
|
|
360
|
+
else:
|
|
361
|
+
return []
|
|
362
|
+
|
|
363
|
+
self.control = FormattedTextControl(get_formatted_text)
|
|
364
|
+
|
|
365
|
+
self.container = ConditionalContainer(
|
|
366
|
+
content=Window(self.control, height=1), filter=has_validation_error
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
def __pt_container__(self) -> Container:
|
|
370
|
+
return self.container
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ctypes import Structure, Union, c_char, c_long, c_short, c_ulong
|
|
4
|
+
from ctypes.wintypes import BOOL, DWORD, LPVOID, WCHAR, WORD
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
# Input/Output standard device numbers. Note that these are not handle objects.
|
|
8
|
+
# It's the `windll.kernel32.GetStdHandle` system call that turns them into a
|
|
9
|
+
# real handle object.
|
|
10
|
+
STD_INPUT_HANDLE = c_ulong(-10)
|
|
11
|
+
STD_OUTPUT_HANDLE = c_ulong(-11)
|
|
12
|
+
STD_ERROR_HANDLE = c_ulong(-12)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class COORD(Structure):
|
|
16
|
+
"""
|
|
17
|
+
Struct in wincon.h
|
|
18
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119(v=vs.85).aspx
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
X: int
|
|
23
|
+
Y: int
|
|
24
|
+
|
|
25
|
+
_fields_ = [
|
|
26
|
+
("X", c_short), # Short
|
|
27
|
+
("Y", c_short), # Short
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
def __repr__(self) -> str:
|
|
31
|
+
return "{}(X={!r}, Y={!r}, type_x={!r}, type_y={!r})".format(
|
|
32
|
+
self.__class__.__name__,
|
|
33
|
+
self.X,
|
|
34
|
+
self.Y,
|
|
35
|
+
type(self.X),
|
|
36
|
+
type(self.Y),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class UNICODE_OR_ASCII(Union):
|
|
41
|
+
if TYPE_CHECKING:
|
|
42
|
+
AsciiChar: bytes
|
|
43
|
+
UnicodeChar: str
|
|
44
|
+
|
|
45
|
+
_fields_ = [
|
|
46
|
+
("AsciiChar", c_char),
|
|
47
|
+
("UnicodeChar", WCHAR),
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class KEY_EVENT_RECORD(Structure):
|
|
52
|
+
"""
|
|
53
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684166(v=vs.85).aspx
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
if TYPE_CHECKING:
|
|
57
|
+
KeyDown: int
|
|
58
|
+
RepeatCount: int
|
|
59
|
+
VirtualKeyCode: int
|
|
60
|
+
VirtualScanCode: int
|
|
61
|
+
uChar: UNICODE_OR_ASCII
|
|
62
|
+
ControlKeyState: int
|
|
63
|
+
|
|
64
|
+
_fields_ = [
|
|
65
|
+
("KeyDown", c_long), # bool
|
|
66
|
+
("RepeatCount", c_short), # word
|
|
67
|
+
("VirtualKeyCode", c_short), # word
|
|
68
|
+
("VirtualScanCode", c_short), # word
|
|
69
|
+
("uChar", UNICODE_OR_ASCII), # Unicode or ASCII.
|
|
70
|
+
("ControlKeyState", c_long), # double word
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class MOUSE_EVENT_RECORD(Structure):
|
|
75
|
+
"""
|
|
76
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684239(v=vs.85).aspx
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if TYPE_CHECKING:
|
|
80
|
+
MousePosition: COORD
|
|
81
|
+
ButtonState: int
|
|
82
|
+
ControlKeyState: int
|
|
83
|
+
EventFlags: int
|
|
84
|
+
|
|
85
|
+
_fields_ = [
|
|
86
|
+
("MousePosition", COORD),
|
|
87
|
+
("ButtonState", c_long), # dword
|
|
88
|
+
("ControlKeyState", c_long), # dword
|
|
89
|
+
("EventFlags", c_long), # dword
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class WINDOW_BUFFER_SIZE_RECORD(Structure):
|
|
94
|
+
"""
|
|
95
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687093(v=vs.85).aspx
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
if TYPE_CHECKING:
|
|
99
|
+
Size: COORD
|
|
100
|
+
|
|
101
|
+
_fields_ = [("Size", COORD)]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class MENU_EVENT_RECORD(Structure):
|
|
105
|
+
"""
|
|
106
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684213(v=vs.85).aspx
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
if TYPE_CHECKING:
|
|
110
|
+
CommandId: int
|
|
111
|
+
|
|
112
|
+
_fields_ = [("CommandId", c_long)] # uint
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class FOCUS_EVENT_RECORD(Structure):
|
|
116
|
+
"""
|
|
117
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683149(v=vs.85).aspx
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
if TYPE_CHECKING:
|
|
121
|
+
SetFocus: int
|
|
122
|
+
|
|
123
|
+
_fields_ = [("SetFocus", c_long)] # bool
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class EVENT_RECORD(Union):
|
|
127
|
+
if TYPE_CHECKING:
|
|
128
|
+
KeyEvent: KEY_EVENT_RECORD
|
|
129
|
+
MouseEvent: MOUSE_EVENT_RECORD
|
|
130
|
+
WindowBufferSizeEvent: WINDOW_BUFFER_SIZE_RECORD
|
|
131
|
+
MenuEvent: MENU_EVENT_RECORD
|
|
132
|
+
FocusEvent: FOCUS_EVENT_RECORD
|
|
133
|
+
|
|
134
|
+
_fields_ = [
|
|
135
|
+
("KeyEvent", KEY_EVENT_RECORD),
|
|
136
|
+
("MouseEvent", MOUSE_EVENT_RECORD),
|
|
137
|
+
("WindowBufferSizeEvent", WINDOW_BUFFER_SIZE_RECORD),
|
|
138
|
+
("MenuEvent", MENU_EVENT_RECORD),
|
|
139
|
+
("FocusEvent", FOCUS_EVENT_RECORD),
|
|
140
|
+
]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class INPUT_RECORD(Structure):
|
|
144
|
+
"""
|
|
145
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
if TYPE_CHECKING:
|
|
149
|
+
EventType: int
|
|
150
|
+
Event: EVENT_RECORD
|
|
151
|
+
|
|
152
|
+
_fields_ = [("EventType", c_short), ("Event", EVENT_RECORD)] # word # Union.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
EventTypes = {
|
|
156
|
+
1: "KeyEvent",
|
|
157
|
+
2: "MouseEvent",
|
|
158
|
+
4: "WindowBufferSizeEvent",
|
|
159
|
+
8: "MenuEvent",
|
|
160
|
+
16: "FocusEvent",
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class SMALL_RECT(Structure):
|
|
165
|
+
"""struct in wincon.h."""
|
|
166
|
+
|
|
167
|
+
if TYPE_CHECKING:
|
|
168
|
+
Left: int
|
|
169
|
+
Top: int
|
|
170
|
+
Right: int
|
|
171
|
+
Bottom: int
|
|
172
|
+
|
|
173
|
+
_fields_ = [
|
|
174
|
+
("Left", c_short),
|
|
175
|
+
("Top", c_short),
|
|
176
|
+
("Right", c_short),
|
|
177
|
+
("Bottom", c_short),
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
|
|
182
|
+
"""struct in wincon.h."""
|
|
183
|
+
|
|
184
|
+
if TYPE_CHECKING:
|
|
185
|
+
dwSize: COORD
|
|
186
|
+
dwCursorPosition: COORD
|
|
187
|
+
wAttributes: int
|
|
188
|
+
srWindow: SMALL_RECT
|
|
189
|
+
dwMaximumWindowSize: COORD
|
|
190
|
+
|
|
191
|
+
_fields_ = [
|
|
192
|
+
("dwSize", COORD),
|
|
193
|
+
("dwCursorPosition", COORD),
|
|
194
|
+
("wAttributes", WORD),
|
|
195
|
+
("srWindow", SMALL_RECT),
|
|
196
|
+
("dwMaximumWindowSize", COORD),
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
def __repr__(self) -> str:
|
|
200
|
+
return "CONSOLE_SCREEN_BUFFER_INFO({!r},{!r},{!r},{!r},{!r},{!r},{!r},{!r},{!r},{!r},{!r})".format(
|
|
201
|
+
self.dwSize.Y,
|
|
202
|
+
self.dwSize.X,
|
|
203
|
+
self.dwCursorPosition.Y,
|
|
204
|
+
self.dwCursorPosition.X,
|
|
205
|
+
self.wAttributes,
|
|
206
|
+
self.srWindow.Top,
|
|
207
|
+
self.srWindow.Left,
|
|
208
|
+
self.srWindow.Bottom,
|
|
209
|
+
self.srWindow.Right,
|
|
210
|
+
self.dwMaximumWindowSize.Y,
|
|
211
|
+
self.dwMaximumWindowSize.X,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class SECURITY_ATTRIBUTES(Structure):
|
|
216
|
+
"""
|
|
217
|
+
http://msdn.microsoft.com/en-us/library/windows/desktop/aa379560(v=vs.85).aspx
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
if TYPE_CHECKING:
|
|
221
|
+
nLength: int
|
|
222
|
+
lpSecurityDescriptor: int
|
|
223
|
+
bInheritHandle: int # BOOL comes back as 'int'.
|
|
224
|
+
|
|
225
|
+
_fields_ = [
|
|
226
|
+
("nLength", DWORD),
|
|
227
|
+
("lpSecurityDescriptor", LPVOID),
|
|
228
|
+
("bInheritHandle", BOOL),
|
|
229
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Jeff Quast <contact@jeffquast.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Markus Kuhn -- 2007-05-26 (Unicode 5.0)
|
|
24
|
+
|
|
25
|
+
Permission to use, copy, modify, and distribute this software
|
|
26
|
+
for any purpose and without fee is hereby granted. The author
|
|
27
|
+
disclaims all warranties with regard to this software.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wcwidth module.
|
|
3
|
+
|
|
4
|
+
https://github.com/jquast/wcwidth
|
|
5
|
+
"""
|
|
6
|
+
# re-export all functions & definitions, even private ones, from top-level
|
|
7
|
+
# module path, to allow for 'from wcwidth import _private_func'. Of course,
|
|
8
|
+
# user beware that any _private function may disappear or change signature at
|
|
9
|
+
# any future version.
|
|
10
|
+
|
|
11
|
+
# local
|
|
12
|
+
from .wcwidth import ZERO_WIDTH # noqa
|
|
13
|
+
from .wcwidth import (WIDE_EASTASIAN,
|
|
14
|
+
VS16_NARROW_TO_WIDE,
|
|
15
|
+
wcwidth,
|
|
16
|
+
wcswidth,
|
|
17
|
+
_bisearch,
|
|
18
|
+
list_versions,
|
|
19
|
+
_wcmatch_version,
|
|
20
|
+
_wcversion_value)
|
|
21
|
+
|
|
22
|
+
# The __all__ attribute defines the items exported from statement,
|
|
23
|
+
# 'from wcwidth import *', but also to say, "This is the public API".
|
|
24
|
+
__all__ = ('wcwidth', 'wcswidth', 'list_versions')
|
|
25
|
+
|
|
26
|
+
# We also used pkg_resources to load unicode version tables from version.json,
|
|
27
|
+
# generated by bin/update-tables.py, but some environments are unable to
|
|
28
|
+
# import pkg_resources for one reason or another, yikes!
|
|
29
|
+
__version__ = '0.2.13'
|