krnell 3.0.4 → 3.0.5
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/bin/krnell.mjs +2 -2
- package/bridge.py +1 -1
- package/iniciar.sh +1 -1
- package/kimi.py +18 -0
- package/package.json +1 -1
- package/painel.py +756 -172
- package/tui_core.py +135 -16
package/tui_core.py
CHANGED
|
@@ -113,13 +113,13 @@ def pad_vis(s: str, largura: int) -> str:
|
|
|
113
113
|
return s + (' ' * faltam)
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def barra_progresso(fracao: float | None, largura: int =
|
|
117
|
-
"""Barrinha
|
|
116
|
+
def barra_progresso(fracao: float | None, largura: int = 8) -> str:
|
|
117
|
+
"""Barrinha fina e limpa estilo OpenCode (sem bloco sólido estourando)."""
|
|
118
118
|
if fracao is None:
|
|
119
|
-
return '
|
|
119
|
+
return '─' * largura
|
|
120
120
|
f = max(0.0, min(1.0, float(fracao)))
|
|
121
121
|
cheios = int(round(f * largura))
|
|
122
|
-
return '
|
|
122
|
+
return '━' * cheios + '─' * max(0, largura - cheios)
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
class TerminalPosix:
|
|
@@ -133,6 +133,8 @@ class TerminalPosix:
|
|
|
133
133
|
self._prev_winch = None
|
|
134
134
|
self._in_paste = False
|
|
135
135
|
self._paste_chars: list[str] = []
|
|
136
|
+
self._drag_y: int | None = None
|
|
137
|
+
self._drag_moved = False
|
|
136
138
|
|
|
137
139
|
def entrar(self) -> bool:
|
|
138
140
|
if os.name == 'nt' or termios is None or tty is None:
|
|
@@ -157,9 +159,10 @@ class TerminalPosix:
|
|
|
157
159
|
modo[6][termios.VMIN] = 1
|
|
158
160
|
modo[6][termios.VTIME] = 0
|
|
159
161
|
termios.tcsetattr(self._fd, termios.TCSAFLUSH, modo)
|
|
160
|
-
# Mouse SGR (1000=clique/roda,
|
|
161
|
-
#
|
|
162
|
-
|
|
162
|
+
# Mouse SGR (1000=clique/roda, 1002=arrastar com dedo/botão, 1006=SGR)
|
|
163
|
+
# + bracketed paste (2004). 1002 permite scroll arrastando o dedo no Termux
|
|
164
|
+
# sem inundar com eventos de hover sem toque (1003 fica desligado).
|
|
165
|
+
sys.stdout.write('\x1b[?1000h\x1b[?1002h\x1b[?1006h\x1b[?2004h')
|
|
163
166
|
sys.stdout.flush()
|
|
164
167
|
if hasattr(signal, 'SIGWINCH'):
|
|
165
168
|
self._prev_winch = signal.getsignal(signal.SIGWINCH)
|
|
@@ -180,7 +183,7 @@ class TerminalPosix:
|
|
|
180
183
|
|
|
181
184
|
def sair(self) -> None:
|
|
182
185
|
try:
|
|
183
|
-
sys.stdout.write('\x1b[?2004l\x1b[?1006l\x1b[?1000l')
|
|
186
|
+
sys.stdout.write('\x1b[?2004l\x1b[?1006l\x1b[?1002l\x1b[?1000l')
|
|
184
187
|
sys.stdout.flush()
|
|
185
188
|
except Exception:
|
|
186
189
|
pass
|
|
@@ -356,15 +359,54 @@ class TerminalPosix:
|
|
|
356
359
|
if not m:
|
|
357
360
|
return None
|
|
358
361
|
btn, x, y, kind = int(m.group(1)), int(m.group(2)) - 1, int(m.group(3)) - 1, m.group(4)
|
|
359
|
-
|
|
362
|
+
# Roda do mouse e scroll por swipe no Termux (ignora modificadores Shift/Ctrl/Alt)
|
|
363
|
+
base_btn = btn & ~28
|
|
364
|
+
if base_btn == 64:
|
|
365
|
+
self._drag_y = None
|
|
366
|
+
self._drag_moved = False
|
|
360
367
|
return ('mouse_roda', -1)
|
|
361
|
-
if
|
|
368
|
+
if base_btn == 65:
|
|
369
|
+
self._drag_y = None
|
|
370
|
+
self._drag_moved = False
|
|
362
371
|
return ('mouse_roda', 1)
|
|
372
|
+
# Arrastar verticalmente com o dedo/botão pressionado (modo 1002: bit 32 + botão 0)
|
|
373
|
+
if kind == 'M' and (btn & 32) and (btn & 3) == 0:
|
|
374
|
+
if self._drag_y is not None and y != self._drag_y:
|
|
375
|
+
dy = y - self._drag_y
|
|
376
|
+
self._drag_y = y
|
|
377
|
+
self._drag_moved = True
|
|
378
|
+
# Arrastar dedo para cima (dy < 0) rola lista para baixo (+1), natural mobile
|
|
379
|
+
return ('mouse_roda', 1 if dy < 0 else -1)
|
|
380
|
+
self._drag_y = y
|
|
381
|
+
return None
|
|
382
|
+
# Toque/clique pressionado: registra início; se soltar sem arrastar dispara clique
|
|
363
383
|
if kind == 'M' and (btn & 3) == 0 and not (btn & 32):
|
|
364
|
-
|
|
384
|
+
self._drag_y = y
|
|
385
|
+
self._drag_moved = False
|
|
386
|
+
return None
|
|
387
|
+
if kind == 'm' and (btn & 3) == 0:
|
|
388
|
+
arrastou = self._drag_moved
|
|
389
|
+
self._drag_y = None
|
|
390
|
+
self._drag_moved = False
|
|
391
|
+
return None if arrastou else ('mouse_clique', x, y)
|
|
365
392
|
if btn & 32:
|
|
366
393
|
return ('mouse_move', x, y)
|
|
367
394
|
return None
|
|
395
|
+
# Mouse X10 legado (CSI M cb cx cy): fallback de alguns terminais Android/Termux
|
|
396
|
+
if seq == 'M':
|
|
397
|
+
while len(self._buf) < 3 and self._ler_disponivel(0.02):
|
|
398
|
+
pass
|
|
399
|
+
if len(self._buf) >= 3:
|
|
400
|
+
cb, cx, cy = self._buf[0] - 32, self._buf[1] - 33, self._buf[2] - 33
|
|
401
|
+
del self._buf[:3]
|
|
402
|
+
base_cb = cb & ~28
|
|
403
|
+
if base_cb == 64:
|
|
404
|
+
return ('mouse_roda', -1)
|
|
405
|
+
if base_cb == 65:
|
|
406
|
+
return ('mouse_roda', 1)
|
|
407
|
+
if (cb & 3) == 0 and not (cb & 32):
|
|
408
|
+
return ('mouse_clique', max(0, cx), max(0, cy))
|
|
409
|
+
return None
|
|
368
410
|
mapa = {
|
|
369
411
|
'A': 'cima', 'B': 'baixo', 'C': 'direita', 'D': 'esquerda',
|
|
370
412
|
'H': 'home', 'F': 'end', 'Z': 'shift_tab',
|
|
@@ -513,16 +555,93 @@ def construir_dialogo_opencode(
|
|
|
513
555
|
# Extrai índices selecionáveis e janela visível
|
|
514
556
|
selecionaveis = [i for i, it in enumerate(itens) if it.get('tipo', 'item') == 'item']
|
|
515
557
|
total_sel = len(selecionaveis)
|
|
558
|
+
tem_textos = any(it.get('tipo') == 'texto' for it in itens)
|
|
559
|
+
|
|
560
|
+
def _add_texto_item(it: dict) -> None:
|
|
561
|
+
rich_obj = it.get('rich')
|
|
562
|
+
if isinstance(rich_obj, Text):
|
|
563
|
+
t = Text()
|
|
564
|
+
t.append(' ', style=bg.strip())
|
|
565
|
+
# Preserva cores de cada span sobre o fundo do diálogo, truncando para caber
|
|
566
|
+
usado = 0
|
|
567
|
+
max_w = max(4, inner - 4)
|
|
568
|
+
for span_txt in rich_obj.split('\n')[:1]:
|
|
569
|
+
# Copia texto com corte por cell_len
|
|
570
|
+
if cell_len(span_txt.plain) <= max_w:
|
|
571
|
+
for seg in span_txt.spans:
|
|
572
|
+
pass
|
|
573
|
+
copia = span_txt.copy()
|
|
574
|
+
copia.stylize(bg.strip())
|
|
575
|
+
t.append_text(copia)
|
|
576
|
+
usado = cell_len(span_txt.plain)
|
|
577
|
+
else:
|
|
578
|
+
cortado = truncate_vis(span_txt.plain, max_w)
|
|
579
|
+
t.append(cortado, style=f'{it.get("cor") or texto}{bg}')
|
|
580
|
+
usado = cell_len(cortado)
|
|
581
|
+
linhas.append(frame_line(t, max(0, inner - 2 - usado)))
|
|
582
|
+
return
|
|
583
|
+
txt = truncate_vis(str(it.get('rotulo') or ''), max(4, inner - 4))
|
|
584
|
+
cor = it.get('cor') or fraco
|
|
585
|
+
t = Text()
|
|
586
|
+
t.append(' ' + txt, style=f'{cor}{bg}')
|
|
587
|
+
linhas.append(frame_line(t, max(0, inner - 2 - cell_len(txt))))
|
|
516
588
|
|
|
517
589
|
if total_sel == 0:
|
|
518
590
|
# Só texto informativo ou lista vazia (respeita `limite` em telas baixas)
|
|
519
591
|
vis_txt = itens[:max(1, limite)] if limite else itens
|
|
520
592
|
for it in vis_txt:
|
|
521
|
-
|
|
522
|
-
|
|
593
|
+
_add_texto_item(it)
|
|
594
|
+
elif tem_textos:
|
|
595
|
+
# Diálogo misto (ex.: tela de login com instruções + botões clicáveis [Copiar link] / [Abrir navegador])
|
|
596
|
+
pos_sel = {idx_raw: pos for pos, idx_raw in enumerate(selecionaveis)}
|
|
597
|
+
vis_misto = itens[:max(1, limite)] if limite else itens
|
|
598
|
+
for idx_raw, it in enumerate(vis_misto):
|
|
599
|
+
tipo_it = it.get('tipo', 'item')
|
|
600
|
+
if tipo_it == 'texto':
|
|
601
|
+
_add_texto_item(it)
|
|
602
|
+
continue
|
|
603
|
+
if tipo_it == 'secao':
|
|
604
|
+
sec_vis = truncate_vis(str(it.get('rotulo') or '').upper(), max(4, inner - 4))
|
|
605
|
+
st = Text()
|
|
606
|
+
st.append(' ' + sec_vis, style=f'bold {acento2}{bg}')
|
|
607
|
+
linhas.append(frame_line(st, max(0, inner - 2 - cell_len(sec_vis))))
|
|
608
|
+
continue
|
|
609
|
+
pos = pos_sel[idx_raw]
|
|
610
|
+
focado = (pos == foco)
|
|
611
|
+
badge = str(it.get('badge') or ('●' if it.get('ativo') else ' '))
|
|
612
|
+
badge_cor = it.get('badge_cor') or (ok if it.get('ativo') else acento2)
|
|
613
|
+
rotulo = str(it.get('rotulo') or '')
|
|
614
|
+
detalhe = str(it.get('detalhe') or '')
|
|
615
|
+
prefix_w = 2 + cell_len(badge) + 1
|
|
616
|
+
max_det = max(0, (inner - prefix_w - 6) // 2) if detalhe else 0
|
|
617
|
+
det_vis = truncate_vis(detalhe, max_det) if (detalhe and max_det >= 6) else ''
|
|
618
|
+
max_rot = max(4, inner - prefix_w - 2 - (cell_len(det_vis) + 2 if det_vis else 0))
|
|
619
|
+
rot_vis = truncate_vis(rotulo, max_rot)
|
|
620
|
+
gap = max(1, inner - prefix_w - cell_len(rot_vis) - cell_len(det_vis) - 2) if det_vis else max(0, inner - prefix_w - cell_len(rot_vis))
|
|
523
621
|
t = Text()
|
|
524
|
-
|
|
525
|
-
|
|
622
|
+
if focado:
|
|
623
|
+
hi = f'bold {texto_acento} on {acento}'
|
|
624
|
+
hi_dim = f'{texto_acento} on {acento}'
|
|
625
|
+
t.append(f' {badge} ', style=hi)
|
|
626
|
+
t.append(rot_vis, style=hi)
|
|
627
|
+
if det_vis:
|
|
628
|
+
t.append(' ' * gap, style=hi)
|
|
629
|
+
t.append(det_vis, style=hi_dim)
|
|
630
|
+
t.append(' ', style=hi)
|
|
631
|
+
else:
|
|
632
|
+
t.append(' ' * gap, style=hi)
|
|
633
|
+
else:
|
|
634
|
+
t.append(' ', style=bg.strip())
|
|
635
|
+
t.append(badge + ' ', style=f'{badge_cor}{bg}')
|
|
636
|
+
t.append(rot_vis, style=f'bold {acento if it.get("ativo") else texto}{bg}')
|
|
637
|
+
if det_vis:
|
|
638
|
+
t.append(' ' * gap, style=bg.strip())
|
|
639
|
+
t.append(det_vis, style=f'{fraco}{bg}')
|
|
640
|
+
t.append(' ', style=bg.strip())
|
|
641
|
+
else:
|
|
642
|
+
t.append(' ' * gap, style=bg.strip())
|
|
643
|
+
mapa_clique[len(linhas)] = pos
|
|
644
|
+
linhas.append(frame_line(t))
|
|
526
645
|
else:
|
|
527
646
|
# Janela baseada nos selecionáveis, mantendo cabeçalho de seção acima do primeiro item dela
|
|
528
647
|
vis_sel_indices = selecionaveis[topo:topo + limite]
|
|
@@ -607,7 +726,7 @@ def construir_dialogo_opencode(
|
|
|
607
726
|
|
|
608
727
|
# Rodapé de atalhos
|
|
609
728
|
linhas.append(frame_line(Text(' ' * inner, style=bg.strip())))
|
|
610
|
-
rod_vis = truncate_vis(rodape, inner - 4)
|
|
729
|
+
rod_vis = truncate_vis(rodape, max(4, inner - 4))
|
|
611
730
|
rt = Text()
|
|
612
731
|
rt.append(' ' + rod_vis, style=f'{fraco}{bg}')
|
|
613
732
|
linhas.append(frame_line(rt, max(0, inner - 2 - cell_len(rod_vis))))
|