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.
Files changed (329) hide show
  1. codis-1.1.1.dist-info/METADATA +194 -0
  2. codis-1.1.1.dist-info/RECORD +329 -0
  3. codis-1.1.1.dist-info/WHEEL +5 -0
  4. codis-1.1.1.dist-info/entry_points.txt +5 -0
  5. codis-1.1.1.dist-info/licenses/LICENSE +21 -0
  6. codis-1.1.1.dist-info/top_level.txt +2 -0
  7. run.py +190 -0
  8. src/__init__.py +1 -0
  9. src/__main__.py +81 -0
  10. src/_app_build.py +1507 -0
  11. src/_app_editor.py +1274 -0
  12. src/_app_kui.py +825 -0
  13. src/_app_lsp.py +625 -0
  14. src/_app_recovery.py +189 -0
  15. src/_app_settings.py +1385 -0
  16. src/_app_tools.py +2471 -0
  17. src/_app_webpreview.py +126 -0
  18. src/_font_safety.py +127 -0
  19. src/_shells.py +172 -0
  20. src/app.py +1488 -0
  21. src/chat/__init__.py +1 -0
  22. src/chat/adapters/__init__.py +33 -0
  23. src/chat/adapters/base.py +209 -0
  24. src/chat/adapters/discord.py +190 -0
  25. src/chat/adapters/http.py +78 -0
  26. src/chat/adapters/irc.py +360 -0
  27. src/chat/adapters/matrix.py +219 -0
  28. src/chat/adapters/mattermost.py +178 -0
  29. src/chat/adapters/mqtt.py +165 -0
  30. src/chat/adapters/slack.py +204 -0
  31. src/chat/adapters/telegram.py +117 -0
  32. src/chat/adapters/ws.py +154 -0
  33. src/chat/adapters/xmpp.py +337 -0
  34. src/chat/history.py +76 -0
  35. src/chat/models.py +207 -0
  36. src/chat/probe.py +79 -0
  37. src/chat/session.py +446 -0
  38. src/chat/util.py +125 -0
  39. src/collab/__init__.py +1 -0
  40. src/collab/net.py +411 -0
  41. src/collab/ot.py +311 -0
  42. src/collab/session.py +141 -0
  43. src/collab/tk_adapter.py +134 -0
  44. src/config.py +335 -0
  45. src/constants.py +2552 -0
  46. src/dep_catalog.py +446 -0
  47. src/diff/__init__.py +1 -0
  48. src/diff/engine.py +247 -0
  49. src/dpi.py +30 -0
  50. src/editor/__init__.py +1 -0
  51. src/editor/_pane_lsp.py +2937 -0
  52. src/editor/_pane_utils.py +171 -0
  53. src/editor/autocomplete.py +607 -0
  54. src/editor/code_folding.py +836 -0
  55. src/editor/color_preview.py +382 -0
  56. src/editor/complexity_lens.py +281 -0
  57. src/editor/diff_pane.py +623 -0
  58. src/editor/file_watcher.py +144 -0
  59. src/editor/focus_block.py +236 -0
  60. src/editor/heatmap.py +141 -0
  61. src/editor/inlay_hints.py +366 -0
  62. src/editor/inline_blame.py +429 -0
  63. src/editor/kdocs.py +3376 -0
  64. src/editor/large_file.py +488 -0
  65. src/editor/ligatures.py +180 -0
  66. src/editor/line_numbers.py +598 -0
  67. src/editor/minimap.py +691 -0
  68. src/editor/multi_cursor.py +269 -0
  69. src/editor/pane.py +2082 -0
  70. src/editor/rhythm.py +206 -0
  71. src/editor/save_hooks.py +43 -0
  72. src/editor/smart_selection.py +425 -0
  73. src/editor/smart_tips.py +719 -0
  74. src/editor/snippets.py +411 -0
  75. src/editor/sticky_note_gutter.py +410 -0
  76. src/editor/sticky_scroll.py +385 -0
  77. src/editor/suggest.py +464 -0
  78. src/editor/text_transforms.py +310 -0
  79. src/editor/vim_mode.py +1074 -0
  80. src/events/__init__.py +84 -0
  81. src/events/bus.py +427 -0
  82. src/events/correlator.py +244 -0
  83. src/events/kinds.py +125 -0
  84. src/events/pipeline.py +264 -0
  85. src/events/stream.py +416 -0
  86. src/events/window.py +204 -0
  87. src/extcompat/__init__.py +19 -0
  88. src/extcompat/code/__init__.py +13 -0
  89. src/extcompat/code/consent.py +162 -0
  90. src/extcompat/code/host.py +353 -0
  91. src/extcompat/code/hosts/py_host.py +763 -0
  92. src/extcompat/code/locate.py +105 -0
  93. src/extcompat/code/manager.py +325 -0
  94. src/extcompat/code/permissions.py +154 -0
  95. src/extcompat/code/sandbox.py +60 -0
  96. src/extcompat/colors.py +131 -0
  97. src/extcompat/common.py +184 -0
  98. src/extcompat/cson.py +269 -0
  99. src/extcompat/formats/__init__.py +22 -0
  100. src/extcompat/formats/_tm.py +189 -0
  101. src/extcompat/formats/_util.py +31 -0
  102. src/extcompat/formats/base16.py +66 -0
  103. src/extcompat/formats/brackets.py +172 -0
  104. src/extcompat/formats/eclipse.py +193 -0
  105. src/extcompat/formats/emacs.py +361 -0
  106. src/extcompat/formats/geany.py +147 -0
  107. src/extcompat/formats/generic.py +184 -0
  108. src/extcompat/formats/gtksource.py +117 -0
  109. src/extcompat/formats/helix.py +91 -0
  110. src/extcompat/formats/jetbrains.py +343 -0
  111. src/extcompat/formats/kate.py +130 -0
  112. src/extcompat/formats/micro.py +131 -0
  113. src/extcompat/formats/nano.py +111 -0
  114. src/extcompat/formats/notepadpp.py +140 -0
  115. src/extcompat/formats/pulsar.py +165 -0
  116. src/extcompat/formats/pyides.py +163 -0
  117. src/extcompat/formats/sublime.py +340 -0
  118. src/extcompat/jsonc.py +65 -0
  119. src/extcompat/lessish.py +128 -0
  120. src/extcompat/manager.py +122 -0
  121. src/extcompat/market/__init__.py +63 -0
  122. src/extcompat/market/sources.py +211 -0
  123. src/extcompat/model.py +88 -0
  124. src/extcompat/net.py +228 -0
  125. src/extcompat/openvsx.py +63 -0
  126. src/extcompat/readers.py +362 -0
  127. src/extcompat/registry.py +73 -0
  128. src/extcompat/safexml.py +63 -0
  129. src/extcompat/sexp.py +187 -0
  130. src/extcompat/sources.py +105 -0
  131. src/extcompat/store.py +276 -0
  132. src/extcompat/textmate.py +214 -0
  133. src/extcompat/themes.py +487 -0
  134. src/extcompat/yamlite.py +294 -0
  135. src/fileio.py +94 -0
  136. src/fs_ops.py +106 -0
  137. src/i18n.py +233 -0
  138. src/ia/__init__.py +1 -0
  139. src/ia/actions.py +295 -0
  140. src/ia/approval_gate.py +672 -0
  141. src/ia/checkpoints.py +308 -0
  142. src/ia/context_builder.py +921 -0
  143. src/ia/dialdiff.py +408 -0
  144. src/ia/iaspace.py +2078 -0
  145. src/ia/pair.py +296 -0
  146. src/ia/providers.py +954 -0
  147. src/ia/session.py +335 -0
  148. src/ia/toolbox.py +2524 -0
  149. src/launcher_actions.py +204 -0
  150. src/lint/__init__.py +1 -0
  151. src/lint/manager.py +1058 -0
  152. src/locales/.translate_manifest.json +64170 -0
  153. src/locales/de.json +4936 -0
  154. src/locales/en.json +4936 -0
  155. src/locales/es.json +4936 -0
  156. src/locales/fr.json +4936 -0
  157. src/locales/it.json +4936 -0
  158. src/locales/ja.json +4936 -0
  159. src/locales/ko.json +4936 -0
  160. src/locales/nl.json +4936 -0
  161. src/locales/pl.json +4936 -0
  162. src/locales/pt-BR.json +4936 -0
  163. src/locales/ru.json +4936 -0
  164. src/locales/tr.json +4936 -0
  165. src/locales/uk.json +4936 -0
  166. src/locales/zh-CN.json +4936 -0
  167. src/lsp/__init__.py +26 -0
  168. src/lsp/client.py +2300 -0
  169. src/lsp/dap_client.py +480 -0
  170. src/lsp/edits.py +84 -0
  171. src/lsp/framing.py +73 -0
  172. src/lsp/protocol.py +931 -0
  173. src/main.py +260 -0
  174. src/memtrim.py +91 -0
  175. src/plugins/__init__.py +1 -0
  176. src/plugins/api.py +1761 -0
  177. src/plugins/loader.py +571 -0
  178. src/plugins/process_runner.py +519 -0
  179. src/plugins/registry.py +342 -0
  180. src/plugins/safety.py +367 -0
  181. src/plugins/startup.py +195 -0
  182. src/plugins/store.py +1178 -0
  183. src/proc_registry.py +278 -0
  184. src/pyexec.py +394 -0
  185. src/recovery.py +259 -0
  186. src/stall_trace.py +92 -0
  187. src/standalone.py +1070 -0
  188. src/startup_profile.py +35 -0
  189. src/syntax/__init__.py +1 -0
  190. src/syntax/highlighter.py +776 -0
  191. src/syntax/patterns.py +584 -0
  192. src/system_profile.py +430 -0
  193. src/terminal/backends.py +658 -0
  194. src/terminal/internal.py +346 -0
  195. src/terminal/keys.py +138 -0
  196. src/terminal/palette.py +67 -0
  197. src/terminal/session.py +283 -0
  198. src/terminal/shells.py +79 -0
  199. src/terminal/view.py +489 -0
  200. src/terminal/vt.py +870 -0
  201. src/textfmt.py +22 -0
  202. src/theme/__init__.py +1 -0
  203. src/theme/base.py +1281 -0
  204. src/theme/colors.py +49 -0
  205. src/theme/manager.py +602 -0
  206. src/theme/utils.py +312 -0
  207. src/toolbox.py +329 -0
  208. src/trash_core.py +531 -0
  209. src/ui/__init__.py +1 -0
  210. src/ui/_perf_utils.py +285 -0
  211. src/ui/_persistence_utils.py +93 -0
  212. src/ui/accessibility.py +843 -0
  213. src/ui/activity_bar.py +860 -0
  214. src/ui/app_embed.py +434 -0
  215. src/ui/archive_panel.py +608 -0
  216. src/ui/bookmarks.py +314 -0
  217. src/ui/breadcrumb.py +383 -0
  218. src/ui/calculator_panel.py +982 -0
  219. src/ui/calendar_panel.py +1218 -0
  220. src/ui/chat_panel.py +1271 -0
  221. src/ui/chat_profile_dialog.py +278 -0
  222. src/ui/chat_render.py +128 -0
  223. src/ui/clock_panel.py +810 -0
  224. src/ui/code_outline.py +364 -0
  225. src/ui/code_runner.py +729 -0
  226. src/ui/code_stats.py +546 -0
  227. src/ui/collab_panel.py +1009 -0
  228. src/ui/color_picker.py +547 -0
  229. src/ui/command_palette.py +452 -0
  230. src/ui/cursor_manager.py +750 -0
  231. src/ui/custom_keywords_panel.py +413 -0
  232. src/ui/debug_panel.py +1037 -0
  233. src/ui/dependency_graph.py +692 -0
  234. src/ui/diff_panel.py +381 -0
  235. src/ui/docs_panel.py +514 -0
  236. src/ui/doom_embed.py +349 -0
  237. src/ui/dropdown.py +321 -0
  238. src/ui/easter_eggs.py +979 -0
  239. src/ui/env_manager.py +666 -0
  240. src/ui/extcode_bridge.py +215 -0
  241. src/ui/extcode_dialogs.py +412 -0
  242. src/ui/extcompat_dialog.py +583 -0
  243. src/ui/file_timeline.py +319 -0
  244. src/ui/file_tree.py +1208 -0
  245. src/ui/find_in_files.py +1355 -0
  246. src/ui/flowchart_panel.py +727 -0
  247. src/ui/formatter_panel.py +490 -0
  248. src/ui/git_auth.py +763 -0
  249. src/ui/git_clone_dialog.py +487 -0
  250. src/ui/git_panel.py +1483 -0
  251. src/ui/grab_safe.py +84 -0
  252. src/ui/internal_python_dialog.py +98 -0
  253. src/ui/k_ui/__init__.py +1305 -0
  254. src/ui/k_ui/_bgrenderer.py +317 -0
  255. src/ui/k_ui/_colors.py +213 -0
  256. src/ui/k_ui/_dock.py +545 -0
  257. src/ui/k_ui/_easter.py +290 -0
  258. src/ui/k_ui/_engine.py +5448 -0
  259. src/ui/k_ui/_perf.py +333 -0
  260. src/ui/k_ui/_tkutil.py +7 -0
  261. src/ui/k_ui/_tooltip.py +365 -0
  262. src/ui/k_ui/_widgets.py +1204 -0
  263. src/ui/k_ui/_world.py +837 -0
  264. src/ui/key_remapper.py +856 -0
  265. src/ui/launcher.py +1252 -0
  266. src/ui/lazy_panel.py +73 -0
  267. src/ui/macro_recorder.py +610 -0
  268. src/ui/menu_bar.py +898 -0
  269. src/ui/output_panel.py +321 -0
  270. src/ui/paint_canvas.py +1000 -0
  271. src/ui/paint_engine.py +535 -0
  272. src/ui/paint_panel.py +888 -0
  273. src/ui/panel_detach.py +112 -0
  274. src/ui/performance_panel.py +861 -0
  275. src/ui/pip_manager.py +1758 -0
  276. src/ui/plugin_panel.py +1586 -0
  277. src/ui/pomodoro_panel.py +447 -0
  278. src/ui/problems.py +566 -0
  279. src/ui/process_manager.py +1657 -0
  280. src/ui/project_templates.py +775 -0
  281. src/ui/recovery_dialog.py +122 -0
  282. src/ui/regex_playground.py +304 -0
  283. src/ui/remote_adapters.py +1398 -0
  284. src/ui/remote_browser.py +1224 -0
  285. src/ui/remote_profile_dialog.py +342 -0
  286. src/ui/render_panel.py +1293 -0
  287. src/ui/rest_client.py +549 -0
  288. src/ui/scratchpad.py +548 -0
  289. src/ui/search_bar.py +1274 -0
  290. src/ui/settings_editor.py +3349 -0
  291. src/ui/settings_window.py +1554 -0
  292. src/ui/snippets_panel.py +597 -0
  293. src/ui/sql_studio.py +1815 -0
  294. src/ui/status_bar.py +438 -0
  295. src/ui/tab_bar.py +654 -0
  296. src/ui/task_manager.py +1773 -0
  297. src/ui/terminal.py +525 -0
  298. src/ui/theme_preview_panel.py +851 -0
  299. src/ui/thread_safe_tk.py +152 -0
  300. src/ui/time_tracker.py +574 -0
  301. src/ui/tkbind.py +43 -0
  302. src/ui/todo_panel.py +358 -0
  303. src/ui/toolbox_panels.py +658 -0
  304. src/ui/trash_manager.py +657 -0
  305. src/ui/ui_scale.py +294 -0
  306. src/ui/ux_enhancements.py +41 -0
  307. src/ui/web_preview.py +397 -0
  308. src/ui/webdev.py +630 -0
  309. src/ui/welcome.py +567 -0
  310. src/ui/window_embed.py +1500 -0
  311. src/ui/wizard.py +1550 -0
  312. src/ui/workspace_switcher.py +418 -0
  313. src/ui/workspace_trust.py +370 -0
  314. src/ui/zen_audio.py +354 -0
  315. src/ui/zen_media.py +2271 -0
  316. src/ui/zen_media_client.py +303 -0
  317. src/ui/zen_media_host.py +329 -0
  318. src/ui/zen_player.py +907 -0
  319. src/ui/zen_player_widgets.py +700 -0
  320. src/updater/__init__.py +11 -0
  321. src/updater/assets.py +145 -0
  322. src/updater/backup.py +101 -0
  323. src/updater/channel.py +221 -0
  324. src/updater/dialog.py +492 -0
  325. src/updater/integrity.py +111 -0
  326. src/updater/manager.py +727 -0
  327. src/updater/result.py +114 -0
  328. src/venv_runtime.py +531 -0
  329. src/workspace_state.py +25 -0
@@ -0,0 +1,598 @@
1
+ """Codis - LineNumbers (Gutter).
2
+
3
+ Princípio de layout (simples e correto):
4
+ - A barra tem EXATAMENTE a largura necessária para caber o maior número
5
+ possível + espaço para o breakpoint à esquerda e fold icon à direita.
6
+ - O número é renderizado com anchor="w" a partir de x=_ZONE_BP (borda
7
+ esquerda da zona numérica), crescendo para a DIREITA.
8
+ - O frame pai NÃO tem width fixo nem pack_propagate(False) -
9
+ o canvas controla sua própria largura via config(width=...).
10
+ - Resize manual: arrastar a borda direita do canvas redimensiona o frame
11
+ pai via _gutter_frame.config(width=...) com pack_propagate(False)
12
+ temporário, devolvendo o controle ao canvas no reset.
13
+
14
+ Layout de zonas (esquerda -> direita):
15
+ [_ZONE_BP px] [número left-aligned] [_ZONE_PAD px] [_ZONE_FOLD px] [_ZONE_LINT px]
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import contextlib
21
+ import logging
22
+ import tkinter as tk
23
+ import tkinter.font as tkfont
24
+ from collections.abc import Callable
25
+ from typing import Any
26
+
27
+ from src.constants import FONT_MONO, FONT_SIZE
28
+ from src.editor.kdocs import KDocsNotes, KDocsParser
29
+ from src.lint.manager import Diag
30
+ from src.theme.base import Theme
31
+
32
+ logger = logging.getLogger("Codis")
33
+
34
+ _ZONE_BP = 14
35
+ _ZONE_PAD = 6
36
+ _ZONE_FOLD = 14
37
+ _ZONE_LINT = 8
38
+
39
+
40
+ class LineNumbers(tk.Canvas):
41
+ """Widget de gutter: números de linha, breakpoints, ícones de fold e dots de lint.
42
+
43
+ Renderizado como ``tk.Canvas`` dimensionado para sempre caber o número de
44
+ linha mais largo, mais zonas fixas para breakpoints (esquerda), ícones de fold
45
+ e dots de lint (direita). Suporta redimensionamento manual arrastando a borda direita.
46
+ """
47
+
48
+ BP_RADIUS = 5
49
+ _MIN_W = 40
50
+ _MAX_W = 240
51
+
52
+ def __init__(
53
+ self,
54
+ parent: tk.Widget,
55
+ text_widget: tk.Text,
56
+ theme: Theme,
57
+ **kw,
58
+ ) -> None:
59
+ super().__init__(parent, bd=0, highlightthickness=0, **kw)
60
+
61
+ self._txt = text_widget
62
+ self._theme = theme
63
+ self._font = (FONT_MONO, FONT_SIZE)
64
+ self._after_id: str | None = None
65
+
66
+ self._current_line = 1
67
+ # Modo gigante: a janela do widget começa na linha ``line_offset + 1`` de um arquivo com ``line_total`` linhas.
68
+ self.line_offset = 0
69
+ self.line_total = 0
70
+ self._breakpoints: set[int] = set()
71
+ self._lint_lines: dict[int, str] = {}
72
+ self._kdocs_lines: dict[int, str] = {}
73
+ self._marked_lines: set[int] = set()
74
+ self._fold_map: dict[int, bool] = {}
75
+ self._hover_line: int | None = None
76
+
77
+ self._on_fold_toggle: Callable[[int], None] | None = None
78
+ self._on_marked_change: Callable[[set[int]], None] | None = None
79
+ self._on_breakpoint_toggle: Callable[[set[int]], None] | None = None
80
+
81
+ self._line_geo: dict[int, tuple[int, int]] = {}
82
+
83
+ self._desired_w: int = self._MIN_W
84
+
85
+ self._resize_x: int | None = None
86
+ self._manual_width: int | None = None
87
+
88
+ self._redrawing: bool = False
89
+
90
+ self._apply_theme(theme)
91
+ self._update_width()
92
+
93
+ for ev in (
94
+ "<KeyRelease>",
95
+ "<ButtonRelease-1>",
96
+ "<MouseWheel>",
97
+ "<Configure>",
98
+ "<<Change>>",
99
+ "<<Modified>>",
100
+ "<FocusIn>",
101
+ ):
102
+ with contextlib.suppress(tk.TclError):
103
+ self._txt.bind(ev, self._schedule_redraw, add="+")
104
+
105
+ self.bind("<Configure>", self._schedule_redraw)
106
+ self.bind("<ButtonPress-1>", self._on_press)
107
+ self.bind("<B1-Motion>", self._resize_drag)
108
+ self.bind("<ButtonRelease-1>", self._resize_end)
109
+ self.bind("<Double-Button-1>", self._resize_reset)
110
+ self.bind("<Motion>", self._on_motion)
111
+ self.bind("<Leave>", self._on_leave)
112
+
113
+ def _apply_theme(self, t: Theme) -> None:
114
+ """Armazena o tema e atualiza a cor de fundo do canvas."""
115
+ self._theme = t
116
+ self.config(bg=t.gutter_bg)
117
+
118
+ def update_theme(self, t: Theme) -> None:
119
+ """Aplica um novo tema e força um redesenho imediato."""
120
+ self._apply_theme(t)
121
+ self.redraw()
122
+
123
+ def update_font(self, family: str, size: int) -> None:
124
+ """Atualiza a fonte usada nos números de linha e recalcula a largura do gutter.
125
+
126
+ Args:
127
+ family: Nome da família de fonte (ex.: ``"JetBrains Mono"``).
128
+ size: Tamanho da fonte em pontos.
129
+ """
130
+ self._font = family, size
131
+ self._update_width()
132
+ self.redraw()
133
+
134
+ def _measure_num_width(self, digits: int) -> int:
135
+ """Retorna a largura em pixels de um número com ``digits`` dígitos na fonte atual.
136
+
137
+ Usa ``"8"`` repetido, que costuma ser o dígito mais largo em fontes monoespaçadas.
138
+ Retorna ``digits * 9`` como fallback se a fonte não puder ser medida.
139
+ """
140
+ try:
141
+ fnt = tkfont.Font(family=self._font[0], size=self._font[1])
142
+ return fnt.measure("8" * digits)
143
+ except Exception:
144
+ return digits * 9
145
+
146
+ def _calc_desired_w(self, total_lines: int) -> int:
147
+ """Calcula a largura ideal do canvas para caber ``total_lines`` sem corte.
148
+
149
+ Layout: ``[BP] [número] [PAD] [FOLD] [LINT]``, limitado a ``[_MIN_W, _MAX_W]``.
150
+
151
+ Args:
152
+ total_lines: Número atual de linhas do widget de texto.
153
+
154
+ Returns:
155
+ Largura alvo em pixels.
156
+ """
157
+ digits = max(len(str(total_lines)), 1)
158
+ num_w = self._measure_num_width(digits)
159
+ w = _ZONE_BP + num_w + _ZONE_PAD + _ZONE_FOLD + _ZONE_LINT
160
+ return max(self._MIN_W, min(w, self._MAX_W))
161
+
162
+ def _update_width(self) -> None:
163
+ """Recalcula e aplica a largura do canvas, propagando ao frame pai.
164
+
165
+ Ignora a atualização se a largura alvo já coincide com ``_desired_w``.
166
+ No modo de redimensionamento manual, usa ``_manual_width`` em vez do valor calculado.
167
+ """
168
+ if self._manual_width is not None:
169
+ target = self._manual_width
170
+ else:
171
+ try:
172
+ total = max(1, int(self._txt.index("end").split(".")[0]) - 1)
173
+ except Exception:
174
+ total = 1
175
+ target = self._calc_desired_w(max(total + self.line_offset, self.line_total))
176
+
177
+ if target == self._desired_w:
178
+ return
179
+
180
+ self._desired_w = target
181
+ self.config(width=target)
182
+
183
+ parent = self.master
184
+ if parent and parent.winfo_exists():
185
+ with contextlib.suppress(Exception):
186
+ parent.config(width=target)
187
+
188
+ def _schedule_redraw(self, e: Any = None) -> None:
189
+ """Debounce adaptativo: 16ms para scroll/configure (suave), 50ms para conteudo.
190
+
191
+ Scroll chama este método em alta frequência - debounce de 16ms (~60fps)
192
+ mantém o gutter sincronizado com o editor sem sobrecarregar o event loop.
193
+ Mudanças de conteúdo usam 50ms para agrupar keystroke rápidos.
194
+ """
195
+ if not self.winfo_exists():
196
+ return
197
+ if self._redrawing:
198
+ try:
199
+ if str(e.type) in ("22", "Configure"):
200
+ return
201
+ except Exception:
202
+ logger.debug(
203
+ "Falha ao checar tipo de evento em redraw.", exc_info=True)
204
+ try:
205
+ etype = str(e.type) if e is not None else ""
206
+ delay = (
207
+ 16
208
+ if etype
209
+ in ("38", "22", "5", "MouseWheel", "Configure", "ButtonRelease")
210
+ else 50
211
+ )
212
+ except Exception:
213
+ delay = 50
214
+ if self._after_id:
215
+ with contextlib.suppress(tk.TclError):
216
+ self.after_cancel(self._after_id)
217
+ self._after_id = self.after(delay, self.redraw)
218
+
219
+ def redraw(self, _e: Any = None) -> None:
220
+ """Redesenha o gutter inteiro, protegido contra chamadas reentrantes."""
221
+ if not self.winfo_exists():
222
+ return
223
+ self._redrawing = True
224
+ try:
225
+ self._redraw_impl()
226
+ finally:
227
+ self._redrawing = False
228
+
229
+ def _redraw_impl(self) -> None:
230
+ """Renderiza todos os elementos do gutter: separador, breakpoints, números, ícones de fold e dots de lint."""
231
+ with contextlib.suppress(tk.TclError):
232
+ self.delete("all")
233
+
234
+ with contextlib.suppress(tk.TclError, ValueError):
235
+ ins_ln = int(self._txt.index(tk.INSERT).split(".")[0])
236
+ if ins_ln != self._current_line:
237
+ self._current_line = ins_ln
238
+
239
+ t = self._theme
240
+ self._update_width()
241
+
242
+ raw_w = self.winfo_width()
243
+ w = raw_w if raw_w > 1 else self._desired_w
244
+ h_canvas = max(1, self.winfo_height())
245
+
246
+ x_bp = _ZONE_BP // 2
247
+ x_num = _ZONE_BP
248
+ x_fold = w - _ZONE_LINT - _ZONE_FOLD // 2
249
+ x_lint = w - _ZONE_LINT // 2
250
+
251
+ sep_color = getattr(t, "gutter_border", getattr(t, "border", "#444"))
252
+ self.create_line(w - 1, 0, w - 1, h_canvas, fill=sep_color, width=1)
253
+
254
+ try:
255
+ total = max(1, int(self._txt.index("end").split(".")[0]) - 1)
256
+ except Exception:
257
+ return
258
+
259
+ try:
260
+ first_n = int(self._txt.index("@0,0").split(".")[0])
261
+ except Exception:
262
+ first_n = 1
263
+ first_n = max(1, first_n)
264
+
265
+ self._line_geo = {}
266
+ fold_color_base = getattr(
267
+ t, "gutter_fold_fg", getattr(t, "accent", "#89b4fa"))
268
+
269
+ try:
270
+ txt_root_y = self._txt.winfo_rooty()
271
+ canvas_root_y = self.winfo_rooty()
272
+ _sticky_offset = max(0, txt_root_y - canvas_root_y)
273
+ except Exception:
274
+ _sticky_offset = 0
275
+
276
+ # Só as linhas que cabem na altura do gutter: sem este limite, cada redesenho consultava
277
+ # o Tk linha por linha até o fim do arquivo (centenas de milhares de chamadas).
278
+ try:
279
+ last_n = int(self._txt.index(f"@0,{max(0, h_canvas - _sticky_offset)}").split(".")[0]) + 1
280
+ except (tk.TclError, ValueError):
281
+ last_n = total
282
+ for n in range(first_n, min(total, last_n) + 1):
283
+ try:
284
+ dl = self._txt.dlineinfo(f"{n}.0")
285
+ except tk.TclError:
286
+ break
287
+ if dl is None:
288
+ continue
289
+ _x, dy, _dw, dh, _base = dl
290
+ dy += _sticky_offset
291
+ if dy < 0:
292
+ continue
293
+ if dy > h_canvas:
294
+ break
295
+
296
+ cy = dy + dh // 2
297
+ self._line_geo[n] = (dy, dy + dh)
298
+
299
+ r = self.BP_RADIUS
300
+ if n in self._breakpoints:
301
+ self.create_oval(
302
+ x_bp - r,
303
+ cy - r,
304
+ x_bp + r,
305
+ cy + r,
306
+ fill="#f87171",
307
+ outline="",
308
+ tags="bp",
309
+ )
310
+ else:
311
+ self.create_oval(
312
+ x_bp - r,
313
+ cy - r,
314
+ x_bp + r,
315
+ cy + r,
316
+ fill="",
317
+ outline="",
318
+ tags=f"bp_{n}",
319
+ )
320
+
321
+ if n in self._fold_map:
322
+ folded = self._fold_map[n]
323
+ hovered = n == self._hover_line
324
+ icon = "▸" if folded else "▾"
325
+ icon_color = t.gutter_active_fg if hovered else fold_color_base
326
+ self.create_text(
327
+ x_fold,
328
+ cy,
329
+ text=icon,
330
+ anchor="center",
331
+ fill=icon_color,
332
+ font=(self._font[0], self._font[1] - 1),
333
+ tags=("fold_icon", f"fi_{n}"),
334
+ )
335
+
336
+ dot = self._lint_lines.get(n) or self._kdocs_lines.get(n)
337
+ if dot:
338
+ self.create_oval(
339
+ x_lint - 3,
340
+ cy - 3,
341
+ x_lint + 3,
342
+ cy + 3,
343
+ fill=dot,
344
+ outline="",
345
+ )
346
+
347
+ is_cur = n == self._current_line
348
+ is_mark = n in self._marked_lines
349
+
350
+ if is_cur:
351
+ fg = t.gutter_active_fg
352
+ font = self._font[0], self._font[1], "bold"
353
+ elif is_mark:
354
+ fg = getattr(t, "accent", "#4fc3f7")
355
+ font = self._font[0], self._font[1], "bold"
356
+ else:
357
+ fg = t.gutter_fg
358
+ font = self._font
359
+
360
+ self.create_text(
361
+ x_num,
362
+ cy,
363
+ text=str(n + self.line_offset),
364
+ anchor="w",
365
+ fill=fg,
366
+ font=font,
367
+ )
368
+
369
+ def _line_at_y(self, y: int) -> int | None:
370
+ """Retorna o número da linha cuja linha renderizada contém o pixel ``y``, ou a
371
+ linha mais próxima se ``y`` estiver entre linhas. Retorna ``None`` se não há cache.
372
+ """
373
+ for lnum, (y0, y1) in self._line_geo.items():
374
+ if y0 <= y < y1:
375
+ return lnum
376
+ if not self._line_geo:
377
+ return None
378
+ return min(
379
+ self._line_geo.items(), key=lambda kv: abs((kv[1][0] + kv[1][1]) // 2 - y)
380
+ )[0]
381
+
382
+ _RESIZE_ZONE = 8
383
+
384
+ def _in_resize_zone(self, x: int) -> bool:
385
+ """Retorna ``True`` se ``x`` está dentro dos ``_RESIZE_ZONE`` px da borda direita."""
386
+ raw = self.winfo_width()
387
+ w = raw if raw > 1 else self._desired_w
388
+ return x >= w - self._RESIZE_ZONE
389
+
390
+ def _on_press(self, e: Any) -> None:
391
+ """Roteia um clique com botão esquerdo para início de resize ou tratamento de clique."""
392
+ if self._in_resize_zone(e.x):
393
+ self._resize_x = e.x
394
+ self.config(cursor="sb_h_double_arrow")
395
+ else:
396
+ self._on_click(e)
397
+
398
+ def _resize_drag(self, e: Any) -> None:
399
+ """Ajusta a largura do gutter enquanto o usuário arrasta a borda direita."""
400
+ if self._resize_x is None:
401
+ return
402
+ delta = e.x - self._resize_x
403
+ raw = self.winfo_width()
404
+ cur_w = raw if raw > 1 else self._desired_w
405
+ new_w = max(self._MIN_W, min(self._MAX_W, cur_w + delta))
406
+ if new_w == self._desired_w:
407
+ return
408
+
409
+ self._manual_width = new_w
410
+ self._desired_w = new_w
411
+ self._resize_x = e.x
412
+
413
+ self.config(width=new_w)
414
+
415
+ parent = self.master
416
+ if parent and parent.winfo_exists():
417
+ with contextlib.suppress(Exception):
418
+ parent.pack_propagate(False)
419
+ parent.config(width=new_w)
420
+
421
+ self.redraw()
422
+
423
+ def _resize_end(self, _e: Any) -> None:
424
+ """Clears the resize anchor and resets the cursor after a drag ends."""
425
+ if self._resize_x is not None:
426
+ self._resize_x = None
427
+ self.config(cursor="")
428
+
429
+ def _resize_reset(self, e: Any) -> None:
430
+ """Double-click on the right border resets the gutter to automatic width."""
431
+ if not self._in_resize_zone(e.x):
432
+ return
433
+ self._manual_width = None
434
+ parent = self.master
435
+ if parent and parent.winfo_exists():
436
+ with contextlib.suppress(Exception):
437
+ parent.pack_propagate(True)
438
+ self._update_width()
439
+ self.redraw()
440
+
441
+ def _fold_zone_x(self) -> int:
442
+ """Returns the left pixel boundary of the fold icon zone."""
443
+ raw = self.winfo_width()
444
+ w = raw if raw > 1 else self._desired_w
445
+ return w - _ZONE_LINT - _ZONE_FOLD
446
+
447
+ def _on_motion(self, e: Any) -> None:
448
+ """Updates the cursor and hover highlight as the pointer moves over the gutter."""
449
+ if self._in_resize_zone(e.x):
450
+ self.config(cursor="sb_h_double_arrow")
451
+ if self._hover_line is not None:
452
+ self._hover_line = None
453
+ self.redraw()
454
+ return
455
+
456
+ if not self._fold_map:
457
+ self.config(cursor="")
458
+ return
459
+
460
+ line = self._line_at_y(e.y)
461
+ in_fold_zone = (
462
+ line is not None and line in self._fold_map and e.x >= self._fold_zone_x()
463
+ )
464
+ new_hover = line if in_fold_zone else None
465
+ if new_hover != self._hover_line:
466
+ self._hover_line = new_hover
467
+ self.config(cursor="hand2" if in_fold_zone else "")
468
+ self.redraw()
469
+
470
+ def _on_leave(self, _e: Any = None) -> None:
471
+ """Clears the hover highlight when the pointer leaves the gutter."""
472
+ if self._hover_line is not None:
473
+ self._hover_line = None
474
+ self.config(cursor="")
475
+ self.redraw()
476
+
477
+ def _on_click(self, e: Any) -> None:
478
+ """Handles left-button clicks: fold toggle, Alt+click line mark, or breakpoint."""
479
+ if self._in_resize_zone(e.x):
480
+ return
481
+ line = self._line_at_y(e.y)
482
+ if line is None:
483
+ return
484
+
485
+ if e.x >= self._fold_zone_x() and line in self._fold_map:
486
+ if self._on_fold_toggle:
487
+ self._on_fold_toggle(line)
488
+ return
489
+
490
+ if e.state & 0x8:
491
+ if line in self._marked_lines:
492
+ self._marked_lines.discard(line)
493
+ else:
494
+ self._marked_lines.add(line)
495
+ self.redraw()
496
+ if self._on_marked_change:
497
+ self._on_marked_change(set(self._marked_lines))
498
+ return
499
+
500
+ if line in self._breakpoints:
501
+ self._breakpoints.discard(line)
502
+ else:
503
+ self._breakpoints.add(line)
504
+ self.redraw()
505
+ if self._on_breakpoint_toggle:
506
+ self._on_breakpoint_toggle(set(self._breakpoints))
507
+
508
+ def set_current_line(self, line: int) -> None:
509
+ """Updates the highlighted current-line number and schedules a redraw.
510
+
511
+ Args:
512
+ line: 1-based line number of the editor cursor.
513
+ """
514
+ if self._current_line != line:
515
+ self._current_line = line
516
+ self._schedule_redraw()
517
+
518
+ def set_fold_map(self, fold_map: dict[int, bool]) -> None:
519
+ """Replaces the fold state map and schedules a redraw.
520
+
521
+ Args:
522
+ fold_map: ``{start_line: folded}`` dict from the folding engine.
523
+ """
524
+ self._fold_map = fold_map
525
+ self._schedule_redraw()
526
+
527
+ def set_on_fold_toggle(self, cb: Callable[[int], None]) -> None:
528
+ """Registers the callback invoked when the user clicks a fold icon.
529
+
530
+ Args:
531
+ cb: Called with the 1-based line number of the toggled region.
532
+ """
533
+ self._on_fold_toggle = cb
534
+
535
+ def set_on_breakpoint_toggle(self, cb: Callable[[set[int]], None]) -> None:
536
+ """Registers the callback invoked when a breakpoint is added/removed.
537
+
538
+ Args:
539
+ cb: Called with a copy of the full current breakpoint set
540
+ (1-based line numbers) every time the user clicks the
541
+ gutter to toggle one.
542
+ """
543
+ self._on_breakpoint_toggle = cb
544
+
545
+ def set_lint_lines(self, diags: list[Diag]) -> None:
546
+ """Updates the lint dot map from a list of diagnostics and redraws.
547
+
548
+ Only the highest-severity diagnostic per line is shown. Severity 1 = error,
549
+ 2 = warning, 3 = info, 4 = hint.
550
+
551
+ Args:
552
+ diags: Diagnostic objects from the LSP manager.
553
+ """
554
+ self._lint_lines.clear()
555
+ severity_map: dict[int, int] = {}
556
+ color_table = {
557
+ 1: self._theme.err_fg,
558
+ 2: self._theme.warn_fg,
559
+ 3: self._theme.info_fg,
560
+ 4: self._theme.hint_fg,
561
+ }
562
+ for d in diags:
563
+ color = color_table.get(d.severity)
564
+ if color is None:
565
+ continue
566
+ if d.line not in severity_map or d.severity < severity_map[d.line]:
567
+ severity_map[d.line] = d.severity
568
+ self._lint_lines[d.line] = color
569
+ self._schedule_redraw()
570
+
571
+ def set_kdocs_lines(self, annotations: list[KDocsNotes]) -> None:
572
+ """Updates the KDocs annotation dot map and schedules a redraw.
573
+
574
+ Args:
575
+ annotations: Annotation objects produced by ``KDocsParser``.
576
+ """
577
+ self._kdocs_lines = {a.line: KDocsParser.color(
578
+ a.kind) for a in annotations}
579
+ self._schedule_redraw()
580
+
581
+ def set_on_marked_change(self, cb: Callable[[set[int]], None]) -> None:
582
+ """Registers the callback fired when the set of Alt+clicked marked lines changes.
583
+
584
+ Args:
585
+ cb: Called with the updated set of marked line numbers.
586
+ """
587
+ self._on_marked_change = cb
588
+
589
+ def clear_marked(self) -> None:
590
+ """Clears all marked lines and fires the ``on_marked_change`` callback."""
591
+ self._marked_lines.clear()
592
+ self.redraw()
593
+ if self._on_marked_change:
594
+ self._on_marked_change(set())
595
+
596
+ def get_breakpoints(self) -> set[int]:
597
+ """Returns a copy of the current set of breakpoint line numbers."""
598
+ return set(self._breakpoints)