@leosdc/exploreio 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tui/app.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * HTML Reader/Source, Syntax Highlighting e 3 temas oficiais.
6
6
  */
7
7
  import path from 'node:path';
8
+ import { formatKeyEvent, formatKeyForDisplay, loadKeybindsRegistry, saveKeybindsConfig, } from '../config/keybinds.js';
8
9
  import { VimEngine } from '../editor/vimEngine.js';
9
10
  import { buildEditorFrame } from '../editor/vimView.js';
10
11
  import { getGitSummaryBadge, gitCheckoutBranch, gitCommit, gitCreateBranch, gitDiscardFile, gitFetch, gitPull, gitPush, gitStageAll, gitStageFile, gitStashPop, gitStashPush, gitUnstageAll, gitUnstageFile, loadCommitDetails, loadFileDiff, loadGitHubData, loadGitPanelSnapshot, } from '../git/gitService.js';
@@ -17,6 +18,7 @@ import { BOLD, DIM, ITALIC, RESET, fitAnsi, highlightSearch, stripUnsafeAnsi, tr
17
18
  import { copyTextToClipboard } from './clipboard.js';
18
19
  import { openInFullscreenShell } from './fullscreenLauncher.js';
19
20
  import { parseInputChunk } from './input.js';
21
+ import { KEYBINDS_TABS, buildKeybindsPanelFrame, getFilteredKeybindDefinitions, } from './keybindsView.js';
20
22
  import { ScreenBuffer } from './screen.js';
21
23
  function getFileBadge(entry, theme) {
22
24
  if (entry.isDirectory)
@@ -100,6 +102,16 @@ export class ExploreioApp {
100
102
  gitQuickPaletteIndex = 0;
101
103
  gitBusyMessage = '';
102
104
  gitPendingConfirm = null;
105
+ // Custom Keybinds & Painel Interativo (SPEC-006)
106
+ keybinds;
107
+ configPath;
108
+ keybindsTab = 'all';
109
+ keybindsSelectedIndex = 0;
110
+ keybindsScroll = 0;
111
+ keybindsFilterQuery = '';
112
+ keybindsCaptureMode = null;
113
+ keybindsDirty = false;
114
+ keybindsReturnView = 'browser';
103
115
  // Prompt modal inline (barra inferior)
104
116
  promptKind = null;
105
117
  promptInput = '';
@@ -111,6 +123,12 @@ export class ExploreioApp {
111
123
  this.singleFile = Boolean(options.singleFile);
112
124
  this.themeName = options.themeName ?? 'midnight';
113
125
  this.showHidden = Boolean(options.showHidden);
126
+ const loadedBinds = loadKeybindsRegistry(options.configPath);
127
+ this.keybinds = loadedBinds.registry;
128
+ this.configPath = loadedBinds.configPath;
129
+ if (loadedBinds.warning) {
130
+ this.toastMessage = loadedBinds.warning;
131
+ }
114
132
  if (options.initialFile) {
115
133
  this.currentDir = path.dirname(path.resolve(options.initialFile));
116
134
  }
@@ -182,7 +200,13 @@ export class ExploreioApp {
182
200
  process.exit(0);
183
201
  }
184
202
  if (this.showHelp) {
185
- if (ev.name === 'escape' || ev.char === '?' || ev.char === 'q') {
203
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
204
+ this.showHelp = false;
205
+ const ret = this.view === 'reader' || this.view === 'git' ? this.view : 'browser';
206
+ this.openKeybindsPanel(ret);
207
+ continue;
208
+ }
209
+ if (ev.name === 'escape' || this.keybinds.matches('global.help', ev) || this.keybinds.matches('global.quit', ev)) {
186
210
  this.showHelp = false;
187
211
  this.draw();
188
212
  }
@@ -195,6 +219,9 @@ export class ExploreioApp {
195
219
  if (this.view === 'editor') {
196
220
  await this.handleEditorKey(ev);
197
221
  }
222
+ else if (this.view === 'keybinds') {
223
+ await this.handleKeybindsKey(ev);
224
+ }
198
225
  else if (this.view === 'git') {
199
226
  await this.handleGitKey(ev);
200
227
  }
@@ -212,6 +239,11 @@ export class ExploreioApp {
212
239
  this.filterQuery = '';
213
240
  await this.reloadDirectory();
214
241
  }
242
+ else if (this.promptKind === 'keybinds-filter') {
243
+ this.keybindsFilterQuery = '';
244
+ this.keybindsSelectedIndex = 0;
245
+ this.keybindsScroll = 0;
246
+ }
215
247
  this.promptKind = null;
216
248
  this.promptInput = '';
217
249
  this.draw();
@@ -293,6 +325,21 @@ export class ExploreioApp {
293
325
  this.toastMessage = 'Operação Git cancelada.';
294
326
  }
295
327
  }
328
+ else if (kind === 'keybinds-filter') {
329
+ this.keybindsFilterQuery = value;
330
+ this.keybindsSelectedIndex = 0;
331
+ this.keybindsScroll = 0;
332
+ }
333
+ else if (kind === 'keybinds-reset-confirm') {
334
+ if (value.trim().toLowerCase() === 'y' || value.trim().toLowerCase() === 's') {
335
+ this.keybinds.resetAll();
336
+ this.keybindsDirty = true;
337
+ this.toastMessage = 'Todos os keybinds restaurados para o padrão (pressione s para salvar).';
338
+ }
339
+ else {
340
+ this.toastMessage = 'Reset global cancelado.';
341
+ }
342
+ }
296
343
  this.draw();
297
344
  return;
298
345
  }
@@ -302,6 +349,11 @@ export class ExploreioApp {
302
349
  this.filterQuery = this.promptInput;
303
350
  await this.reloadDirectory();
304
351
  }
352
+ else if (this.promptKind === 'keybinds-filter') {
353
+ this.keybindsFilterQuery = this.promptInput;
354
+ this.keybindsSelectedIndex = 0;
355
+ this.keybindsScroll = 0;
356
+ }
305
357
  this.draw();
306
358
  return;
307
359
  }
@@ -311,118 +363,133 @@ export class ExploreioApp {
311
363
  this.filterQuery = this.promptInput;
312
364
  await this.reloadDirectory();
313
365
  }
366
+ else if (this.promptKind === 'keybinds-filter') {
367
+ this.keybindsFilterQuery = this.promptInput;
368
+ this.keybindsSelectedIndex = 0;
369
+ this.keybindsScroll = 0;
370
+ }
314
371
  this.draw();
315
372
  }
316
373
  }
317
374
  async handleBrowserKey(ev) {
318
375
  this.toastMessage = '';
319
376
  const maxIdx = Math.max(0, this.currentEntries.length - 1);
320
- if (ev.char === 'q') {
377
+ if (this.keybinds.matches('global.quit', ev)) {
321
378
  this.shutdown();
322
379
  process.exit(0);
323
380
  }
324
- if (ev.char === '?') {
381
+ if (this.keybinds.matches('global.help', ev)) {
325
382
  this.showHelp = true;
326
383
  this.draw();
327
384
  return;
328
385
  }
329
- if (ev.char === 't') {
386
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
387
+ this.openKeybindsPanel('browser');
388
+ return;
389
+ }
390
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
330
391
  this.themeName = nextTheme(this.themeName);
331
392
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
332
393
  await this.refreshSelectedPreview();
333
394
  this.draw();
334
395
  return;
335
396
  }
336
- if (ev.char === '.') {
397
+ if (this.keybinds.matches('browser.toggleHidden', ev)) {
337
398
  this.showHidden = !this.showHidden;
338
399
  this.toastMessage = this.showHidden ? 'Exibindo arquivos ocultos' : 'Ocultando arquivos iniciados por "."';
339
400
  await this.reloadDirectory();
340
401
  this.draw();
341
402
  return;
342
403
  }
343
- if (ev.char === '/' || ev.char === 'f') {
404
+ if (this.keybinds.matches('browser.filter', ev)) {
344
405
  this.promptKind = 'filter';
345
406
  this.promptInput = this.filterQuery;
346
407
  this.draw();
347
408
  return;
348
409
  }
349
- if (ev.char === 'a') {
410
+ if (this.keybinds.matches('browser.createEntry', ev)) {
350
411
  this.promptKind = 'create';
351
412
  this.promptInput = '';
352
413
  this.draw();
353
414
  return;
354
415
  }
355
- if (ev.char === 'r' && this.currentEntries[this.selectedIndex]) {
416
+ if (this.keybinds.matches('browser.renameEntry', ev) && this.currentEntries[this.selectedIndex]) {
356
417
  this.promptKind = 'rename';
357
418
  this.promptInput = this.currentEntries[this.selectedIndex]?.name ?? '';
358
419
  this.draw();
359
420
  return;
360
421
  }
361
- if (ev.char === 'd' && this.currentEntries[this.selectedIndex]) {
422
+ if (this.keybinds.matches('browser.deleteEntry', ev) && this.currentEntries[this.selectedIndex]) {
362
423
  this.promptKind = 'delete';
363
424
  this.promptInput = '';
364
425
  this.draw();
365
426
  return;
366
427
  }
367
- if (ev.char === 'y') {
428
+ if (this.keybinds.matches('browser.copyPath', ev)) {
368
429
  await this.copySelectedPath();
369
430
  return;
370
431
  }
371
- if (ev.char === 'o' || ev.char === 'F') {
432
+ if (this.keybinds.matches('browser.openFullscreen', ev)) {
372
433
  const entry = this.currentEntries[this.selectedIndex];
373
434
  if (entry && !entry.isDirectory) {
374
435
  await this.openInFullscreenTerminal(entry.fullPath);
375
436
  }
376
437
  else {
377
- this.toastMessage = 'Selecione um arquivo para abrir em terminal tela cheia (o).';
438
+ this.toastMessage = `Selecione um arquivo para abrir em terminal tela cheia (${this.keybinds.formatActionKeys('browser.openFullscreen')}).`;
378
439
  this.draw();
379
440
  }
380
441
  return;
381
442
  }
382
- if (ev.name === 'tab' || (ev.ctrl && ev.name === 'g')) {
443
+ if (this.keybinds.matches('browser.openGitPanel', ev)) {
383
444
  await this.openGitPanel();
384
445
  return;
385
446
  }
386
- if (ev.char === 'e') {
447
+ if (this.keybinds.matches('browser.refresh', ev)) {
448
+ await this.reloadDirectory();
449
+ this.toastMessage = 'Diretório recarregado.';
450
+ this.draw();
451
+ return;
452
+ }
453
+ if (this.keybinds.matches('browser.openEditor', ev)) {
387
454
  const entry = this.currentEntries[this.selectedIndex];
388
455
  if (entry && !entry.isDirectory) {
389
456
  await this.openFileInEditor(entry.fullPath, 'browser');
390
457
  }
391
458
  else {
392
- this.toastMessage = 'Selecione um arquivo de texto para abrir no editor Vim (e).';
459
+ this.toastMessage = `Selecione um arquivo de texto para abrir no editor Vim (${this.keybinds.formatActionKeys('browser.openEditor')}).`;
393
460
  this.draw();
394
461
  }
395
462
  return;
396
463
  }
397
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
464
+ if (this.keybinds.matches('browser.moveUp', ev) || ev.name === 'wheel_up') {
398
465
  if (this.selectedIndex > 0) {
399
466
  this.selectedIndex--;
400
467
  await this.refreshSelectedPreview();
401
468
  }
402
469
  }
403
- else if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
470
+ else if (this.keybinds.matches('browser.moveDown', ev) || ev.name === 'wheel_down') {
404
471
  if (this.selectedIndex < maxIdx) {
405
472
  this.selectedIndex++;
406
473
  await this.refreshSelectedPreview();
407
474
  }
408
475
  }
409
- else if (ev.name === 'pageup') {
476
+ else if (this.keybinds.matches('browser.pageUp', ev)) {
410
477
  this.selectedIndex = Math.max(0, this.selectedIndex - 10);
411
478
  await this.refreshSelectedPreview();
412
479
  }
413
- else if (ev.name === 'pagedown') {
480
+ else if (this.keybinds.matches('browser.pageDown', ev)) {
414
481
  this.selectedIndex = Math.min(maxIdx, this.selectedIndex + 10);
415
482
  await this.refreshSelectedPreview();
416
483
  }
417
- else if (ev.name === 'home' || ev.char === 'g') {
484
+ else if (this.keybinds.matches('browser.goTop', ev)) {
418
485
  this.selectedIndex = 0;
419
486
  await this.refreshSelectedPreview();
420
487
  }
421
- else if (ev.name === 'end' || ev.char === 'G') {
488
+ else if (this.keybinds.matches('browser.goBottom', ev)) {
422
489
  this.selectedIndex = maxIdx;
423
490
  await this.refreshSelectedPreview();
424
491
  }
425
- else if (ev.name === 'left' || ev.char === 'h' || ev.name === 'backspace') {
492
+ else if (this.keybinds.matches('browser.parentDir', ev)) {
426
493
  const parent = path.dirname(this.currentDir);
427
494
  if (parent !== this.currentDir) {
428
495
  const previousName = path.basename(this.currentDir);
@@ -431,7 +498,7 @@ export class ExploreioApp {
431
498
  await this.reloadDirectory(previousName);
432
499
  }
433
500
  }
434
- else if (ev.name === 'enter' || ev.name === 'right' || ev.char === 'l') {
501
+ else if (this.keybinds.matches('browser.open', ev)) {
435
502
  const entry = this.currentEntries[this.selectedIndex];
436
503
  if (!entry)
437
504
  return;
@@ -454,7 +521,7 @@ export class ExploreioApp {
454
521
  const bodyHeight = Math.max(4, height - 3);
455
522
  const totalLines = this.activeDoc?.lines.length ?? 0;
456
523
  const isJsonTree = this.activeDoc?.kind === 'json' && this.activeDoc.activeMode === 'tree';
457
- if (ev.name === 'escape' || ev.char === 'q' || ev.name === 'backspace') {
524
+ if (this.keybinds.matches('reader.back', ev)) {
458
525
  if (this.singleFile) {
459
526
  this.shutdown();
460
527
  process.exit(0);
@@ -466,35 +533,41 @@ export class ExploreioApp {
466
533
  this.draw();
467
534
  return;
468
535
  }
469
- if (ev.char === '?') {
536
+ if (this.keybinds.matches('global.help', ev)) {
470
537
  this.showHelp = true;
471
538
  this.draw();
472
539
  return;
473
540
  }
474
- if (ev.char === 't') {
541
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
542
+ this.openKeybindsPanel('reader');
543
+ return;
544
+ }
545
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
475
546
  this.themeName = nextTheme(this.themeName);
476
547
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
477
548
  this.rerenderReaderDoc();
478
549
  this.draw();
479
550
  return;
480
551
  }
481
- if (ev.char === 'y') {
552
+ if (this.keybinds.matches('reader.copyPath', ev)) {
482
553
  await this.copySelectedPath();
483
554
  return;
484
555
  }
485
- if ((ev.char === 'o' || ev.char === 'F') && this.activeFilePreview) {
556
+ if (this.keybinds.matches('reader.openFullscreen', ev) && this.activeFilePreview) {
486
557
  await this.openInFullscreenTerminal(this.activeFilePreview.filePath, this.activeDoc?.activeMode);
487
558
  return;
488
559
  }
489
- if (ev.ctrl && ev.name === 'g') {
560
+ if (this.keybinds.matches('reader.openGitPanel', ev)) {
490
561
  await this.openGitPanel();
491
562
  return;
492
563
  }
493
- if ((ev.char === 'E' || (ev.char === 'e' && !isJsonTree)) && this.activeFilePreview) {
564
+ if (this.keybinds.matches('reader.openEditor', ev) &&
565
+ !(isJsonTree && this.keybinds.matches('reader.jsonExpandAll', ev)) &&
566
+ this.activeFilePreview) {
494
567
  await this.openFileInEditor(this.activeFilePreview.filePath, 'reader');
495
568
  return;
496
569
  }
497
- if (ev.name === 'tab' && this.activeDoc && this.activeDoc.modes.length > 1) {
570
+ if (this.keybinds.matches('reader.toggleMode', ev) && this.activeDoc && this.activeDoc.modes.length > 1) {
498
571
  const idx = this.activeDoc.modes.indexOf(this.activeDoc.activeMode);
499
572
  this.preferredMode = this.activeDoc.modes[(idx + 1) % this.activeDoc.modes.length];
500
573
  this.readerScroll = 0;
@@ -504,19 +577,19 @@ export class ExploreioApp {
504
577
  this.draw();
505
578
  return;
506
579
  }
507
- if (ev.char === '/') {
580
+ if (this.keybinds.matches('reader.search', ev)) {
508
581
  this.promptKind = 'search';
509
582
  this.promptInput = this.readerSearchQuery;
510
583
  this.draw();
511
584
  return;
512
585
  }
513
- if (ev.char === 'n' && this.readerSearchMatches.length > 0) {
586
+ if (this.keybinds.matches('reader.searchNext', ev) && this.readerSearchMatches.length > 0) {
514
587
  this.readerSearchCursor = (this.readerSearchCursor + 1) % this.readerSearchMatches.length;
515
588
  this.jumpToMatch(this.readerSearchCursor);
516
589
  this.draw();
517
590
  return;
518
591
  }
519
- if (ev.char === 'N' && this.readerSearchMatches.length > 0) {
592
+ if (this.keybinds.matches('reader.searchPrev', ev) && this.readerSearchMatches.length > 0) {
520
593
  this.readerSearchCursor =
521
594
  (this.readerSearchCursor - 1 + this.readerSearchMatches.length) % this.readerSearchMatches.length;
522
595
  this.jumpToMatch(this.readerSearchCursor);
@@ -526,7 +599,7 @@ export class ExploreioApp {
526
599
  // Interações exclusivas da Árvore JSON (expandir/recolher)
527
600
  if (isJsonTree && this.activeDoc) {
528
601
  const row = this.activeDoc.jsonTreeRows[this.readerCursor];
529
- if (ev.name === 'enter' || ev.name === 'space') {
602
+ if (this.keybinds.matches('reader.jsonToggleNode', ev)) {
530
603
  if (row?.collapsible) {
531
604
  if (this.collapsedJsonPaths.has(row.path))
532
605
  this.collapsedJsonPaths.delete(row.path);
@@ -537,7 +610,7 @@ export class ExploreioApp {
537
610
  this.draw();
538
611
  return;
539
612
  }
540
- if (ev.name === 'left' || ev.char === 'h') {
613
+ if (this.keybinds.matches('reader.jsonCollapseNode', ev)) {
541
614
  if (row?.collapsible && !row.collapsed) {
542
615
  this.collapsedJsonPaths.add(row.path);
543
616
  this.rerenderReaderDoc();
@@ -545,7 +618,7 @@ export class ExploreioApp {
545
618
  this.draw();
546
619
  return;
547
620
  }
548
- if (ev.name === 'right' || ev.char === 'l') {
621
+ if (this.keybinds.matches('reader.jsonExpandNode', ev)) {
549
622
  if (row?.collapsible && row.collapsed) {
550
623
  this.collapsedJsonPaths.delete(row.path);
551
624
  this.rerenderReaderDoc();
@@ -553,14 +626,14 @@ export class ExploreioApp {
553
626
  this.draw();
554
627
  return;
555
628
  }
556
- if (ev.char === 'e') {
629
+ if (this.keybinds.matches('reader.jsonExpandAll', ev)) {
557
630
  this.collapsedJsonPaths.clear();
558
631
  this.rerenderReaderDoc();
559
632
  this.toastMessage = 'Todos os nós JSON expandidos';
560
633
  this.draw();
561
634
  return;
562
635
  }
563
- if (ev.char === 'c' && this.activeFilePreview) {
636
+ if (this.keybinds.matches('reader.jsonCollapseAll', ev) && this.activeFilePreview) {
564
637
  try {
565
638
  const parsed = JSON.parse(this.activeFilePreview.text);
566
639
  const all = collectAllCollapsiblePaths(parsed).filter((p) => p !== '$');
@@ -579,7 +652,7 @@ export class ExploreioApp {
579
652
  }
580
653
  // Scroll & navegação vertical no leitor
581
654
  const maxScroll = Math.max(0, totalLines - bodyHeight);
582
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
655
+ if (this.keybinds.matches('reader.moveUp', ev) || ev.name === 'wheel_up') {
583
656
  if (isJsonTree) {
584
657
  this.readerCursor = Math.max(0, this.readerCursor - 1);
585
658
  if (this.readerCursor < this.readerScroll)
@@ -589,7 +662,7 @@ export class ExploreioApp {
589
662
  this.readerScroll = Math.max(0, this.readerScroll - (ev.name === 'wheel_up' ? 3 : 1));
590
663
  }
591
664
  }
592
- else if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
665
+ else if (this.keybinds.matches('reader.moveDown', ev) || ev.name === 'wheel_down') {
593
666
  if (isJsonTree) {
594
667
  this.readerCursor = Math.min(Math.max(0, totalLines - 1), this.readerCursor + 1);
595
668
  if (this.readerCursor >= this.readerScroll + bodyHeight) {
@@ -600,21 +673,21 @@ export class ExploreioApp {
600
673
  this.readerScroll = Math.min(maxScroll, this.readerScroll + (ev.name === 'wheel_down' ? 3 : 1));
601
674
  }
602
675
  }
603
- else if (ev.name === 'pageup' || ev.char === 'b') {
676
+ else if (this.keybinds.matches('reader.pageUp', ev)) {
604
677
  const step = Math.max(4, bodyHeight - 2);
605
678
  this.readerScroll = Math.max(0, this.readerScroll - step);
606
679
  this.readerCursor = Math.max(0, this.readerCursor - step);
607
680
  }
608
- else if (ev.name === 'pagedown' || ev.name === 'space') {
681
+ else if (this.keybinds.matches('reader.pageDown', ev)) {
609
682
  const step = Math.max(4, bodyHeight - 2);
610
683
  this.readerScroll = Math.min(maxScroll, this.readerScroll + step);
611
684
  this.readerCursor = Math.min(Math.max(0, totalLines - 1), this.readerCursor + step);
612
685
  }
613
- else if (ev.name === 'home' || ev.char === 'g') {
686
+ else if (this.keybinds.matches('reader.goTop', ev)) {
614
687
  this.readerScroll = 0;
615
688
  this.readerCursor = 0;
616
689
  }
617
- else if (ev.name === 'end' || ev.char === 'G') {
690
+ else if (this.keybinds.matches('reader.goBottom', ev)) {
618
691
  this.readerScroll = maxScroll;
619
692
  this.readerCursor = Math.max(0, totalLines - 1);
620
693
  }
@@ -839,24 +912,42 @@ export class ExploreioApp {
839
912
  statusMessage: this.editorStatusMessage,
840
913
  statusIsError: this.editorStatusIsError,
841
914
  })
842
- : this.view === 'git' && this.gitSnapshot
843
- ? buildGitPanelFrame({
844
- snapshot: this.gitSnapshot,
845
- github: this.gitHubData,
846
- activeTab: this.gitTab,
847
- selectedIndex: this.gitSelectedIndex,
848
- listScroll: this.gitListScroll,
849
- detailTitle: this.gitDetailTitle,
850
- detailLines: this.gitDetailLines,
851
- detailScroll: this.gitDetailScroll,
852
- showQuickPalette: this.gitShowQuickPalette,
853
- quickPaletteIndex: this.gitQuickPaletteIndex,
854
- busyMessage: this.gitBusyMessage,
915
+ : this.view === 'keybinds'
916
+ ? buildKeybindsPanelFrame({
917
+ width,
918
+ height,
919
+ theme,
920
+ registry: this.keybinds,
921
+ configPath: this.configPath,
855
922
  footerLine: this.buildFooterBar(width, theme),
856
- }, width, height, theme)
857
- : this.view === 'reader'
858
- ? this.buildReaderFrame(width, height, theme)
859
- : this.buildBrowserFrame(width, height, theme);
923
+ state: {
924
+ activeTab: this.keybindsTab,
925
+ selectedIndex: this.keybindsSelectedIndex,
926
+ scrollOffset: this.keybindsScroll,
927
+ filterQuery: this.keybindsFilterQuery,
928
+ captureMode: this.keybindsCaptureMode,
929
+ dirty: this.keybindsDirty,
930
+ statusMessage: this.toastMessage,
931
+ },
932
+ })
933
+ : this.view === 'git' && this.gitSnapshot
934
+ ? buildGitPanelFrame({
935
+ snapshot: this.gitSnapshot,
936
+ github: this.gitHubData,
937
+ activeTab: this.gitTab,
938
+ selectedIndex: this.gitSelectedIndex,
939
+ listScroll: this.gitListScroll,
940
+ detailTitle: this.gitDetailTitle,
941
+ detailLines: this.gitDetailLines,
942
+ detailScroll: this.gitDetailScroll,
943
+ showQuickPalette: this.gitShowQuickPalette,
944
+ quickPaletteIndex: this.gitQuickPaletteIndex,
945
+ busyMessage: this.gitBusyMessage,
946
+ footerLine: this.buildFooterBar(width, theme),
947
+ }, width, height, theme)
948
+ : this.view === 'reader'
949
+ ? this.buildReaderFrame(width, height, theme)
950
+ : this.buildBrowserFrame(width, height, theme);
860
951
  if (this.showHelp) {
861
952
  this.overlayHelpModal(lines, width, height, theme);
862
953
  }
@@ -986,13 +1077,23 @@ export class ExploreioApp {
986
1077
  'git-commit': 'git commit -m : ',
987
1078
  'git-branch-create': 'Nova branch (git checkout -b): ',
988
1079
  'git-confirm': `${this.gitPendingConfirm?.label ?? 'Confirmar operação Git'}? (y/N): `,
1080
+ 'keybinds-filter': 'Filtrar keybinds: ',
1081
+ 'keybinds-reset-confirm': 'Restaurar TODOS os keybinds para o padrão? (y/N): ',
989
1082
  };
990
1083
  const text = ` ${labels[this.promptKind]}${this.promptInput}█`;
991
1084
  return `${bg(theme.selectionBg)}${fg(theme.selectionFg)}${BOLD}${fitAnsi(text, width)}${RESET}`;
992
1085
  }
1086
+ if (this.view === 'keybinds' && this.keybindsCaptureMode) {
1087
+ const modeText = this.keybindsCaptureMode === 'replace' ? 'SUBSTITUIR tecla principal' : 'ADICIONAR tecla alternativa';
1088
+ return `${bg(theme.selectionBg)}${fg(theme.selectionFg)}${BOLD}${fitAnsi(` ◉ Pressione a nova tecla para ${modeText} (Esc cancela)`, width)}${RESET}`;
1089
+ }
993
1090
  if (this.toastMessage) {
994
1091
  return `${bg(theme.statusBg)}${fg(theme.warning)}${BOLD}${fitAnsi(` ◆ ${this.toastMessage}`, width)}${RESET}`;
995
1092
  }
1093
+ if (this.view === 'keybinds') {
1094
+ const hint = ' Esc/q Voltar · ↑↓ Selecionar · Enter Capturar · +/a Add tecla · d/Bksp Remover · r Reset · R Reset Tudo · s Salvar · / Filtrar · 1-5/Tab Abas';
1095
+ return `${bg(theme.statusBg)}${fg(theme.statusFg)}${fitAnsi(hint, width)}${RESET}`;
1096
+ }
996
1097
  if (this.view === 'reader') {
997
1098
  const isJsonTree = this.activeDoc?.kind === 'json' && this.activeDoc.activeMode === 'tree';
998
1099
  const exitLabel = this.singleFile ? 'Esc/q Fechar' : 'Esc Voltar';
@@ -1013,50 +1114,63 @@ export class ExploreioApp {
1013
1114
  }
1014
1115
  const pos = this.currentEntries.length > 0 ? `${this.selectedIndex + 1}/${this.currentEntries.length}` : '0/0';
1015
1116
  const filterTag = this.filterQuery ? ` [filtro: ${this.filterQuery}]` : '';
1016
- const hint = ` ${pos}${filterTag} · Enter Ler · Tab/Ctrl+G Git · o Tela cheia · e Vim · ←→ Navegar · y Path · / Filtrar · t Tema · ? Ajuda · q Sair`;
1117
+ const kbKey = this.keybinds.formatActionKeys('global.openKeybinds', '/');
1118
+ const helpKey = this.keybinds.formatActionKeys('global.help', '/');
1119
+ const quitKey = this.keybinds.formatActionKeys('global.quit', '/');
1120
+ const hint = ` ${pos}${filterTag} · Enter Ler · Tab/Ctrl+G Git · e Vim · ${kbKey} Binds · t Tema · ${helpKey} Ajuda · ${quitKey} Sair`;
1017
1121
  return `${bg(theme.statusBg)}${fg(theme.statusFg)}${fitAnsi(hint, width)}${RESET}`;
1018
1122
  }
1019
1123
  overlayHelpModal(lines, width, height, theme) {
1020
- const boxW = Math.min(78, width - 4);
1124
+ const boxW = Math.min(82, width - 4);
1125
+ const k = (id) => this.keybinds.formatActionKeys(id, '/');
1126
+ const row = (keys, desc) => ` ${keys.padEnd(18).slice(0, 18)} ${desc}`;
1127
+ const kbKey = k('global.openKeybinds');
1021
1128
  const helpItems = [
1022
1129
  ' NAVEGADOR (3 Painéis estilo Yazi)',
1023
- ' ↑/↓ ou j/k Mover seleção (roda do mouse suportada)',
1024
- ' Enter ou → / l Entrar na pasta ou ABRIR ARQUIVO NO LEITOR',
1025
- ' ← / h / Bksp Subir para diretório pai',
1026
- ' / ou f Filtrar arquivos (fuzzy)',
1027
- ' . Mostrar/ocultar arquivos ocultos',
1028
- ' y Copiar caminho selecionado (arquivo ou pasta)',
1029
- ' a / r / d Criar / Renomear / Excluir (com confirmação)',
1030
- ' Tab ou Ctrl+G Abrir PAINEL GIT / GITHUB (status, árvore, branches, PRs)',
1130
+ row(`${k('browser.moveUp')} · ${k('browser.moveDown')}`, 'Mover seleção (roda do mouse suportada)'),
1131
+ row(k('browser.open'), 'Entrar na pasta ou ABRIR ARQUIVO NO LEITOR'),
1132
+ row(k('browser.parentDir'), 'Subir para diretório pai'),
1133
+ row(k('browser.filter'), 'Filtrar arquivos (fuzzy)'),
1134
+ row(k('browser.toggleHidden'), 'Mostrar/ocultar arquivos ocultos'),
1135
+ row(k('browser.copyPath'), 'Copiar caminho selecionado (arquivo ou pasta)'),
1136
+ row(`${k('browser.createEntry')} / ${k('browser.renameEntry')} / ${k('browser.deleteEntry')}`, 'Criar / Renomear / Excluir (com confirmação)'),
1137
+ row(k('browser.openGitPanel'), 'Abrir PAINEL GIT / GITHUB (status, árvore, branches, PRs)'),
1031
1138
  '',
1032
- ' PAINEL GIT / GITHUB (Tab ou Ctrl+G)',
1033
- ' 1-4 ou Tab Alternar abas (Status/Parados · Árvore · Branches · GitHub)',
1034
- ' s / S / c Stage/Unstage · Stage All · Commit com mensagem',
1035
- ' p / P / f / b Pull · Push · Fetch · Criar nova branch (? abre paleta)',
1139
+ ' PAINEL GIT / GITHUB',
1140
+ row(`1-4 / ${k('git.nextTab')}`, 'Alternar abas (Status/Parados · Árvore · Branches · GitHub)'),
1141
+ row(`${k('git.stageToggle')} · ${k('git.stageAll')} · ${k('git.commit')}`, 'Stage/Unstage · Stage All · Commit com mensagem'),
1142
+ row(`${k('git.pull')}/${k('git.push')}/${k('git.fetch')}/${k('git.createBranch')}`, `Pull · Push · Fetch · Nova branch (${k('git.quickPalette')} paleta)`),
1036
1143
  '',
1037
1144
  ' MODO LEITOR FULLSCREEN (Markdown · Mermaid · JSON · HTML · Código)',
1038
- ' Tab Alternar modo (Rendered↔Raw | Tree↔Pretty | Reader↔Source)',
1039
- ' o ou F Abrir arquivo em novo terminal TELA CHEIA (ideal p/ split)',
1040
- ' Enter / ← / → Expandir/recolher nó no JSON Tree (e=tudo, c=recolher)',
1041
- ' / e n / N Buscar texto no arquivo e saltar ocorrências',
1042
- ' y Copiar caminho completo do arquivo aberto',
1043
- ' e (ou E no JSON) Abrir arquivo no EDITOR VIM NATIVO',
1044
- ' t Alternar tema (Midnight · Parchment Light · Nord)',
1045
- ' Esc ou q Voltar ao navegador (ou sair)',
1145
+ row(k('reader.toggleMode'), 'Alternar modo (Rendered↔Raw | Tree↔Pretty | Reader↔Source)'),
1146
+ row(k('reader.openFullscreen'), 'Abrir arquivo em novo terminal TELA CHEIA'),
1147
+ row(`${k('reader.jsonToggleNode')}`, `JSON Tree: alternar nó (${k('reader.jsonExpandAll')}=tudo, ${k('reader.jsonCollapseAll')}=recolher)`),
1148
+ row(`${k('reader.search')} · ${k('reader.searchNext')}/${k('reader.searchPrev')}`, 'Buscar texto no arquivo e saltar ocorrências'),
1149
+ row(k('reader.openEditor'), 'Abrir arquivo no EDITOR VIM NATIVO'),
1150
+ row(k('global.cycleTheme'), 'Alternar tema (Midnight · Parchment Light · Nord)'),
1151
+ row(k('reader.back'), 'Voltar ao navegador (ou sair)'),
1152
+ '',
1153
+ ' CUSTOMIZAÇÃO DE KEYBINDS (Pressione ' + kbKey + ' agora para editar!)',
1154
+ row(kbKey, 'Abrir PAINEL INTERATIVO DE EDIÇÃO DE BINDS'),
1155
+ row('~/.exploreiorc.json', 'Config base (rode "exploreio --init-config" para gerar)'),
1046
1156
  '',
1047
1157
  ' MODO EDITOR VIM (NORMAL · INSERT · VISUAL · COMMAND)',
1048
- ' i/I/a/A/o/O Entrar em INSERT (Esc volta para NORMAL)',
1049
- ' hjkl · w/b/e Navegar · 0/^/$ · gg/G · Ctrl+d/u · / Buscar (n/N)',
1050
- ' x · dd · yy · p Editar · v/V Visual (y/d/c) · u Undo · Ctrl+r Redo',
1051
- ' :w · :wq · :q! Salvar · Salvar e sair · Sair sem salvar · :<linha>',
1158
+ row('i/I/a/A/o/O · Esc', 'Entrar em INSERT · voltar para NORMAL'),
1159
+ row(':w · :wq · :q!', 'Salvar · Salvar e sair · Sair sem salvar · :<linha>'),
1052
1160
  ];
1053
1161
  const startRow = Math.max(1, Math.floor((height - (helpItems.length + 4)) / 2));
1054
1162
  const padLeft = ' '.repeat(Math.max(0, Math.floor((width - boxW) / 2)));
1055
1163
  const innerW = boxW - 2;
1056
1164
  const modalLines = [
1057
1165
  `${padLeft}${fg(theme.borderActive)}${BOLD}╭${'─'.repeat(innerW)}╮${RESET}`,
1058
- `${padLeft}${fg(theme.borderActive)}${BOLD}│${bg(theme.headerBg)}${fg(theme.accent)}${fitAnsi(' ◈ EXPLOREIO — ATALHOS DE TECLADO (Esc/? para fechar)', innerW)}${RESET}${fg(theme.borderActive)}${BOLD}│${RESET}`,
1059
- ...helpItems.map((item) => `${padLeft}${fg(theme.borderActive)}│${bg(theme.statusBg)}${fg(item.startsWith(' NAVEGADOR') || item.startsWith(' MODO') ? theme.accentAlt : theme.text)}${fitAnsi(item, innerW)}${RESET}${fg(theme.borderActive)}│${RESET}`),
1166
+ `${padLeft}${fg(theme.borderActive)}${BOLD}│${bg(theme.headerBg)}${fg(theme.accent)}${fitAnsi(` ◈ EXPLOREIO — ATALHOS (${kbKey} Editar Binds · Esc/? Fechar)`, innerW)}${RESET}${fg(theme.borderActive)}${BOLD}│${RESET}`,
1167
+ ...helpItems.map((item) => {
1168
+ const isHeader = item.startsWith(' NAVEGADOR') ||
1169
+ item.startsWith(' PAINEL') ||
1170
+ item.startsWith(' MODO') ||
1171
+ item.startsWith(' CUSTOMIZAÇÃO');
1172
+ return `${padLeft}${fg(theme.borderActive)}│${bg(theme.statusBg)}${fg(isHeader ? theme.accentAlt : theme.text)}${fitAnsi(item, innerW)}${RESET}${fg(theme.borderActive)}│${RESET}`;
1173
+ }),
1060
1174
  `${padLeft}${fg(theme.borderActive)}${BOLD}╰${'─'.repeat(innerW)}╯${RESET}`,
1061
1175
  ];
1062
1176
  modalLines.forEach((mLine, offset) => {
@@ -1387,19 +1501,23 @@ export class ExploreioApp {
1387
1501
  }
1388
1502
  return;
1389
1503
  }
1390
- if (ev.name === 'escape' || ev.char === 'q') {
1504
+ if (this.keybinds.matches('git.back', ev)) {
1391
1505
  this.view = 'browser';
1392
1506
  await this.reloadDirectory();
1393
1507
  this.draw();
1394
1508
  return;
1395
1509
  }
1396
- if (ev.char === 't') {
1510
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
1397
1511
  this.themeName = nextTheme(this.themeName);
1398
1512
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
1399
1513
  this.draw();
1400
1514
  return;
1401
1515
  }
1402
- if (ev.char === '?' && this.gitSnapshot?.isGitRepo) {
1516
+ if (this.keybinds.matches('global.openKeybinds', ev) && !this.keybinds.matches('git.detailUp', ev)) {
1517
+ this.openKeybindsPanel('git');
1518
+ return;
1519
+ }
1520
+ if (this.keybinds.matches('git.quickPalette', ev) && this.gitSnapshot?.isGitRepo) {
1403
1521
  this.gitShowQuickPalette = true;
1404
1522
  this.gitQuickPaletteIndex = 0;
1405
1523
  this.draw();
@@ -1409,7 +1527,7 @@ export class ExploreioApp {
1409
1527
  this.draw();
1410
1528
  return;
1411
1529
  }
1412
- // Troca de abas (1..4 ou Tab / Shift+Tab)
1530
+ // Troca de abas (1..4 ou nextTab / prevTab)
1413
1531
  const tabOrder = ['status', 'graph', 'branches', 'github'];
1414
1532
  if (ev.char === '1' || ev.char === '2' || ev.char === '3' || ev.char === '4') {
1415
1533
  const nextTab = tabOrder[Number(ev.char) - 1] ?? 'status';
@@ -1423,9 +1541,10 @@ export class ExploreioApp {
1423
1541
  this.draw();
1424
1542
  return;
1425
1543
  }
1426
- if (ev.name === 'tab') {
1544
+ if (this.keybinds.matches('git.prevTab', ev) || this.keybinds.matches('git.nextTab', ev)) {
1427
1545
  const idx = tabOrder.indexOf(this.gitTab);
1428
- const nextIdx = ev.shift ? (idx - 1 + tabOrder.length) % tabOrder.length : (idx + 1) % tabOrder.length;
1546
+ const goPrev = this.keybinds.matches('git.prevTab', ev);
1547
+ const nextIdx = goPrev ? (idx - 1 + tabOrder.length) % tabOrder.length : (idx + 1) % tabOrder.length;
1429
1548
  this.gitTab = tabOrder[nextIdx] ?? 'status';
1430
1549
  this.gitSelectedIndex = 0;
1431
1550
  this.gitListScroll = 0;
@@ -1435,68 +1554,76 @@ export class ExploreioApp {
1435
1554
  return;
1436
1555
  }
1437
1556
  // Navegação na lista
1438
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
1557
+ if (this.keybinds.matches('git.moveUp', ev) || ev.name === 'wheel_up') {
1439
1558
  this.moveGitSelection(-1);
1440
1559
  await this.refreshGitDetail();
1441
1560
  this.draw();
1442
1561
  return;
1443
1562
  }
1444
- if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
1563
+ if (this.keybinds.matches('git.moveDown', ev) || ev.name === 'wheel_down') {
1445
1564
  this.moveGitSelection(1);
1446
1565
  await this.refreshGitDetail();
1447
1566
  this.draw();
1448
1567
  return;
1449
1568
  }
1450
1569
  // Rolagem do painel direito (diff / detalhes)
1451
- if (ev.char === 'J' || ev.name === 'pagedown') {
1570
+ if (this.keybinds.matches('git.detailDown', ev)) {
1452
1571
  this.gitDetailScroll = Math.min(Math.max(0, this.gitDetailLines.length - 5), this.gitDetailScroll + 8);
1453
1572
  this.draw();
1454
1573
  return;
1455
1574
  }
1456
- if (ev.char === 'K' || ev.name === 'pageup') {
1575
+ if (this.keybinds.matches('git.detailUp', ev)) {
1457
1576
  this.gitDetailScroll = Math.max(0, this.gitDetailScroll - 8);
1458
1577
  this.draw();
1459
1578
  return;
1460
1579
  }
1461
1580
  // Ações rápidas diretas
1462
- if (ev.char === 'r') {
1581
+ if (this.keybinds.matches('git.refresh', ev)) {
1463
1582
  await this.refreshGitPanelData(true);
1464
1583
  this.toastMessage = 'Painel Git/GitHub atualizado.';
1465
1584
  this.draw();
1466
1585
  return;
1467
1586
  }
1468
- if (ev.char === 'f') {
1587
+ if (this.keybinds.matches('git.fetch', ev)) {
1469
1588
  await this.triggerGitQuickAction('fetch');
1470
1589
  return;
1471
1590
  }
1472
- if (ev.char === 'p') {
1591
+ if (this.keybinds.matches('git.pull', ev)) {
1473
1592
  await this.triggerGitQuickAction('pull');
1474
1593
  return;
1475
1594
  }
1476
- if (ev.char === 'P') {
1595
+ if (this.keybinds.matches('git.push', ev)) {
1477
1596
  await this.triggerGitQuickAction('push');
1478
1597
  return;
1479
1598
  }
1480
- if (ev.char === 'c') {
1599
+ if (this.keybinds.matches('git.commit', ev)) {
1481
1600
  await this.triggerGitQuickAction('commit');
1482
1601
  return;
1483
1602
  }
1484
- if (ev.char === 'b') {
1603
+ if (this.keybinds.matches('git.createBranch', ev)) {
1485
1604
  await this.triggerGitQuickAction('create-branch');
1486
1605
  return;
1487
1606
  }
1488
- if (ev.char === 'S') {
1607
+ if (this.keybinds.matches('git.stageAll', ev)) {
1489
1608
  await this.triggerGitQuickAction('stage-all');
1490
1609
  return;
1491
1610
  }
1492
- if (ev.char === 'U') {
1611
+ if (this.keybinds.matches('git.unstageAll', ev)) {
1493
1612
  const res = await gitUnstageAll(this.gitSnapshot.repoRoot);
1494
1613
  this.toastMessage = res.ok ? 'Todas as alterações removidas do stage.' : (res.errorMessage ?? 'Erro no unstage.');
1495
1614
  await this.refreshGitPanelData(false);
1496
1615
  return;
1497
1616
  }
1617
+ if (this.keybinds.matches('git.stashPush', ev)) {
1618
+ await this.triggerGitQuickAction('stash-push');
1619
+ return;
1620
+ }
1621
+ if (this.keybinds.matches('git.stashPop', ev)) {
1622
+ await this.triggerGitQuickAction('stash-pop');
1623
+ return;
1624
+ }
1498
1625
  // Stage / Unstage individual na aba Status
1499
- if ((ev.char === 's' || ev.name === 'space') && this.gitTab === 'status') {
1626
+ if (this.keybinds.matches('git.stageToggle', ev) && this.gitTab === 'status') {
1500
1627
  const item = buildStatusListItems(this.gitSnapshot)[this.gitSelectedIndex];
1501
1628
  if (item?.kind === 'file') {
1502
1629
  const res = item.entry.section === 'staged'
@@ -1510,7 +1637,7 @@ export class ExploreioApp {
1510
1637
  return;
1511
1638
  }
1512
1639
  // Descartar alterações de um arquivo (com confirmação obrigatória)
1513
- if (ev.char === 'x' && this.gitTab === 'status') {
1640
+ if (this.keybinds.matches('git.discard', ev) && this.gitTab === 'status') {
1514
1641
  const item = buildStatusListItems(this.gitSnapshot)[this.gitSelectedIndex];
1515
1642
  if (item?.kind === 'file' && item.entry.section !== 'staged') {
1516
1643
  const entry = item.entry;
@@ -1524,12 +1651,12 @@ export class ExploreioApp {
1524
1651
  return;
1525
1652
  }
1526
1653
  // Copiar hash / path / branch / URL
1527
- if (ev.char === 'y') {
1654
+ if (this.keybinds.matches('git.copyItem', ev)) {
1528
1655
  await this.copyActiveGitItem();
1529
1656
  return;
1530
1657
  }
1531
1658
  // Enter contextual por aba
1532
- if (ev.name === 'enter') {
1659
+ if (this.keybinds.matches('git.openItem', ev)) {
1533
1660
  if (this.gitTab === 'branches') {
1534
1661
  const br = this.gitSnapshot.branches[this.gitSelectedIndex];
1535
1662
  if (br && !br.isCurrent) {
@@ -1704,5 +1831,189 @@ export class ExploreioApp {
1704
1831
  : `Falha ao copiar: ${stripUnsafeAnsi(res.error ?? 'clipboard indisponível')}`;
1705
1832
  this.draw();
1706
1833
  }
1834
+ // ==================== PAINEL DE EDIÇÃO DE KEYBINDS (SPEC-006) ====================
1835
+ openKeybindsPanel(returnTo) {
1836
+ this.keybindsReturnView = returnTo;
1837
+ this.view = 'keybinds';
1838
+ this.keybindsCaptureMode = null;
1839
+ this.toastMessage = '';
1840
+ this.clampKeybindsSelection();
1841
+ this.draw();
1842
+ }
1843
+ clampKeybindsSelection() {
1844
+ const items = getFilteredKeybindDefinitions(this.keybinds, this.keybindsTab, this.keybindsFilterQuery);
1845
+ const { height } = this.screen.getSize();
1846
+ const bodyHeight = Math.max(4, height - 3);
1847
+ if (items.length === 0) {
1848
+ this.keybindsSelectedIndex = 0;
1849
+ this.keybindsScroll = 0;
1850
+ return;
1851
+ }
1852
+ this.keybindsSelectedIndex = Math.max(0, Math.min(items.length - 1, this.keybindsSelectedIndex));
1853
+ if (this.keybindsSelectedIndex < this.keybindsScroll) {
1854
+ this.keybindsScroll = this.keybindsSelectedIndex;
1855
+ }
1856
+ else if (this.keybindsSelectedIndex >= this.keybindsScroll + bodyHeight) {
1857
+ this.keybindsScroll = this.keybindsSelectedIndex - bodyHeight + 1;
1858
+ }
1859
+ }
1860
+ saveKeybindsNow() {
1861
+ const res = saveKeybindsConfig(this.keybinds, this.configPath, this.themeName);
1862
+ if (res.ok) {
1863
+ this.keybindsDirty = false;
1864
+ this.toastMessage = `Keybinds salvos em ${stripUnsafeAnsi(this.configPath)}`;
1865
+ }
1866
+ else {
1867
+ this.toastMessage = `Erro ao salvar keybinds: ${stripUnsafeAnsi(res.error ?? 'falha de escrita')}`;
1868
+ }
1869
+ }
1870
+ async handleKeybindsKey(ev) {
1871
+ this.toastMessage = '';
1872
+ const items = getFilteredKeybindDefinitions(this.keybinds, this.keybindsTab, this.keybindsFilterQuery);
1873
+ const selected = items[this.keybindsSelectedIndex];
1874
+ // Modo de captura de tecla ao vivo
1875
+ if (this.keybindsCaptureMode) {
1876
+ if (ev.name === 'escape') {
1877
+ this.keybindsCaptureMode = null;
1878
+ this.toastMessage = 'Captura de tecla cancelada.';
1879
+ this.draw();
1880
+ return;
1881
+ }
1882
+ const captured = formatKeyEvent(ev);
1883
+ const mode = this.keybindsCaptureMode;
1884
+ this.keybindsCaptureMode = null;
1885
+ if (!captured || !selected) {
1886
+ this.toastMessage = 'Tecla não suportada para bind.';
1887
+ this.draw();
1888
+ return;
1889
+ }
1890
+ const changed = mode === 'replace'
1891
+ ? this.keybinds.replacePrimaryKey(selected.id, captured)
1892
+ : this.keybinds.addKey(selected.id, captured);
1893
+ if (changed) {
1894
+ this.keybindsDirty = true;
1895
+ const conflicts = this.keybinds.getConflictsForAction(selected.id);
1896
+ const label = formatKeyForDisplay(captured);
1897
+ this.toastMessage =
1898
+ conflicts.length > 0
1899
+ ? `Tecla [${label}] aplicada com ⚠ conflito em ${selected.context} (pressione s para salvar).`
1900
+ : `Tecla [${label}] aplicada em "${selected.label}" (pressione s para salvar).`;
1901
+ }
1902
+ else {
1903
+ this.toastMessage = `Tecla [${formatKeyForDisplay(captured)}] já estava atribuída.`;
1904
+ }
1905
+ this.draw();
1906
+ return;
1907
+ }
1908
+ if (ev.name === 'escape' || ev.char === 'q') {
1909
+ if (this.keybindsDirty) {
1910
+ this.saveKeybindsNow();
1911
+ }
1912
+ this.view = this.keybindsReturnView;
1913
+ this.draw();
1914
+ return;
1915
+ }
1916
+ if (ev.char === 't') {
1917
+ this.themeName = nextTheme(this.themeName);
1918
+ this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
1919
+ this.draw();
1920
+ return;
1921
+ }
1922
+ // Troca de aba por número (1..5) ou Tab / Shift+Tab
1923
+ if (ev.char && ev.char >= '1' && ev.char <= '5') {
1924
+ const tab = KEYBINDS_TABS[Number(ev.char) - 1];
1925
+ if (tab) {
1926
+ this.keybindsTab = tab.id;
1927
+ this.keybindsSelectedIndex = 0;
1928
+ this.keybindsScroll = 0;
1929
+ this.clampKeybindsSelection();
1930
+ }
1931
+ this.draw();
1932
+ return;
1933
+ }
1934
+ if (ev.name === 'tab') {
1935
+ const idx = KEYBINDS_TABS.findIndex((t) => t.id === this.keybindsTab);
1936
+ const nextIdx = ev.shift
1937
+ ? (idx - 1 + KEYBINDS_TABS.length) % KEYBINDS_TABS.length
1938
+ : (idx + 1) % KEYBINDS_TABS.length;
1939
+ this.keybindsTab = KEYBINDS_TABS[nextIdx]?.id ?? 'all';
1940
+ this.keybindsSelectedIndex = 0;
1941
+ this.keybindsScroll = 0;
1942
+ this.clampKeybindsSelection();
1943
+ this.draw();
1944
+ return;
1945
+ }
1946
+ if (ev.char === '/') {
1947
+ this.promptKind = 'keybinds-filter';
1948
+ this.promptInput = this.keybindsFilterQuery;
1949
+ this.draw();
1950
+ return;
1951
+ }
1952
+ if (ev.char === 's') {
1953
+ this.saveKeybindsNow();
1954
+ this.draw();
1955
+ return;
1956
+ }
1957
+ if (ev.char === 'R') {
1958
+ this.promptKind = 'keybinds-reset-confirm';
1959
+ this.promptInput = '';
1960
+ this.draw();
1961
+ return;
1962
+ }
1963
+ // Navegação vertical
1964
+ if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
1965
+ this.keybindsSelectedIndex = Math.max(0, this.keybindsSelectedIndex - 1);
1966
+ this.clampKeybindsSelection();
1967
+ this.draw();
1968
+ return;
1969
+ }
1970
+ if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
1971
+ this.keybindsSelectedIndex = Math.min(Math.max(0, items.length - 1), this.keybindsSelectedIndex + 1);
1972
+ this.clampKeybindsSelection();
1973
+ this.draw();
1974
+ return;
1975
+ }
1976
+ if (ev.name === 'pageup') {
1977
+ this.keybindsSelectedIndex = Math.max(0, this.keybindsSelectedIndex - 10);
1978
+ this.clampKeybindsSelection();
1979
+ this.draw();
1980
+ return;
1981
+ }
1982
+ if (ev.name === 'pagedown') {
1983
+ this.keybindsSelectedIndex = Math.min(Math.max(0, items.length - 1), this.keybindsSelectedIndex + 10);
1984
+ this.clampKeybindsSelection();
1985
+ this.draw();
1986
+ return;
1987
+ }
1988
+ if (!selected)
1989
+ return;
1990
+ if (ev.name === 'enter') {
1991
+ this.keybindsCaptureMode = 'replace';
1992
+ this.draw();
1993
+ return;
1994
+ }
1995
+ if (ev.char === '+' || ev.char === 'a') {
1996
+ this.keybindsCaptureMode = 'add';
1997
+ this.draw();
1998
+ return;
1999
+ }
2000
+ if (ev.char === 'd' || ev.name === 'backspace') {
2001
+ if (this.keybinds.removeLastKey(selected.id)) {
2002
+ this.keybindsDirty = true;
2003
+ this.toastMessage = `Última tecla removida de "${selected.label}" (pressione s para salvar).`;
2004
+ }
2005
+ else {
2006
+ this.toastMessage = 'Cada ação precisa manter pelo menos 1 tecla ativa.';
2007
+ }
2008
+ this.draw();
2009
+ return;
2010
+ }
2011
+ if (ev.char === 'r') {
2012
+ this.keybinds.resetAction(selected.id);
2013
+ this.keybindsDirty = true;
2014
+ this.toastMessage = `Ação "${selected.label}" restaurada para o padrão.`;
2015
+ this.draw();
2016
+ }
2017
+ }
1707
2018
  }
1708
2019
  //# sourceMappingURL=app.js.map