krnell 3.0.3 → 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/opencode_sync.py +81 -17
- package/package.json +1 -1
- package/painel.py +873 -210
- package/tui_core.py +160 -26
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:
|
|
@@ -142,10 +144,25 @@ class TerminalPosix:
|
|
|
142
144
|
try:
|
|
143
145
|
self._fd = sys.stdin.fileno()
|
|
144
146
|
self._orig = termios.tcgetattr(self._fd)
|
|
145
|
-
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
|
|
147
|
+
# Raw mode na entrada, preservando OPOST (traducao \n -> \r\n) na saida.
|
|
148
|
+
# Sem OPOST, todo '\n' impresso em Linux/Termux vira escadinha horizontal
|
|
149
|
+
# (cada linha comeca onde a anterior terminou) e o zoom/resize corrompe a tela.
|
|
150
|
+
modo = termios.tcgetattr(self._fd)
|
|
151
|
+
modo[0] &= ~(termios.IGNBRK | termios.BRKINT | termios.PARMRK | termios.ISTRIP
|
|
152
|
+
| termios.INLCR | termios.IGNCR | termios.ICRNL | termios.IXON)
|
|
153
|
+
modo[1] |= termios.OPOST
|
|
154
|
+
if hasattr(termios, 'ONLCR'):
|
|
155
|
+
modo[1] |= termios.ONLCR
|
|
156
|
+
modo[2] &= ~(termios.CSIZE | termios.PARENB)
|
|
157
|
+
modo[2] |= termios.CS8
|
|
158
|
+
modo[3] &= ~(termios.ECHO | termios.ECHONL | termios.ICANON | termios.ISIG | termios.IEXTEN)
|
|
159
|
+
modo[6][termios.VMIN] = 1
|
|
160
|
+
modo[6][termios.VTIME] = 0
|
|
161
|
+
termios.tcsetattr(self._fd, termios.TCSAFLUSH, modo)
|
|
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')
|
|
149
166
|
sys.stdout.flush()
|
|
150
167
|
if hasattr(signal, 'SIGWINCH'):
|
|
151
168
|
self._prev_winch = signal.getsignal(signal.SIGWINCH)
|
|
@@ -166,7 +183,7 @@ class TerminalPosix:
|
|
|
166
183
|
|
|
167
184
|
def sair(self) -> None:
|
|
168
185
|
try:
|
|
169
|
-
sys.stdout.write('\x1b[?2004l\x1b[?1006l\x1b[?1000l')
|
|
186
|
+
sys.stdout.write('\x1b[?2004l\x1b[?1006l\x1b[?1002l\x1b[?1000l')
|
|
170
187
|
sys.stdout.flush()
|
|
171
188
|
except Exception:
|
|
172
189
|
pass
|
|
@@ -342,15 +359,54 @@ class TerminalPosix:
|
|
|
342
359
|
if not m:
|
|
343
360
|
return None
|
|
344
361
|
btn, x, y, kind = int(m.group(1)), int(m.group(2)) - 1, int(m.group(3)) - 1, m.group(4)
|
|
345
|
-
|
|
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
|
|
346
367
|
return ('mouse_roda', -1)
|
|
347
|
-
if
|
|
368
|
+
if base_btn == 65:
|
|
369
|
+
self._drag_y = None
|
|
370
|
+
self._drag_moved = False
|
|
348
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
|
|
349
383
|
if kind == 'M' and (btn & 3) == 0 and not (btn & 32):
|
|
350
|
-
|
|
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)
|
|
351
392
|
if btn & 32:
|
|
352
393
|
return ('mouse_move', x, y)
|
|
353
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
|
|
354
410
|
mapa = {
|
|
355
411
|
'A': 'cima', 'B': 'baixo', 'C': 'direita', 'D': 'esquerda',
|
|
356
412
|
'H': 'home', 'F': 'end', 'Z': 'shift_tab',
|
|
@@ -391,8 +447,8 @@ def desenhar_overlay_centrado(
|
|
|
391
447
|
|
|
392
448
|
h_box = len(caixa_linhas)
|
|
393
449
|
w_box = max((vis_len(l) for l in caixa_linhas), default=0)
|
|
394
|
-
top = max(
|
|
395
|
-
left = max(
|
|
450
|
+
top = max(0, (altura_tela - h_box) // 2)
|
|
451
|
+
left = max(0, (largura_tela - w_box) // 2)
|
|
396
452
|
|
|
397
453
|
for offset, linha_box in enumerate(caixa_linhas):
|
|
398
454
|
y = top + offset
|
|
@@ -443,7 +499,7 @@ def construir_dialogo_opencode(
|
|
|
443
499
|
fundo = c.get('fundo', '#1e1e1e')
|
|
444
500
|
texto_acento = c.get('texto_acento', '#0a0a0a')
|
|
445
501
|
|
|
446
|
-
w = max(
|
|
502
|
+
w = max(20, largura_caixa)
|
|
447
503
|
inner = w - 2 # entre ┃ ... ┃
|
|
448
504
|
bg = f' on {fundo}'
|
|
449
505
|
linhas: list[Text] = []
|
|
@@ -465,7 +521,7 @@ def construir_dialogo_opencode(
|
|
|
465
521
|
|
|
466
522
|
# Cabeçalho: título à esquerda + "esc" à direita (assinatura visual do OpenCode)
|
|
467
523
|
esc_tag = 'esc '
|
|
468
|
-
tit_max = max(
|
|
524
|
+
tit_max = max(4, inner - cell_len(esc_tag) - 3)
|
|
469
525
|
tit_vis = truncate_vis(titulo, tit_max)
|
|
470
526
|
gap_hdr = max(1, inner - 2 - cell_len(tit_vis) - cell_len(esc_tag))
|
|
471
527
|
hdr = Text()
|
|
@@ -476,7 +532,7 @@ def construir_dialogo_opencode(
|
|
|
476
532
|
linhas.append(frame_line(hdr))
|
|
477
533
|
|
|
478
534
|
if subtitulo:
|
|
479
|
-
sub_vis = truncate_vis(subtitulo, inner - 4)
|
|
535
|
+
sub_vis = truncate_vis(subtitulo, max(4, inner - 4))
|
|
480
536
|
sub = Text()
|
|
481
537
|
sub.append(' ' + sub_vis, style=f'{fraco}{bg}')
|
|
482
538
|
linhas.append(frame_line(sub, max(0, inner - 2 - cell_len(sub_vis))))
|
|
@@ -485,7 +541,7 @@ def construir_dialogo_opencode(
|
|
|
485
541
|
if mostrar_busca:
|
|
486
542
|
linhas.append(frame_line(Text(' ' * inner, style=bg.strip())))
|
|
487
543
|
busca_vis = ('•' * min(len(busca), 36)) if mascarar_busca else busca
|
|
488
|
-
campo_max = max(
|
|
544
|
+
campo_max = max(4, inner - 6)
|
|
489
545
|
campo_txt = truncate_vis(busca_vis, campo_max) if busca_vis else truncate_vis(placeholder, campo_max)
|
|
490
546
|
row_b = Text()
|
|
491
547
|
row_b.append(' ', style=bg.strip())
|
|
@@ -493,21 +549,99 @@ def construir_dialogo_opencode(
|
|
|
493
549
|
row_b.append(campo_txt, style=f'{texto if busca_vis else fraco}{bg}')
|
|
494
550
|
rest = max(0, inner - 4 - cell_len(campo_txt))
|
|
495
551
|
linhas.append(frame_line(row_b, rest))
|
|
496
|
-
sep = Text(' ' + '─' * max(
|
|
552
|
+
sep = Text(' ' + '─' * max(2, inner - 4) + ' ', style=f'{borda}{bg}')
|
|
497
553
|
linhas.append(frame_line(sep))
|
|
498
554
|
|
|
499
555
|
# Extrai índices selecionáveis e janela visível
|
|
500
556
|
selecionaveis = [i for i, it in enumerate(itens) if it.get('tipo', 'item') == 'item']
|
|
501
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))))
|
|
502
588
|
|
|
503
589
|
if total_sel == 0:
|
|
504
|
-
# Só texto informativo ou lista vazia
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
590
|
+
# Só texto informativo ou lista vazia (respeita `limite` em telas baixas)
|
|
591
|
+
vis_txt = itens[:max(1, limite)] if limite else itens
|
|
592
|
+
for it in vis_txt:
|
|
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))
|
|
508
621
|
t = Text()
|
|
509
|
-
|
|
510
|
-
|
|
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))
|
|
511
645
|
else:
|
|
512
646
|
# Janela baseada nos selecionáveis, mantendo cabeçalho de seção acima do primeiro item dela
|
|
513
647
|
vis_sel_indices = selecionaveis[topo:topo + limite]
|
|
@@ -592,7 +726,7 @@ def construir_dialogo_opencode(
|
|
|
592
726
|
|
|
593
727
|
# Rodapé de atalhos
|
|
594
728
|
linhas.append(frame_line(Text(' ' * inner, style=bg.strip())))
|
|
595
|
-
rod_vis = truncate_vis(rodape, inner - 4)
|
|
729
|
+
rod_vis = truncate_vis(rodape, max(4, inner - 4))
|
|
596
730
|
rt = Text()
|
|
597
731
|
rt.append(' ' + rod_vis, style=f'{fraco}{bg}')
|
|
598
732
|
linhas.append(frame_line(rt, max(0, inner - 2 - cell_len(rod_vis))))
|