codis 1.1.1__py3-none-any.whl
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.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/editor/vim_mode.py
ADDED
|
@@ -0,0 +1,1074 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Codis - Modo Vim CLI
|
|
4
|
+
====================
|
|
5
|
+
Reimplementação do modo Vim como experiência completamente imersiva e CLI.
|
|
6
|
+
|
|
7
|
+
Quando ativado:
|
|
8
|
+
* Uma janela ``tk.Toplevel`` separada é criada com aparência de terminal.
|
|
9
|
+
* O conteúdo do arquivo ativo é copiado para o editor interno da janela.
|
|
10
|
+
* A interface principal do Codis fica em segundo plano (não é destruída).
|
|
11
|
+
* A janela CLI exibe modo atual, número de linha e coluna no rodapé.
|
|
12
|
+
* Só é possível sair via ``:q``, ``:q!``, ``:wq``, ou ``Ctrl+Alt+V``.
|
|
13
|
+
|
|
14
|
+
Modos implementados:
|
|
15
|
+
* ``NORMAL`` - navegação e comandos (hjkl, w, b, e, gg, G, dd, yy ...)
|
|
16
|
+
* ``INSERT`` - entrada de texto livre (``i``, ``a``, ``o``, ``I``, ``A``)
|
|
17
|
+
* ``VISUAL`` - seleção char a char (``v``)
|
|
18
|
+
* ``V-LINE`` - seleção por linha (``V``)
|
|
19
|
+
* ``REPLACE`` - substituição de um caractere (``r``)
|
|
20
|
+
* ``COMMAND`` - linha de comando ex (``:``, Enter executa)
|
|
21
|
+
|
|
22
|
+
Design da janela CLI
|
|
23
|
+
--------------------
|
|
24
|
+
A janela ocupa 80 % da tela por padrão e é redimensionável.
|
|
25
|
+
O editor de texto usa fonte monoespaçada, cursor em bloco.
|
|
26
|
+
O rodapé exibe: modo | arquivo | linha:coluna | modificado.
|
|
27
|
+
Uma linha de status separada mostra o buffer de comando ``:``.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import contextlib
|
|
33
|
+
import re
|
|
34
|
+
import tkinter as tk
|
|
35
|
+
from collections.abc import Callable
|
|
36
|
+
from tkinter import font as tkfont
|
|
37
|
+
|
|
38
|
+
from src.ui.grab_safe import safe_grab_set
|
|
39
|
+
|
|
40
|
+
NORMAL = "NORMAL"
|
|
41
|
+
INSERT = "INSERT"
|
|
42
|
+
VISUAL = "VISUAL"
|
|
43
|
+
VLINE = "V-LINE"
|
|
44
|
+
REPLACE = "REPLACE"
|
|
45
|
+
COMMAND = "COMMAND"
|
|
46
|
+
|
|
47
|
+
_SAIDA_ATALHO = "Ctrl+Alt+V"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class VimMode:
|
|
51
|
+
"""Modo de edição Vim imersivo em janela CLI separada.
|
|
52
|
+
|
|
53
|
+
Ao ser ativado, cria um ``tk.Toplevel`` com aparência de terminal e
|
|
54
|
+
copia o conteúdo do editor ativo para dentro dele. A janela principal
|
|
55
|
+
do Codis continua rodando normalmente em segundo plano.
|
|
56
|
+
|
|
57
|
+
O usuário só consegue retornar ao Codis normal via comando ``:q``,
|
|
58
|
+
``:q!``, ``:wq`` ou pelo atalho ``Ctrl+Alt+V``.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
editor_pane: Painel de editor do Codis com atributo ``.text``
|
|
62
|
+
(``tk.Text``) e opcionalmente ``.current_file``.
|
|
63
|
+
on_mode_change: Callback ``(modo: str, cmd: str = "")`` chamado a
|
|
64
|
+
cada transição de modo; usado pela K-UI.
|
|
65
|
+
quit_cb: Chamado quando o usuário executa ``:q`` / ``:q!``;
|
|
66
|
+
deve chamar ``_disable_vim_mode()`` do app.
|
|
67
|
+
save_cb: Chamado quando o usuário executa ``:w`` / ``:wq``;
|
|
68
|
+
deve salvar o arquivo ativo.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
editor_pane,
|
|
74
|
+
on_mode_change: Callable,
|
|
75
|
+
quit_cb: Callable | None = None,
|
|
76
|
+
save_cb: Callable | None = None,
|
|
77
|
+
) -> None:
|
|
78
|
+
self.editor_pane = editor_pane
|
|
79
|
+
self._source_text: tk.Text = editor_pane.text
|
|
80
|
+
self._on_mode_change = on_mode_change
|
|
81
|
+
self._quit_cb = quit_cb
|
|
82
|
+
self._save_cb = save_cb
|
|
83
|
+
self._enabled = False
|
|
84
|
+
|
|
85
|
+
self._mode = NORMAL
|
|
86
|
+
self._cmd_buffer = ""
|
|
87
|
+
self._pending = ""
|
|
88
|
+
self._count_buf = ""
|
|
89
|
+
self._register = ""
|
|
90
|
+
self._visual_start = ""
|
|
91
|
+
self._modified = False
|
|
92
|
+
|
|
93
|
+
self._win: tk.Toplevel | None = None
|
|
94
|
+
self._txt: tk.Text | None = None
|
|
95
|
+
self._status_lbl: tk.Label | None = None
|
|
96
|
+
self._cmd_lbl: tk.Label | None = None
|
|
97
|
+
self._bindings: list = []
|
|
98
|
+
|
|
99
|
+
def enable(self) -> None:
|
|
100
|
+
"""Abre a janela CLI e transfere o conteúdo do editor ativo."""
|
|
101
|
+
if self._enabled:
|
|
102
|
+
return
|
|
103
|
+
self._enabled = True
|
|
104
|
+
self._modified = False
|
|
105
|
+
self._criar_janela_cli()
|
|
106
|
+
|
|
107
|
+
def disable(self) -> None:
|
|
108
|
+
"""Fecha a janela CLI e restaura o foco para o Codis."""
|
|
109
|
+
if not self._enabled:
|
|
110
|
+
return
|
|
111
|
+
self._enabled = False
|
|
112
|
+
self._fechar_janela()
|
|
113
|
+
with contextlib.suppress(tk.TclError):
|
|
114
|
+
self._on_mode_change("")
|
|
115
|
+
|
|
116
|
+
def _criar_janela_cli(self) -> None:
|
|
117
|
+
"""Cria a janela Toplevel com aparência de terminal."""
|
|
118
|
+
root = self._source_text.winfo_toplevel()
|
|
119
|
+
|
|
120
|
+
self._win = tk.Toplevel(root)
|
|
121
|
+
self._win.title("[ VIM ]")
|
|
122
|
+
self._win.protocol("WM_DELETE_WINDOW", self._abortar)
|
|
123
|
+
|
|
124
|
+
sw = root.winfo_screenwidth()
|
|
125
|
+
sh = root.winfo_screenheight()
|
|
126
|
+
w = max(900, int(sw * 0.80))
|
|
127
|
+
h = max(600, int(sh * 0.80))
|
|
128
|
+
x = (sw - w) // 2
|
|
129
|
+
y = (sh - h) // 2
|
|
130
|
+
self._win.geometry(f"{w}x{h}+{x}+{y}")
|
|
131
|
+
self._win.resizable(True, True)
|
|
132
|
+
self._win.configure(bg="#0a0a0f")
|
|
133
|
+
|
|
134
|
+
self._win.bind("<Control-Alt-v>", lambda _: self._abortar())
|
|
135
|
+
self._win.bind("<Control-Alt-V>", lambda _: self._abortar())
|
|
136
|
+
|
|
137
|
+
self._construir_layout()
|
|
138
|
+
self._carregar_conteudo()
|
|
139
|
+
self._set_mode(NORMAL)
|
|
140
|
+
|
|
141
|
+
self._txt.focus_set()
|
|
142
|
+
safe_grab_set(self._win)
|
|
143
|
+
|
|
144
|
+
def _construir_layout(self) -> None:
|
|
145
|
+
"""Constrói os widgets internos da janela CLI."""
|
|
146
|
+
BG = "#0a0a0f"
|
|
147
|
+
FG = "#c8d3f5"
|
|
148
|
+
FG_DIM = "#545c7e"
|
|
149
|
+
CURSOR_CLR = "#c8d3f5"
|
|
150
|
+
SEL_BG = "#2d3f76"
|
|
151
|
+
LINE_HL = "#13131f"
|
|
152
|
+
FONT_NOME = "Consolas"
|
|
153
|
+
FONT_SZ = 13
|
|
154
|
+
|
|
155
|
+
mono = (FONT_NOME, FONT_SZ)
|
|
156
|
+
|
|
157
|
+
with contextlib.suppress(tk.TclError):
|
|
158
|
+
f = tkfont.Font(family=FONT_NOME, size=FONT_SZ)
|
|
159
|
+
if f.measure("M") == 0:
|
|
160
|
+
FONT_NOME = "Courier New"
|
|
161
|
+
|
|
162
|
+
corpo = tk.Frame(self._win, bg=BG)
|
|
163
|
+
corpo.pack(fill="both", expand=True)
|
|
164
|
+
|
|
165
|
+
nums_frame = tk.Frame(corpo, bg="#0d0d18")
|
|
166
|
+
nums_frame.pack(side="left", fill="y")
|
|
167
|
+
|
|
168
|
+
self._numeros = tk.Text(
|
|
169
|
+
nums_frame,
|
|
170
|
+
width=5,
|
|
171
|
+
bg="#0d0d18",
|
|
172
|
+
fg=FG_DIM,
|
|
173
|
+
font=mono,
|
|
174
|
+
state="disabled",
|
|
175
|
+
relief="flat",
|
|
176
|
+
bd=0,
|
|
177
|
+
highlightthickness=0,
|
|
178
|
+
padx=6,
|
|
179
|
+
pady=2,
|
|
180
|
+
cursor="arrow",
|
|
181
|
+
)
|
|
182
|
+
self._numeros.pack(fill="y", expand=True)
|
|
183
|
+
|
|
184
|
+
self._txt = tk.Text(
|
|
185
|
+
corpo,
|
|
186
|
+
bg=BG,
|
|
187
|
+
fg=FG,
|
|
188
|
+
insertbackground=CURSOR_CLR,
|
|
189
|
+
insertwidth=10,
|
|
190
|
+
selectbackground=SEL_BG,
|
|
191
|
+
font=mono,
|
|
192
|
+
relief="flat",
|
|
193
|
+
bd=0,
|
|
194
|
+
highlightthickness=0,
|
|
195
|
+
padx=8,
|
|
196
|
+
pady=2,
|
|
197
|
+
undo=True,
|
|
198
|
+
wrap="none",
|
|
199
|
+
)
|
|
200
|
+
self._txt.tag_configure("current_line", background=LINE_HL)
|
|
201
|
+
self._txt.pack(side="left", fill="both", expand=True)
|
|
202
|
+
|
|
203
|
+
scrolly = tk.Scrollbar(
|
|
204
|
+
corpo, command=self._txt.yview, bg="#0d0d18", troughcolor="#0d0d18"
|
|
205
|
+
)
|
|
206
|
+
scrolly.pack(side="right", fill="y")
|
|
207
|
+
self._txt.config(yscrollcommand=scrolly.set)
|
|
208
|
+
|
|
209
|
+
scrollx = tk.Scrollbar(
|
|
210
|
+
self._win,
|
|
211
|
+
orient="horizontal",
|
|
212
|
+
command=self._txt.xview,
|
|
213
|
+
bg="#0d0d18",
|
|
214
|
+
troughcolor="#0d0d18",
|
|
215
|
+
)
|
|
216
|
+
scrollx.pack(side="bottom", fill="x")
|
|
217
|
+
self._txt.config(xscrollcommand=scrollx.set)
|
|
218
|
+
|
|
219
|
+
footer = tk.Frame(self._win, bg="#1a1a2e", height=24)
|
|
220
|
+
footer.pack(side="bottom", fill="x")
|
|
221
|
+
footer.pack_propagate(False)
|
|
222
|
+
|
|
223
|
+
self._modo_lbl = tk.Label(
|
|
224
|
+
footer,
|
|
225
|
+
text="",
|
|
226
|
+
bg="#7c4dff",
|
|
227
|
+
fg="#ffffff",
|
|
228
|
+
font=(FONT_NOME, 10, "bold"),
|
|
229
|
+
padx=8,
|
|
230
|
+
)
|
|
231
|
+
self._modo_lbl.pack(side="left")
|
|
232
|
+
|
|
233
|
+
self._arquivo_lbl = tk.Label(
|
|
234
|
+
footer,
|
|
235
|
+
text="",
|
|
236
|
+
bg="#1a1a2e",
|
|
237
|
+
fg=FG_DIM,
|
|
238
|
+
font=(FONT_NOME, 10),
|
|
239
|
+
padx=8,
|
|
240
|
+
)
|
|
241
|
+
self._arquivo_lbl.pack(side="left")
|
|
242
|
+
|
|
243
|
+
self._pos_lbl = tk.Label(
|
|
244
|
+
footer,
|
|
245
|
+
text="",
|
|
246
|
+
bg="#1a1a2e",
|
|
247
|
+
fg=FG_DIM,
|
|
248
|
+
font=(FONT_NOME, 10),
|
|
249
|
+
padx=8,
|
|
250
|
+
)
|
|
251
|
+
self._pos_lbl.pack(side="right")
|
|
252
|
+
|
|
253
|
+
self._mod_lbl = tk.Label(
|
|
254
|
+
footer,
|
|
255
|
+
text="",
|
|
256
|
+
bg="#1a1a2e",
|
|
257
|
+
fg="#ff5370",
|
|
258
|
+
font=(FONT_NOME, 10, "bold"),
|
|
259
|
+
padx=8,
|
|
260
|
+
)
|
|
261
|
+
self._mod_lbl.pack(side="right")
|
|
262
|
+
|
|
263
|
+
self._cmd_lbl = tk.Label(
|
|
264
|
+
self._win,
|
|
265
|
+
text="",
|
|
266
|
+
bg="#0a0a0f",
|
|
267
|
+
fg="#c8d3f5",
|
|
268
|
+
font=(FONT_NOME, 11),
|
|
269
|
+
anchor="w",
|
|
270
|
+
padx=8,
|
|
271
|
+
)
|
|
272
|
+
self._cmd_lbl.pack(side="bottom", fill="x")
|
|
273
|
+
|
|
274
|
+
self._txt.bind("<Key>", self._handle_key, add=True)
|
|
275
|
+
self._txt.bind("<Return>", self._handle_return, add=True)
|
|
276
|
+
self._txt.bind("<KeyRelease>", lambda _: self._atualizar_pos())
|
|
277
|
+
|
|
278
|
+
def _carregar_conteudo(self) -> None:
|
|
279
|
+
"""Copia o conteúdo do editor ativo para o editor interno da janela."""
|
|
280
|
+
content = ""
|
|
281
|
+
with contextlib.suppress(tk.TclError):
|
|
282
|
+
content = self._source_text.get("1.0", "end-1c")
|
|
283
|
+
self._txt.delete("1.0", "end")
|
|
284
|
+
self._txt.insert("1.0", content)
|
|
285
|
+
self._txt.edit_reset()
|
|
286
|
+
self._atualizar_numeros()
|
|
287
|
+
|
|
288
|
+
with contextlib.suppress(tk.TclError):
|
|
289
|
+
cursor_src = self._source_text.index("insert")
|
|
290
|
+
self._txt.mark_set("insert", cursor_src)
|
|
291
|
+
self._txt.see("insert")
|
|
292
|
+
|
|
293
|
+
name = ""
|
|
294
|
+
with contextlib.suppress(tk.TclError):
|
|
295
|
+
name = getattr(self.editor_pane, "current_file", "") or ""
|
|
296
|
+
if name:
|
|
297
|
+
import os
|
|
298
|
+
|
|
299
|
+
name = os.path.basename(name)
|
|
300
|
+
with contextlib.suppress(tk.TclError):
|
|
301
|
+
self._arquivo_lbl.config(text=f" {name or '[sem name]'}")
|
|
302
|
+
|
|
303
|
+
def _fechar_janela(self) -> None:
|
|
304
|
+
"""Fecha a janela CLI e libera o grab."""
|
|
305
|
+
with contextlib.suppress(tk.TclError):
|
|
306
|
+
if self._win:
|
|
307
|
+
self._win.grab_release()
|
|
308
|
+
self._win.destroy()
|
|
309
|
+
self._win = None
|
|
310
|
+
self._txt = None
|
|
311
|
+
|
|
312
|
+
def _abortar(self) -> None:
|
|
313
|
+
"""Sai do modo Vim sem salvar (equivalente a ``:q!``)."""
|
|
314
|
+
self._fechar_janela()
|
|
315
|
+
self._enabled = False
|
|
316
|
+
with contextlib.suppress(tk.TclError):
|
|
317
|
+
self._on_mode_change("")
|
|
318
|
+
if self._quit_cb:
|
|
319
|
+
with contextlib.suppress(tk.TclError):
|
|
320
|
+
self._quit_cb()
|
|
321
|
+
|
|
322
|
+
def _set_mode(self, mode: str, cmd: str = "") -> None:
|
|
323
|
+
"""Atualiza o modo atual e sincroniza a UI da janela CLI.
|
|
324
|
+
|
|
325
|
+
Args:
|
|
326
|
+
mode: Novo modo (``NORMAL``, ``INSERT``, etc.).
|
|
327
|
+
cmd: Buffer de comando ex atual (usado em ``COMMAND``).
|
|
328
|
+
"""
|
|
329
|
+
self._mode = mode
|
|
330
|
+
self._pending = ""
|
|
331
|
+
self._count_buf = ""
|
|
332
|
+
if mode == COMMAND:
|
|
333
|
+
self._cmd_buffer = ""
|
|
334
|
+
|
|
335
|
+
with contextlib.suppress(tk.TclError):
|
|
336
|
+
if self._txt:
|
|
337
|
+
if mode == INSERT:
|
|
338
|
+
self._txt.config(insertwidth=2)
|
|
339
|
+
else:
|
|
340
|
+
self._txt.config(insertwidth=10)
|
|
341
|
+
|
|
342
|
+
self._atualizar_rodape(mode, cmd)
|
|
343
|
+
with contextlib.suppress(tk.TclError):
|
|
344
|
+
self._on_mode_change(mode, cmd)
|
|
345
|
+
|
|
346
|
+
def _atualizar_rodape(self, mode: str, cmd: str = "") -> None:
|
|
347
|
+
"""Atualiza os rótulos do rodapé com o modo e o buffer de comando.
|
|
348
|
+
|
|
349
|
+
Args:
|
|
350
|
+
mode: Modo atual.
|
|
351
|
+
cmd: Buffer de comando ex (exibido na linha de cmd abaixo).
|
|
352
|
+
"""
|
|
353
|
+
if not self._win:
|
|
354
|
+
return
|
|
355
|
+
cores_modo = {
|
|
356
|
+
NORMAL: ("#7c4dff", "#ffffff"),
|
|
357
|
+
INSERT: ("#00bcd4", "#000000"),
|
|
358
|
+
VISUAL: ("#ff9800", "#000000"),
|
|
359
|
+
VLINE: ("#ff9800", "#000000"),
|
|
360
|
+
REPLACE: ("#f44336", "#ffffff"),
|
|
361
|
+
COMMAND: ("#1a1a2e", "#c8d3f5"),
|
|
362
|
+
}
|
|
363
|
+
bg_m, fg_m = cores_modo.get(mode, ("#1a1a2e", "#c8d3f5"))
|
|
364
|
+
with contextlib.suppress(tk.TclError):
|
|
365
|
+
self._modo_lbl.config(text=f" {mode} ", bg=bg_m, fg=fg_m)
|
|
366
|
+
|
|
367
|
+
if mode == COMMAND:
|
|
368
|
+
with contextlib.suppress(tk.TclError):
|
|
369
|
+
self._cmd_lbl.config(text=f":{cmd}")
|
|
370
|
+
else:
|
|
371
|
+
with contextlib.suppress(tk.TclError):
|
|
372
|
+
self._cmd_lbl.config(text="")
|
|
373
|
+
|
|
374
|
+
self._atualizar_pos()
|
|
375
|
+
with contextlib.suppress(tk.TclError):
|
|
376
|
+
self._mod_lbl.config(text="[+]" if self._modified else "")
|
|
377
|
+
|
|
378
|
+
def _atualizar_pos(self) -> None:
|
|
379
|
+
"""Atualiza o rótulo de posição (linha:coluna) no rodapé."""
|
|
380
|
+
if not self._txt or not self._win:
|
|
381
|
+
return
|
|
382
|
+
with contextlib.suppress(tk.TclError):
|
|
383
|
+
idx = self._txt.index("insert")
|
|
384
|
+
ln, col = idx.split(".")
|
|
385
|
+
self._pos_lbl.config(text=f"Ln {ln} Col {int(col) + 1} ")
|
|
386
|
+
self._atualizar_numeros()
|
|
387
|
+
self._hl_linha_atual()
|
|
388
|
+
|
|
389
|
+
def _atualizar_numeros(self) -> None:
|
|
390
|
+
"""Sincroniza o painel de números de linha."""
|
|
391
|
+
if not self._txt or not self._numeros:
|
|
392
|
+
return
|
|
393
|
+
with contextlib.suppress(tk.TclError):
|
|
394
|
+
total = int(self._txt.index("end-1c").split(".", 1)[0])
|
|
395
|
+
lines = "\n".join(str(i) for i in range(1, total + 1))
|
|
396
|
+
self._numeros.config(state="normal")
|
|
397
|
+
self._numeros.delete("1.0", "end")
|
|
398
|
+
self._numeros.insert("1.0", lines)
|
|
399
|
+
self._numeros.config(state="disabled")
|
|
400
|
+
|
|
401
|
+
def _hl_linha_atual(self) -> None:
|
|
402
|
+
"""Realça a linha onde o cursor está."""
|
|
403
|
+
if not self._txt:
|
|
404
|
+
return
|
|
405
|
+
with contextlib.suppress(tk.TclError):
|
|
406
|
+
self._txt.tag_remove("current_line", "1.0", "end")
|
|
407
|
+
ln = self._txt.index("insert").split(".", 1)[0]
|
|
408
|
+
self._txt.tag_add("current_line", f"{ln}.0", f"{ln}.end+1c")
|
|
409
|
+
|
|
410
|
+
def _handle_return(self, _event: tk.Event) -> str | None:
|
|
411
|
+
"""Handler dedicado para Enter - executa o buffer COMMAND ou move linha.
|
|
412
|
+
|
|
413
|
+
Args:
|
|
414
|
+
_event: Evento Tkinter de teclado.
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
``"break"`` para consumir o evento; ``None`` para passar adiante.
|
|
418
|
+
"""
|
|
419
|
+
if not self._enabled:
|
|
420
|
+
return None
|
|
421
|
+
if self._mode == COMMAND:
|
|
422
|
+
self._execute_command(self._cmd_buffer)
|
|
423
|
+
return "break"
|
|
424
|
+
if self._mode == INSERT:
|
|
425
|
+
return None
|
|
426
|
+
with contextlib.suppress(tk.TclError):
|
|
427
|
+
self._txt.mark_set("insert", "insert+1l")
|
|
428
|
+
return "break"
|
|
429
|
+
|
|
430
|
+
def _handle_key(self, event: tk.Event) -> str | None:
|
|
431
|
+
"""
|
|
432
|
+
Args:
|
|
433
|
+
event: Evento Tkinter de teclado.
|
|
434
|
+
|
|
435
|
+
Returns:
|
|
436
|
+
``"break"`` para consumir; ``None`` para passar ao Tkinter.
|
|
437
|
+
"""
|
|
438
|
+
if not self._enabled:
|
|
439
|
+
return None
|
|
440
|
+
sym = event.keysym
|
|
441
|
+
char = event.char
|
|
442
|
+
|
|
443
|
+
if self._mode == INSERT:
|
|
444
|
+
if sym == "Escape":
|
|
445
|
+
self._set_mode(NORMAL)
|
|
446
|
+
with contextlib.suppress(tk.TclError):
|
|
447
|
+
idx = self._txt.index("insert")
|
|
448
|
+
ln, col = idx.split(".")
|
|
449
|
+
if int(col) > 0:
|
|
450
|
+
self._txt.mark_set("insert", f"{ln}.{int(col) - 1}")
|
|
451
|
+
return "break"
|
|
452
|
+
self._modified = True
|
|
453
|
+
self._atualizar_pos()
|
|
454
|
+
return None
|
|
455
|
+
|
|
456
|
+
if self._mode == REPLACE:
|
|
457
|
+
if sym == "Escape":
|
|
458
|
+
self._set_mode(NORMAL)
|
|
459
|
+
return "break"
|
|
460
|
+
if char and char.isprintable():
|
|
461
|
+
with contextlib.suppress(tk.TclError):
|
|
462
|
+
idx = self._txt.index("insert")
|
|
463
|
+
self._txt.delete(idx)
|
|
464
|
+
self._txt.insert(idx, char)
|
|
465
|
+
self._txt.mark_set("insert", idx)
|
|
466
|
+
self._modified = True
|
|
467
|
+
self._set_mode(NORMAL)
|
|
468
|
+
return "break"
|
|
469
|
+
return "break"
|
|
470
|
+
|
|
471
|
+
if self._mode == COMMAND:
|
|
472
|
+
return self._command_key(sym, char)
|
|
473
|
+
|
|
474
|
+
if self._mode in (VISUAL, VLINE):
|
|
475
|
+
return self._visual_key(sym, char)
|
|
476
|
+
|
|
477
|
+
return self._normal_key(event, sym, char)
|
|
478
|
+
|
|
479
|
+
def _normal_motion(self, sym: str, char: str, count: int) -> str | None:
|
|
480
|
+
"""Trata teclas de movimento no modo NORMAL (h/j/k/l, w/b/e, 0/$, G, gg)."""
|
|
481
|
+
txt = self._txt
|
|
482
|
+
if sym in ("h", "Left"):
|
|
483
|
+
for _ in range(count):
|
|
484
|
+
with contextlib.suppress(tk.TclError):
|
|
485
|
+
txt.mark_set("insert", "insert-1c")
|
|
486
|
+
return "break"
|
|
487
|
+
if sym in ("l", "Right"):
|
|
488
|
+
for _ in range(count):
|
|
489
|
+
with contextlib.suppress(tk.TclError):
|
|
490
|
+
txt.mark_set("insert", "insert+1c")
|
|
491
|
+
return "break"
|
|
492
|
+
if sym in ("j", "Down"):
|
|
493
|
+
for _ in range(count):
|
|
494
|
+
with contextlib.suppress(tk.TclError):
|
|
495
|
+
txt.mark_set("insert", "insert+1l")
|
|
496
|
+
self._atualizar_pos()
|
|
497
|
+
return "break"
|
|
498
|
+
if sym in ("k", "Up"):
|
|
499
|
+
for _ in range(count):
|
|
500
|
+
with contextlib.suppress(tk.TclError):
|
|
501
|
+
txt.mark_set("insert", "insert-1l")
|
|
502
|
+
self._atualizar_pos()
|
|
503
|
+
return "break"
|
|
504
|
+
if char == "w":
|
|
505
|
+
for _ in range(count):
|
|
506
|
+
with contextlib.suppress(tk.TclError):
|
|
507
|
+
txt.mark_set("insert", "insert wordend")
|
|
508
|
+
txt.mark_set("insert", "insert+1c wordstart")
|
|
509
|
+
return "break"
|
|
510
|
+
if char == "b":
|
|
511
|
+
for _ in range(count):
|
|
512
|
+
with contextlib.suppress(tk.TclError):
|
|
513
|
+
txt.mark_set("insert", "insert-1c wordstart")
|
|
514
|
+
return "break"
|
|
515
|
+
if char == "e":
|
|
516
|
+
for _ in range(count):
|
|
517
|
+
with contextlib.suppress(tk.TclError):
|
|
518
|
+
txt.mark_set("insert", "insert wordend")
|
|
519
|
+
return "break"
|
|
520
|
+
if char == "0" or sym == "Home":
|
|
521
|
+
with contextlib.suppress(tk.TclError):
|
|
522
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
523
|
+
txt.mark_set("insert", f"{ln}.0")
|
|
524
|
+
return "break"
|
|
525
|
+
if char == "$" or sym == "End":
|
|
526
|
+
with contextlib.suppress(tk.TclError):
|
|
527
|
+
txt.mark_set("insert", "insert lineend")
|
|
528
|
+
return "break"
|
|
529
|
+
if char == "^":
|
|
530
|
+
with contextlib.suppress(tk.TclError):
|
|
531
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
532
|
+
line = txt.get(f"{ln}.0", f"{ln}.end")
|
|
533
|
+
col = len(line) - len(line.lstrip())
|
|
534
|
+
txt.mark_set("insert", f"{ln}.{col}")
|
|
535
|
+
return "break"
|
|
536
|
+
if char == "G":
|
|
537
|
+
target = (
|
|
538
|
+
count if self._count_buf else int(
|
|
539
|
+
txt.index("end-1c").split(".", 1)[0])
|
|
540
|
+
)
|
|
541
|
+
with contextlib.suppress(tk.TclError):
|
|
542
|
+
txt.mark_set("insert", f"{target}.0")
|
|
543
|
+
txt.see("insert")
|
|
544
|
+
self._count_buf = ""
|
|
545
|
+
return "break"
|
|
546
|
+
if self._pending == "g" and char == "g":
|
|
547
|
+
with contextlib.suppress(tk.TclError):
|
|
548
|
+
txt.mark_set("insert", "1.0")
|
|
549
|
+
txt.see("insert")
|
|
550
|
+
self._pending = ""
|
|
551
|
+
return "break"
|
|
552
|
+
return None
|
|
553
|
+
|
|
554
|
+
def _normal_scroll(self, event: tk.Event, sym: str, count: int) -> str | None:
|
|
555
|
+
"""Trata teclas de scroll no modo NORMAL (Ctrl-f/b/d/u)."""
|
|
556
|
+
txt = self._txt
|
|
557
|
+
ctrl = event.state & 4
|
|
558
|
+
if sym == "control_f" or (ctrl and sym == "f"):
|
|
559
|
+
with contextlib.suppress(tk.TclError):
|
|
560
|
+
txt.yview_scroll(count, "pages")
|
|
561
|
+
return "break"
|
|
562
|
+
if sym == "control_b" or (ctrl and sym == "b"):
|
|
563
|
+
with contextlib.suppress(tk.TclError):
|
|
564
|
+
txt.yview_scroll(-count, "pages")
|
|
565
|
+
return "break"
|
|
566
|
+
if sym == "control_d" or (ctrl and sym == "d"):
|
|
567
|
+
with contextlib.suppress(tk.TclError):
|
|
568
|
+
txt.yview_scroll(count, "units")
|
|
569
|
+
return "break"
|
|
570
|
+
if sym == "control_u" or (ctrl and sym == "u"):
|
|
571
|
+
with contextlib.suppress(tk.TclError):
|
|
572
|
+
txt.yview_scroll(-count, "units")
|
|
573
|
+
return "break"
|
|
574
|
+
return None
|
|
575
|
+
|
|
576
|
+
def _normal_insert_enter(self, char: str) -> str | None:
|
|
577
|
+
"""Trata teclas de entrada em modo INSERT a partir do NORMAL (i/I/a/A/o/O/r/R)."""
|
|
578
|
+
txt = self._txt
|
|
579
|
+
if char == "i":
|
|
580
|
+
self._set_mode(INSERT)
|
|
581
|
+
return "break"
|
|
582
|
+
if char == "I":
|
|
583
|
+
with contextlib.suppress(tk.TclError):
|
|
584
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
585
|
+
line = txt.get(f"{ln}.0", f"{ln}.end")
|
|
586
|
+
col = len(line) - len(line.lstrip())
|
|
587
|
+
txt.mark_set("insert", f"{ln}.{col}")
|
|
588
|
+
self._set_mode(INSERT)
|
|
589
|
+
return "break"
|
|
590
|
+
if char == "a":
|
|
591
|
+
with contextlib.suppress(tk.TclError):
|
|
592
|
+
txt.mark_set("insert", "insert+1c")
|
|
593
|
+
self._set_mode(INSERT)
|
|
594
|
+
return "break"
|
|
595
|
+
if char == "A":
|
|
596
|
+
with contextlib.suppress(tk.TclError):
|
|
597
|
+
txt.mark_set("insert", "insert lineend")
|
|
598
|
+
self._set_mode(INSERT)
|
|
599
|
+
return "break"
|
|
600
|
+
if char == "o":
|
|
601
|
+
with contextlib.suppress(tk.TclError):
|
|
602
|
+
txt.mark_set("insert", "insert lineend")
|
|
603
|
+
txt.insert("insert", "\n")
|
|
604
|
+
self._modified = True
|
|
605
|
+
self._set_mode(INSERT)
|
|
606
|
+
return "break"
|
|
607
|
+
if char == "O":
|
|
608
|
+
with contextlib.suppress(tk.TclError):
|
|
609
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
610
|
+
txt.mark_set("insert", f"{ln}.0")
|
|
611
|
+
txt.insert("insert", "\n")
|
|
612
|
+
txt.mark_set("insert", f"{ln}.0")
|
|
613
|
+
self._modified = True
|
|
614
|
+
self._set_mode(INSERT)
|
|
615
|
+
return "break"
|
|
616
|
+
if char in ("r", "R"):
|
|
617
|
+
self._set_mode(REPLACE)
|
|
618
|
+
return "break"
|
|
619
|
+
return None
|
|
620
|
+
|
|
621
|
+
def _normal_pending(self, char: str, count: int) -> str | None:
|
|
622
|
+
"""Resolve operadores pendentes (dd, dw, yy, cc, cw, zz) no modo NORMAL."""
|
|
623
|
+
txt = self._txt
|
|
624
|
+
pending = self._pending
|
|
625
|
+
if pending == "d":
|
|
626
|
+
if char == "d":
|
|
627
|
+
for _ in range(count):
|
|
628
|
+
with contextlib.suppress(tk.TclError):
|
|
629
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
630
|
+
self._register = txt.get(f"{ln}.0", f"{ln}.end+1c")
|
|
631
|
+
txt.delete(f"{ln}.0", f"{ln}.end+1c")
|
|
632
|
+
self._modified = True
|
|
633
|
+
elif char == "w":
|
|
634
|
+
with contextlib.suppress(tk.TclError):
|
|
635
|
+
start = txt.index("insert")
|
|
636
|
+
txt.mark_set("insert", "insert wordend")
|
|
637
|
+
self._register = txt.get(start, "insert")
|
|
638
|
+
txt.delete(start, "insert")
|
|
639
|
+
self._modified = True
|
|
640
|
+
self._pending = ""
|
|
641
|
+
return "break"
|
|
642
|
+
if pending == "y":
|
|
643
|
+
if char == "y":
|
|
644
|
+
with contextlib.suppress(tk.TclError):
|
|
645
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
646
|
+
self._register = txt.get(f"{ln}.0", f"{ln}.end+1c")
|
|
647
|
+
self._pending = ""
|
|
648
|
+
return "break"
|
|
649
|
+
if pending == "c":
|
|
650
|
+
if char == "c":
|
|
651
|
+
with contextlib.suppress(tk.TclError):
|
|
652
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
653
|
+
self._register = txt.get(f"{ln}.0", f"{ln}.end")
|
|
654
|
+
txt.delete(f"{ln}.0", f"{ln}.end")
|
|
655
|
+
self._modified = True
|
|
656
|
+
self._set_mode(INSERT)
|
|
657
|
+
elif char == "w":
|
|
658
|
+
with contextlib.suppress(tk.TclError):
|
|
659
|
+
start = txt.index("insert")
|
|
660
|
+
txt.mark_set("insert", "insert wordend")
|
|
661
|
+
self._register = txt.get(start, "insert")
|
|
662
|
+
txt.delete(start, "insert")
|
|
663
|
+
txt.mark_set("insert", start)
|
|
664
|
+
self._modified = True
|
|
665
|
+
self._set_mode(INSERT)
|
|
666
|
+
self._pending = ""
|
|
667
|
+
return "break"
|
|
668
|
+
if pending == "z":
|
|
669
|
+
if char == "z":
|
|
670
|
+
with contextlib.suppress(tk.TclError):
|
|
671
|
+
txt.see("insert")
|
|
672
|
+
self._pending = ""
|
|
673
|
+
return "break"
|
|
674
|
+
return None
|
|
675
|
+
|
|
676
|
+
def _normal_key(self, event: tk.Event, sym: str, char: str) -> str | None:
|
|
677
|
+
"""Processa teclas no modo NORMAL.
|
|
678
|
+
|
|
679
|
+
Args:
|
|
680
|
+
event: Evento original do Tk.
|
|
681
|
+
sym: Nome do keysym.
|
|
682
|
+
char: Caractere imprimível (pode ser vazio).
|
|
683
|
+
|
|
684
|
+
Returns:
|
|
685
|
+
``"break"`` para suprimir o evento padrão, ou ``None``.
|
|
686
|
+
"""
|
|
687
|
+
txt = self._txt
|
|
688
|
+
pending = self._pending
|
|
689
|
+
|
|
690
|
+
if sym == "Escape":
|
|
691
|
+
self._pending = ""
|
|
692
|
+
self._count_buf = ""
|
|
693
|
+
self._set_mode(NORMAL)
|
|
694
|
+
return "break"
|
|
695
|
+
|
|
696
|
+
if char.isdigit() and char != "0" and not pending:
|
|
697
|
+
self._count_buf += char
|
|
698
|
+
return "break"
|
|
699
|
+
|
|
700
|
+
count = max(1, int(self._count_buf)) if self._count_buf else 1
|
|
701
|
+
|
|
702
|
+
if pending in ("d", "y", "c", "z"):
|
|
703
|
+
result = self._normal_pending(char, count)
|
|
704
|
+
if result is not None:
|
|
705
|
+
return result
|
|
706
|
+
|
|
707
|
+
result = self._normal_motion(sym, char, count)
|
|
708
|
+
if result is not None:
|
|
709
|
+
return result
|
|
710
|
+
|
|
711
|
+
result = self._normal_scroll(event, sym, count)
|
|
712
|
+
if result is not None:
|
|
713
|
+
return result
|
|
714
|
+
|
|
715
|
+
result = self._normal_insert_enter(char)
|
|
716
|
+
if result is not None:
|
|
717
|
+
return result
|
|
718
|
+
|
|
719
|
+
if char == "v":
|
|
720
|
+
self._visual_start = txt.index("insert")
|
|
721
|
+
self._set_mode(VISUAL)
|
|
722
|
+
return "break"
|
|
723
|
+
if char == "V":
|
|
724
|
+
self._visual_start = txt.index("insert")
|
|
725
|
+
self._set_mode(VLINE)
|
|
726
|
+
return "break"
|
|
727
|
+
|
|
728
|
+
if char == "u":
|
|
729
|
+
with contextlib.suppress(tk.TclError):
|
|
730
|
+
txt.edit_undo()
|
|
731
|
+
return "break"
|
|
732
|
+
if sym == "control_r":
|
|
733
|
+
with contextlib.suppress(tk.TclError):
|
|
734
|
+
txt.edit_redo()
|
|
735
|
+
return "break"
|
|
736
|
+
|
|
737
|
+
if char == ":":
|
|
738
|
+
self._set_mode(COMMAND)
|
|
739
|
+
return "break"
|
|
740
|
+
|
|
741
|
+
if char == "g":
|
|
742
|
+
self._pending = "g"
|
|
743
|
+
return "break"
|
|
744
|
+
if char == "d":
|
|
745
|
+
self._pending = "d"
|
|
746
|
+
self._count_buf = ""
|
|
747
|
+
return "break"
|
|
748
|
+
if char == "y":
|
|
749
|
+
self._pending = "y"
|
|
750
|
+
self._count_buf = ""
|
|
751
|
+
return "break"
|
|
752
|
+
if char == "c":
|
|
753
|
+
self._pending = "c"
|
|
754
|
+
self._count_buf = ""
|
|
755
|
+
return "break"
|
|
756
|
+
if char == "z":
|
|
757
|
+
self._pending = "z"
|
|
758
|
+
return "break"
|
|
759
|
+
|
|
760
|
+
if char == "p":
|
|
761
|
+
if self._register:
|
|
762
|
+
with contextlib.suppress(tk.TclError):
|
|
763
|
+
txt.insert("insert+1c", self._register)
|
|
764
|
+
self._modified = True
|
|
765
|
+
return "break"
|
|
766
|
+
if char == "P":
|
|
767
|
+
if self._register:
|
|
768
|
+
with contextlib.suppress(tk.TclError):
|
|
769
|
+
txt.insert("insert", self._register)
|
|
770
|
+
self._modified = True
|
|
771
|
+
return "break"
|
|
772
|
+
|
|
773
|
+
if char == "x":
|
|
774
|
+
for _ in range(count):
|
|
775
|
+
with contextlib.suppress(tk.TclError):
|
|
776
|
+
self._register = txt.get("insert")
|
|
777
|
+
txt.delete("insert")
|
|
778
|
+
self._modified = True
|
|
779
|
+
return "break"
|
|
780
|
+
if char == "X":
|
|
781
|
+
for _ in range(count):
|
|
782
|
+
with contextlib.suppress(tk.TclError):
|
|
783
|
+
self._register = txt.get("insert-1c")
|
|
784
|
+
txt.delete("insert-1c")
|
|
785
|
+
self._modified = True
|
|
786
|
+
return "break"
|
|
787
|
+
|
|
788
|
+
if char == "/":
|
|
789
|
+
self._cmd_buffer = "/"
|
|
790
|
+
self._set_mode(COMMAND)
|
|
791
|
+
with contextlib.suppress(tk.TclError):
|
|
792
|
+
self._cmd_lbl.config(text="/")
|
|
793
|
+
return "break"
|
|
794
|
+
if char == "n":
|
|
795
|
+
self._buscar_proximo(direction=1)
|
|
796
|
+
return "break"
|
|
797
|
+
if char == "N":
|
|
798
|
+
self._buscar_proximo(direction=-1)
|
|
799
|
+
return "break"
|
|
800
|
+
|
|
801
|
+
if char == "J":
|
|
802
|
+
with contextlib.suppress(tk.TclError):
|
|
803
|
+
ln = txt.index("insert").split(".", 1)[0]
|
|
804
|
+
txt.delete(f"{ln}.end", f"{ln}.end+1c")
|
|
805
|
+
txt.insert(f"{ln}.end", " ")
|
|
806
|
+
self._modified = True
|
|
807
|
+
return "break"
|
|
808
|
+
|
|
809
|
+
return "break"
|
|
810
|
+
|
|
811
|
+
def _command_key(self, sym: str, char: str) -> str | None:
|
|
812
|
+
"""Processa teclas no modo COMMAND (linha de comando ex).
|
|
813
|
+
|
|
814
|
+
Args:
|
|
815
|
+
sym: Keysym da tecla.
|
|
816
|
+
char: Caractere imprimível.
|
|
817
|
+
|
|
818
|
+
Returns:
|
|
819
|
+
Sempre ``"break"``.
|
|
820
|
+
"""
|
|
821
|
+
if sym == "Escape":
|
|
822
|
+
self._set_mode(NORMAL)
|
|
823
|
+
return "break"
|
|
824
|
+
|
|
825
|
+
if sym in ("Return", "KP_Enter"):
|
|
826
|
+
self._execute_command(self._cmd_buffer)
|
|
827
|
+
return "break"
|
|
828
|
+
|
|
829
|
+
if sym == "BackSpace":
|
|
830
|
+
if self._cmd_buffer:
|
|
831
|
+
self._cmd_buffer = self._cmd_buffer[:-1]
|
|
832
|
+
with contextlib.suppress(tk.TclError):
|
|
833
|
+
self._on_mode_change(COMMAND, self._cmd_buffer)
|
|
834
|
+
with contextlib.suppress(tk.TclError):
|
|
835
|
+
self._cmd_lbl.config(text=f":{self._cmd_buffer}")
|
|
836
|
+
else:
|
|
837
|
+
self._set_mode(NORMAL)
|
|
838
|
+
return "break"
|
|
839
|
+
|
|
840
|
+
if char and (char.isprintable() or char in ("!", "%", "/", "\\", " ")):
|
|
841
|
+
self._cmd_buffer += char
|
|
842
|
+
with contextlib.suppress(tk.TclError):
|
|
843
|
+
self._on_mode_change(COMMAND, self._cmd_buffer)
|
|
844
|
+
with contextlib.suppress(tk.TclError):
|
|
845
|
+
self._cmd_lbl.config(text=f":{self._cmd_buffer}")
|
|
846
|
+
|
|
847
|
+
return "break"
|
|
848
|
+
|
|
849
|
+
def _execute_command(self, cmd: str) -> None:
|
|
850
|
+
"""Interpreta e executa o buffer de comando ex.
|
|
851
|
+
|
|
852
|
+
Comandos suportados: ``:q``, ``:q!``, ``:qa``, ``:w``, ``:wq``,
|
|
853
|
+
``:x``, ``:%s/.../.../``, ``:set nu``, ``:set nonu``, ``:N`` (ir para linha).
|
|
854
|
+
|
|
855
|
+
Args:
|
|
856
|
+
cmd: Conteúdo do buffer sem o ``:``.
|
|
857
|
+
"""
|
|
858
|
+
cmd = cmd.strip()
|
|
859
|
+
|
|
860
|
+
if cmd in ("q", "q!", "qa", "qa!"):
|
|
861
|
+
self._do_quit(salvar=False)
|
|
862
|
+
return
|
|
863
|
+
|
|
864
|
+
if cmd in ("w", "w!"):
|
|
865
|
+
self._do_save()
|
|
866
|
+
self._set_mode(NORMAL)
|
|
867
|
+
return
|
|
868
|
+
|
|
869
|
+
if cmd in ("wq", "wq!", "x", "x!"):
|
|
870
|
+
self._do_save()
|
|
871
|
+
self._do_quit(salvar=False)
|
|
872
|
+
return
|
|
873
|
+
|
|
874
|
+
if cmd.startswith("%s/") or cmd.startswith("s/"):
|
|
875
|
+
self._do_substitute(cmd)
|
|
876
|
+
self._set_mode(NORMAL)
|
|
877
|
+
return
|
|
878
|
+
|
|
879
|
+
if cmd in ("set nu", "set number"):
|
|
880
|
+
with contextlib.suppress(tk.TclError):
|
|
881
|
+
self.editor_pane.set_line_numbers(True)
|
|
882
|
+
self._set_mode(NORMAL)
|
|
883
|
+
return
|
|
884
|
+
if cmd in ("set nonu", "set nonumber"):
|
|
885
|
+
with contextlib.suppress(tk.TclError):
|
|
886
|
+
self.editor_pane.set_line_numbers(False)
|
|
887
|
+
self._set_mode(NORMAL)
|
|
888
|
+
return
|
|
889
|
+
|
|
890
|
+
if cmd.startswith("/") and len(cmd) > 1:
|
|
891
|
+
self._ultimo_padrao_busca = cmd[1:]
|
|
892
|
+
self._buscar_proximo(direction=1)
|
|
893
|
+
self._set_mode(NORMAL)
|
|
894
|
+
return
|
|
895
|
+
|
|
896
|
+
if cmd.isdigit():
|
|
897
|
+
target = int(cmd)
|
|
898
|
+
with contextlib.suppress(tk.TclError):
|
|
899
|
+
self._txt.mark_set("insert", f"{target}.0")
|
|
900
|
+
self._txt.see("insert")
|
|
901
|
+
self._set_mode(NORMAL)
|
|
902
|
+
return
|
|
903
|
+
|
|
904
|
+
self._set_mode(NORMAL)
|
|
905
|
+
|
|
906
|
+
def _do_save(self) -> None:
|
|
907
|
+
"""Copia o conteúdo de volta para o editor do Codis e salva."""
|
|
908
|
+
with contextlib.suppress(tk.TclError):
|
|
909
|
+
content = self._txt.get("1.0", "end-1c")
|
|
910
|
+
self._source_text.delete("1.0", "end")
|
|
911
|
+
self._source_text.insert("1.0", content)
|
|
912
|
+
if self._save_cb:
|
|
913
|
+
with contextlib.suppress(tk.TclError):
|
|
914
|
+
self._save_cb()
|
|
915
|
+
self._modified = False
|
|
916
|
+
with contextlib.suppress(tk.TclError):
|
|
917
|
+
self._mod_lbl.config(text="")
|
|
918
|
+
|
|
919
|
+
def _do_quit(self, salvar: bool = False) -> None:
|
|
920
|
+
"""Fecha a janela CLI e retorna ao Codis.
|
|
921
|
+
|
|
922
|
+
Opcionalmente salva antes de fechar.
|
|
923
|
+
|
|
924
|
+
Args:
|
|
925
|
+
salvar: Se ``True``, chama :meth:`_do_save` antes de fechar.
|
|
926
|
+
"""
|
|
927
|
+
if salvar:
|
|
928
|
+
self._do_save()
|
|
929
|
+
self._fechar_janela()
|
|
930
|
+
self._enabled = False
|
|
931
|
+
with contextlib.suppress(tk.TclError):
|
|
932
|
+
self._on_mode_change("")
|
|
933
|
+
if self._quit_cb:
|
|
934
|
+
with contextlib.suppress(tk.TclError):
|
|
935
|
+
self._quit_cb()
|
|
936
|
+
|
|
937
|
+
def _do_substitute(self, cmd: str) -> None:
|
|
938
|
+
"""Implementa substituição ``:%s/padrão/substituto/flags``.
|
|
939
|
+
|
|
940
|
+
Args:
|
|
941
|
+
cmd: Comando ex completo (com ou sem o ``%`` inicial).
|
|
942
|
+
"""
|
|
943
|
+
with contextlib.suppress(re.error, tk.TclError, ValueError):
|
|
944
|
+
partes = cmd.lstrip("%").lstrip("s").lstrip("/").split("/")
|
|
945
|
+
if len(partes) < 2:
|
|
946
|
+
return
|
|
947
|
+
pattern, subst = partes[0], partes[1]
|
|
948
|
+
flags_str = partes[2] if len(partes) > 2 else ""
|
|
949
|
+
global_flag = "g" in flags_str
|
|
950
|
+
re_flags = re.MULTILINE
|
|
951
|
+
if "i" in flags_str:
|
|
952
|
+
re_flags |= re.IGNORECASE
|
|
953
|
+
text = self._txt.get("1.0", "end-1c")
|
|
954
|
+
if global_flag:
|
|
955
|
+
new_val = re.sub(pattern, subst, text, flags=re_flags)
|
|
956
|
+
else:
|
|
957
|
+
new_val = re.sub(pattern, subst, text, count=1, flags=re_flags)
|
|
958
|
+
self._txt.delete("1.0", "end")
|
|
959
|
+
self._txt.insert("1.0", new_val)
|
|
960
|
+
self._modified = True
|
|
961
|
+
|
|
962
|
+
def _buscar_proximo(self, direction: int = 1) -> None:
|
|
963
|
+
"""Busca a próxima ocorrência do padrão de busca atual.
|
|
964
|
+
|
|
965
|
+
Args:
|
|
966
|
+
direction: ``1`` para frente, ``-1`` para trás.
|
|
967
|
+
"""
|
|
968
|
+
pattern = getattr(self, "_ultimo_padrao_busca", "")
|
|
969
|
+
if not pattern or not self._txt:
|
|
970
|
+
return
|
|
971
|
+
with contextlib.suppress(tk.TclError):
|
|
972
|
+
pos_atual = self._txt.index("insert")
|
|
973
|
+
if direction == 1:
|
|
974
|
+
pos = self._txt.search(
|
|
975
|
+
pattern, f"{pos_atual}+1c", stopindex="end", regexp=True
|
|
976
|
+
)
|
|
977
|
+
if not pos:
|
|
978
|
+
pos = self._txt.search(
|
|
979
|
+
pattern, "1.0", stopindex="end", regexp=True)
|
|
980
|
+
else:
|
|
981
|
+
pos = self._txt.search(
|
|
982
|
+
pattern, pos_atual, stopindex="1.0", backwards=True, regexp=True
|
|
983
|
+
)
|
|
984
|
+
if not pos:
|
|
985
|
+
pos = self._txt.search(
|
|
986
|
+
pattern, "end", stopindex="1.0", backwards=True, regexp=True
|
|
987
|
+
)
|
|
988
|
+
if pos:
|
|
989
|
+
self._txt.mark_set("insert", pos)
|
|
990
|
+
self._txt.see("insert")
|
|
991
|
+
|
|
992
|
+
def _visual_key(self, sym: str, char: str) -> str | None:
|
|
993
|
+
"""Processa teclas no modo VISUAL / V-LINE.
|
|
994
|
+
|
|
995
|
+
Args:
|
|
996
|
+
sym: Keysym da tecla.
|
|
997
|
+
char: Caractere imprimível.
|
|
998
|
+
|
|
999
|
+
Returns:
|
|
1000
|
+
Sempre ``"break"``.
|
|
1001
|
+
"""
|
|
1002
|
+
txt = self._txt
|
|
1003
|
+
|
|
1004
|
+
if sym == "Escape":
|
|
1005
|
+
with contextlib.suppress(tk.TclError):
|
|
1006
|
+
txt.tag_remove("sel", "1.0", "end")
|
|
1007
|
+
self._set_mode(NORMAL)
|
|
1008
|
+
return "break"
|
|
1009
|
+
|
|
1010
|
+
movimentos = {
|
|
1011
|
+
("h", "Left"): "insert-1c",
|
|
1012
|
+
("l", "Right"): "insert+1c",
|
|
1013
|
+
("j", "Down"): "insert+1l",
|
|
1014
|
+
("k", "Up"): "insert-1l",
|
|
1015
|
+
}
|
|
1016
|
+
for teclas, dest in movimentos.items():
|
|
1017
|
+
if sym in teclas or char in teclas:
|
|
1018
|
+
with contextlib.suppress(tk.TclError):
|
|
1019
|
+
txt.mark_set("insert", dest)
|
|
1020
|
+
self._update_visual_selection()
|
|
1021
|
+
return "break"
|
|
1022
|
+
|
|
1023
|
+
if char == "y":
|
|
1024
|
+
with contextlib.suppress(tk.TclError):
|
|
1025
|
+
sel = txt.tag_ranges("sel")
|
|
1026
|
+
if sel:
|
|
1027
|
+
self._register = txt.get(sel[0], sel[1])
|
|
1028
|
+
txt.tag_remove("sel", "1.0", "end")
|
|
1029
|
+
self._set_mode(NORMAL)
|
|
1030
|
+
return "break"
|
|
1031
|
+
|
|
1032
|
+
if char == "d":
|
|
1033
|
+
with contextlib.suppress(tk.TclError):
|
|
1034
|
+
sel = txt.tag_ranges("sel")
|
|
1035
|
+
if sel:
|
|
1036
|
+
self._register = txt.get(sel[0], sel[1])
|
|
1037
|
+
txt.delete(sel[0], sel[1])
|
|
1038
|
+
txt.tag_remove("sel", "1.0", "end")
|
|
1039
|
+
self._modified = True
|
|
1040
|
+
self._set_mode(NORMAL)
|
|
1041
|
+
return "break"
|
|
1042
|
+
|
|
1043
|
+
if char == "c":
|
|
1044
|
+
with contextlib.suppress(tk.TclError):
|
|
1045
|
+
sel = txt.tag_ranges("sel")
|
|
1046
|
+
if sel:
|
|
1047
|
+
self._register = txt.get(sel[0], sel[1])
|
|
1048
|
+
txt.delete(sel[0], sel[1])
|
|
1049
|
+
txt.tag_remove("sel", "1.0", "end")
|
|
1050
|
+
self._modified = True
|
|
1051
|
+
self._set_mode(INSERT)
|
|
1052
|
+
return "break"
|
|
1053
|
+
|
|
1054
|
+
return "break"
|
|
1055
|
+
|
|
1056
|
+
def _update_visual_selection(self) -> None:
|
|
1057
|
+
"""Atualiza a tag ``sel`` entre o início da seleção visual e o cursor."""
|
|
1058
|
+
txt = self._txt
|
|
1059
|
+
if not txt:
|
|
1060
|
+
return
|
|
1061
|
+
with contextlib.suppress(tk.TclError):
|
|
1062
|
+
cur = txt.index("insert")
|
|
1063
|
+
start = self._visual_start
|
|
1064
|
+
if txt.compare(start, "<=", cur):
|
|
1065
|
+
a, b = start, cur + "+1c"
|
|
1066
|
+
else:
|
|
1067
|
+
a, b = cur, start + "+1c"
|
|
1068
|
+
if self._mode == VLINE:
|
|
1069
|
+
a_ln = txt.index(a).split(".", 1)[0]
|
|
1070
|
+
b_ln = txt.index(b).split(".", 1)[0]
|
|
1071
|
+
a = f"{a_ln}.0"
|
|
1072
|
+
b = f"{b_ln}.end+1c"
|
|
1073
|
+
txt.tag_remove("sel", "1.0", "end")
|
|
1074
|
+
txt.tag_add("sel", a, b)
|