@leosdc/exploreio 0.6.1 → 0.8.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,18 +5,21 @@
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';
11
12
  import { buildGitHubListItems, buildGitPanelFrame, buildQuickActions, buildStatusListItems, formatGitHeaderBadge, } from '../git/gitView.js';
12
- import { createFileOrDir, deleteEntry, formatBytes, readDirectoryEntries, renameEntry, safeReadFilePreview, safeWriteTextFile, } from '../fs/explorer.js';
13
+ import { createFileOrDir, createFileSafe, createFolderSafe, deleteEntry, duplicateEntrySafe, formatBytes, readDirectoryEntries, renameEntry, safeReadFilePreview, safeWriteTextFile, suggestDuplicateName, } from '../fs/explorer.js';
13
14
  import { collectAllCollapsiblePaths } from '../renderers/json.js';
14
15
  import { renderDirectoryPreview, renderDocument, } from '../renderers/index.js';
15
16
  import { bg, fg, getTheme, nextTheme } from '../themes/palette.js';
16
17
  import { BOLD, DIM, ITALIC, RESET, fitAnsi, highlightSearch, stripUnsafeAnsi, truncateAnsi, visibleLength } from './ansi.js';
17
18
  import { copyTextToClipboard } from './clipboard.js';
19
+ import { applyModalOverlay, createInitialModalState, cycleModalExtension, renderCreateEntryModalOverlay, resolveModalTargetName, } from './createEntryModal.js';
18
20
  import { openInFullscreenShell } from './fullscreenLauncher.js';
19
21
  import { parseInputChunk } from './input.js';
22
+ import { KEYBINDS_TABS, buildKeybindsPanelFrame, getFilteredKeybindDefinitions, } from './keybindsView.js';
20
23
  import { ScreenBuffer } from './screen.js';
21
24
  function getFileBadge(entry, theme) {
22
25
  if (entry.isDirectory)
@@ -100,9 +103,20 @@ export class ExploreioApp {
100
103
  gitQuickPaletteIndex = 0;
101
104
  gitBusyMessage = '';
102
105
  gitPendingConfirm = null;
103
- // Prompt modal inline (barra inferior)
106
+ // Custom Keybinds & Painel Interativo (SPEC-006)
107
+ keybinds;
108
+ configPath;
109
+ keybindsTab = 'all';
110
+ keybindsSelectedIndex = 0;
111
+ keybindsScroll = 0;
112
+ keybindsFilterQuery = '';
113
+ keybindsCaptureMode = null;
114
+ keybindsDirty = false;
115
+ keybindsReturnView = 'browser';
116
+ // Prompt modal inline (barra inferior) & Modal de criação arquivo/pasta (SPEC-007)
104
117
  promptKind = null;
105
118
  promptInput = '';
119
+ createModal = null;
106
120
  toastMessage = '';
107
121
  running = false;
108
122
  constructor(options) {
@@ -111,6 +125,12 @@ export class ExploreioApp {
111
125
  this.singleFile = Boolean(options.singleFile);
112
126
  this.themeName = options.themeName ?? 'midnight';
113
127
  this.showHidden = Boolean(options.showHidden);
128
+ const loadedBinds = loadKeybindsRegistry(options.configPath);
129
+ this.keybinds = loadedBinds.registry;
130
+ this.configPath = loadedBinds.configPath;
131
+ if (loadedBinds.warning) {
132
+ this.toastMessage = loadedBinds.warning;
133
+ }
114
134
  if (options.initialFile) {
115
135
  this.currentDir = path.dirname(path.resolve(options.initialFile));
116
136
  }
@@ -182,12 +202,22 @@ export class ExploreioApp {
182
202
  process.exit(0);
183
203
  }
184
204
  if (this.showHelp) {
185
- if (ev.name === 'escape' || ev.char === '?' || ev.char === 'q') {
205
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
206
+ this.showHelp = false;
207
+ const ret = this.view === 'reader' || this.view === 'git' ? this.view : 'browser';
208
+ this.openKeybindsPanel(ret);
209
+ continue;
210
+ }
211
+ if (ev.name === 'escape' || this.keybinds.matches('global.help', ev) || this.keybinds.matches('global.quit', ev)) {
186
212
  this.showHelp = false;
187
213
  this.draw();
188
214
  }
189
215
  continue;
190
216
  }
217
+ if (this.createModal) {
218
+ await this.handleCreateModalKey(ev);
219
+ continue;
220
+ }
191
221
  if (this.promptKind) {
192
222
  await this.handlePromptKey(ev);
193
223
  continue;
@@ -195,6 +225,9 @@ export class ExploreioApp {
195
225
  if (this.view === 'editor') {
196
226
  await this.handleEditorKey(ev);
197
227
  }
228
+ else if (this.view === 'keybinds') {
229
+ await this.handleKeybindsKey(ev);
230
+ }
198
231
  else if (this.view === 'git') {
199
232
  await this.handleGitKey(ev);
200
233
  }
@@ -212,6 +245,11 @@ export class ExploreioApp {
212
245
  this.filterQuery = '';
213
246
  await this.reloadDirectory();
214
247
  }
248
+ else if (this.promptKind === 'keybinds-filter') {
249
+ this.keybindsFilterQuery = '';
250
+ this.keybindsSelectedIndex = 0;
251
+ this.keybindsScroll = 0;
252
+ }
215
253
  this.promptKind = null;
216
254
  this.promptInput = '';
217
255
  this.draw();
@@ -240,14 +278,27 @@ export class ExploreioApp {
240
278
  }
241
279
  else if (kind === 'create' && value.trim()) {
242
280
  try {
243
- await createFileOrDir(this.currentDir, value);
281
+ const created = await createFileOrDir(this.currentDir, value);
244
282
  this.toastMessage = `Criado: ${value.trim()}`;
245
- await this.reloadDirectory();
283
+ await this.reloadDirectory(path.basename(created));
246
284
  }
247
285
  catch (err) {
248
286
  this.toastMessage = err instanceof Error ? err.message : String(err);
249
287
  }
250
288
  }
289
+ else if (kind === 'duplicate' && value.trim()) {
290
+ const current = this.currentEntries[this.selectedIndex];
291
+ if (current) {
292
+ try {
293
+ const res = await duplicateEntrySafe(current.fullPath, value);
294
+ this.toastMessage = `Duplicado: ${value.trim()}`;
295
+ await this.reloadDirectory(res.focusName);
296
+ }
297
+ catch (err) {
298
+ this.toastMessage = err instanceof Error ? err.message : String(err);
299
+ }
300
+ }
301
+ }
251
302
  else if (kind === 'rename' && value.trim()) {
252
303
  const current = this.currentEntries[this.selectedIndex];
253
304
  if (current) {
@@ -293,6 +344,21 @@ export class ExploreioApp {
293
344
  this.toastMessage = 'Operação Git cancelada.';
294
345
  }
295
346
  }
347
+ else if (kind === 'keybinds-filter') {
348
+ this.keybindsFilterQuery = value;
349
+ this.keybindsSelectedIndex = 0;
350
+ this.keybindsScroll = 0;
351
+ }
352
+ else if (kind === 'keybinds-reset-confirm') {
353
+ if (value.trim().toLowerCase() === 'y' || value.trim().toLowerCase() === 's') {
354
+ this.keybinds.resetAll();
355
+ this.keybindsDirty = true;
356
+ this.toastMessage = 'Todos os keybinds restaurados para o padrão (pressione s para salvar).';
357
+ }
358
+ else {
359
+ this.toastMessage = 'Reset global cancelado.';
360
+ }
361
+ }
296
362
  this.draw();
297
363
  return;
298
364
  }
@@ -302,6 +368,11 @@ export class ExploreioApp {
302
368
  this.filterQuery = this.promptInput;
303
369
  await this.reloadDirectory();
304
370
  }
371
+ else if (this.promptKind === 'keybinds-filter') {
372
+ this.keybindsFilterQuery = this.promptInput;
373
+ this.keybindsSelectedIndex = 0;
374
+ this.keybindsScroll = 0;
375
+ }
305
376
  this.draw();
306
377
  return;
307
378
  }
@@ -311,118 +382,216 @@ export class ExploreioApp {
311
382
  this.filterQuery = this.promptInput;
312
383
  await this.reloadDirectory();
313
384
  }
385
+ else if (this.promptKind === 'keybinds-filter') {
386
+ this.keybindsFilterQuery = this.promptInput;
387
+ this.keybindsSelectedIndex = 0;
388
+ this.keybindsScroll = 0;
389
+ }
390
+ this.draw();
391
+ }
392
+ }
393
+ async handleCreateModalKey(ev) {
394
+ const modal = this.createModal;
395
+ if (!modal)
396
+ return;
397
+ if (ev.name === 'escape') {
398
+ this.createModal = null;
399
+ this.draw();
400
+ return;
401
+ }
402
+ if (modal.mode === 'file') {
403
+ if (ev.name === 'tab') {
404
+ cycleModalExtension(modal, ev.shift ? -1 : 1);
405
+ this.draw();
406
+ return;
407
+ }
408
+ if (ev.name === 'up' || ev.name === 'down') {
409
+ cycleModalExtension(modal, ev.name === 'up' ? -1 : 1);
410
+ this.draw();
411
+ return;
412
+ }
413
+ if (ev.ctrl && ev.name === 'e') {
414
+ modal.openInEditor = !modal.openInEditor;
415
+ this.draw();
416
+ return;
417
+ }
418
+ }
419
+ if (ev.name === 'enter') {
420
+ const targetName = resolveModalTargetName(modal);
421
+ if (!targetName) {
422
+ modal.errorMessage = 'Informe um nome antes de confirmar.';
423
+ this.draw();
424
+ return;
425
+ }
426
+ try {
427
+ const shouldOpenEditor = modal.mode === 'file' && modal.openInEditor;
428
+ const res = modal.mode === 'file'
429
+ ? await createFileSafe(this.currentDir, targetName)
430
+ : await createFolderSafe(this.currentDir, targetName);
431
+ this.createModal = null;
432
+ this.toastMessage =
433
+ modal.mode === 'file' ? `Arquivo criado: ${targetName}` : `Pasta criada: ${targetName}`;
434
+ await this.reloadDirectory(res.focusName);
435
+ if (shouldOpenEditor) {
436
+ await this.openFileInEditor(res.targetPath, 'browser');
437
+ return;
438
+ }
439
+ }
440
+ catch (err) {
441
+ modal.errorMessage = err instanceof Error ? err.message : String(err);
442
+ }
443
+ this.draw();
444
+ return;
445
+ }
446
+ if (ev.name === 'backspace') {
447
+ modal.input = modal.input.slice(0, -1);
448
+ modal.errorMessage = '';
449
+ this.draw();
450
+ return;
451
+ }
452
+ if (ev.char && !ev.ctrl) {
453
+ modal.input += ev.char;
454
+ modal.errorMessage = '';
314
455
  this.draw();
315
456
  }
316
457
  }
317
458
  async handleBrowserKey(ev) {
318
459
  this.toastMessage = '';
319
460
  const maxIdx = Math.max(0, this.currentEntries.length - 1);
320
- if (ev.char === 'q') {
461
+ if (this.keybinds.matches('global.quit', ev)) {
321
462
  this.shutdown();
322
463
  process.exit(0);
323
464
  }
324
- if (ev.char === '?') {
465
+ if (this.keybinds.matches('global.help', ev)) {
325
466
  this.showHelp = true;
326
467
  this.draw();
327
468
  return;
328
469
  }
329
- if (ev.char === 't') {
470
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
471
+ this.openKeybindsPanel('browser');
472
+ return;
473
+ }
474
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
330
475
  this.themeName = nextTheme(this.themeName);
331
476
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
332
477
  await this.refreshSelectedPreview();
333
478
  this.draw();
334
479
  return;
335
480
  }
336
- if (ev.char === '.') {
481
+ if (this.keybinds.matches('browser.toggleHidden', ev)) {
337
482
  this.showHidden = !this.showHidden;
338
483
  this.toastMessage = this.showHidden ? 'Exibindo arquivos ocultos' : 'Ocultando arquivos iniciados por "."';
339
484
  await this.reloadDirectory();
340
485
  this.draw();
341
486
  return;
342
487
  }
343
- if (ev.char === '/' || ev.char === 'f') {
488
+ if (this.keybinds.matches('browser.filter', ev)) {
344
489
  this.promptKind = 'filter';
345
490
  this.promptInput = this.filterQuery;
346
491
  this.draw();
347
492
  return;
348
493
  }
349
- if (ev.char === 'a') {
494
+ if (this.keybinds.matches('browser.createFile', ev)) {
495
+ this.createModal = createInitialModalState('file');
496
+ this.draw();
497
+ return;
498
+ }
499
+ if (this.keybinds.matches('browser.createFolder', ev)) {
500
+ this.createModal = createInitialModalState('folder');
501
+ this.draw();
502
+ return;
503
+ }
504
+ if (this.keybinds.matches('browser.duplicateEntry', ev) && this.currentEntries[this.selectedIndex]) {
505
+ const current = this.currentEntries[this.selectedIndex];
506
+ const existingNames = new Set(this.currentEntries.map((e) => e.name));
507
+ this.promptKind = 'duplicate';
508
+ this.promptInput = suggestDuplicateName(existingNames, current.name, current.isDirectory);
509
+ this.draw();
510
+ return;
511
+ }
512
+ if (this.keybinds.matches('browser.createEntry', ev)) {
350
513
  this.promptKind = 'create';
351
514
  this.promptInput = '';
352
515
  this.draw();
353
516
  return;
354
517
  }
355
- if (ev.char === 'r' && this.currentEntries[this.selectedIndex]) {
518
+ if (this.keybinds.matches('browser.renameEntry', ev) && this.currentEntries[this.selectedIndex]) {
356
519
  this.promptKind = 'rename';
357
520
  this.promptInput = this.currentEntries[this.selectedIndex]?.name ?? '';
358
521
  this.draw();
359
522
  return;
360
523
  }
361
- if (ev.char === 'd' && this.currentEntries[this.selectedIndex]) {
524
+ if (this.keybinds.matches('browser.deleteEntry', ev) && this.currentEntries[this.selectedIndex]) {
362
525
  this.promptKind = 'delete';
363
526
  this.promptInput = '';
364
527
  this.draw();
365
528
  return;
366
529
  }
367
- if (ev.char === 'y') {
530
+ if (this.keybinds.matches('browser.copyPath', ev)) {
368
531
  await this.copySelectedPath();
369
532
  return;
370
533
  }
371
- if (ev.char === 'o' || ev.char === 'F') {
534
+ if (this.keybinds.matches('browser.openFullscreen', ev)) {
372
535
  const entry = this.currentEntries[this.selectedIndex];
373
536
  if (entry && !entry.isDirectory) {
374
537
  await this.openInFullscreenTerminal(entry.fullPath);
375
538
  }
376
539
  else {
377
- this.toastMessage = 'Selecione um arquivo para abrir em terminal tela cheia (o).';
540
+ this.toastMessage = `Selecione um arquivo para abrir em terminal tela cheia (${this.keybinds.formatActionKeys('browser.openFullscreen')}).`;
378
541
  this.draw();
379
542
  }
380
543
  return;
381
544
  }
382
- if (ev.name === 'tab' || (ev.ctrl && ev.name === 'g')) {
545
+ if (this.keybinds.matches('browser.openGitPanel', ev)) {
383
546
  await this.openGitPanel();
384
547
  return;
385
548
  }
386
- if (ev.char === 'e') {
549
+ if (this.keybinds.matches('browser.refresh', ev)) {
550
+ await this.reloadDirectory();
551
+ this.toastMessage = 'Diretório recarregado.';
552
+ this.draw();
553
+ return;
554
+ }
555
+ if (this.keybinds.matches('browser.openEditor', ev)) {
387
556
  const entry = this.currentEntries[this.selectedIndex];
388
557
  if (entry && !entry.isDirectory) {
389
558
  await this.openFileInEditor(entry.fullPath, 'browser');
390
559
  }
391
560
  else {
392
- this.toastMessage = 'Selecione um arquivo de texto para abrir no editor Vim (e).';
561
+ this.toastMessage = `Selecione um arquivo de texto para abrir no editor Vim (${this.keybinds.formatActionKeys('browser.openEditor')}).`;
393
562
  this.draw();
394
563
  }
395
564
  return;
396
565
  }
397
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
566
+ if (this.keybinds.matches('browser.moveUp', ev) || ev.name === 'wheel_up') {
398
567
  if (this.selectedIndex > 0) {
399
568
  this.selectedIndex--;
400
569
  await this.refreshSelectedPreview();
401
570
  }
402
571
  }
403
- else if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
572
+ else if (this.keybinds.matches('browser.moveDown', ev) || ev.name === 'wheel_down') {
404
573
  if (this.selectedIndex < maxIdx) {
405
574
  this.selectedIndex++;
406
575
  await this.refreshSelectedPreview();
407
576
  }
408
577
  }
409
- else if (ev.name === 'pageup') {
578
+ else if (this.keybinds.matches('browser.pageUp', ev)) {
410
579
  this.selectedIndex = Math.max(0, this.selectedIndex - 10);
411
580
  await this.refreshSelectedPreview();
412
581
  }
413
- else if (ev.name === 'pagedown') {
582
+ else if (this.keybinds.matches('browser.pageDown', ev)) {
414
583
  this.selectedIndex = Math.min(maxIdx, this.selectedIndex + 10);
415
584
  await this.refreshSelectedPreview();
416
585
  }
417
- else if (ev.name === 'home' || ev.char === 'g') {
586
+ else if (this.keybinds.matches('browser.goTop', ev)) {
418
587
  this.selectedIndex = 0;
419
588
  await this.refreshSelectedPreview();
420
589
  }
421
- else if (ev.name === 'end' || ev.char === 'G') {
590
+ else if (this.keybinds.matches('browser.goBottom', ev)) {
422
591
  this.selectedIndex = maxIdx;
423
592
  await this.refreshSelectedPreview();
424
593
  }
425
- else if (ev.name === 'left' || ev.char === 'h' || ev.name === 'backspace') {
594
+ else if (this.keybinds.matches('browser.parentDir', ev)) {
426
595
  const parent = path.dirname(this.currentDir);
427
596
  if (parent !== this.currentDir) {
428
597
  const previousName = path.basename(this.currentDir);
@@ -431,7 +600,7 @@ export class ExploreioApp {
431
600
  await this.reloadDirectory(previousName);
432
601
  }
433
602
  }
434
- else if (ev.name === 'enter' || ev.name === 'right' || ev.char === 'l') {
603
+ else if (this.keybinds.matches('browser.open', ev)) {
435
604
  const entry = this.currentEntries[this.selectedIndex];
436
605
  if (!entry)
437
606
  return;
@@ -454,7 +623,7 @@ export class ExploreioApp {
454
623
  const bodyHeight = Math.max(4, height - 3);
455
624
  const totalLines = this.activeDoc?.lines.length ?? 0;
456
625
  const isJsonTree = this.activeDoc?.kind === 'json' && this.activeDoc.activeMode === 'tree';
457
- if (ev.name === 'escape' || ev.char === 'q' || ev.name === 'backspace') {
626
+ if (this.keybinds.matches('reader.back', ev)) {
458
627
  if (this.singleFile) {
459
628
  this.shutdown();
460
629
  process.exit(0);
@@ -466,35 +635,41 @@ export class ExploreioApp {
466
635
  this.draw();
467
636
  return;
468
637
  }
469
- if (ev.char === '?') {
638
+ if (this.keybinds.matches('global.help', ev)) {
470
639
  this.showHelp = true;
471
640
  this.draw();
472
641
  return;
473
642
  }
474
- if (ev.char === 't') {
643
+ if (this.keybinds.matches('global.openKeybinds', ev)) {
644
+ this.openKeybindsPanel('reader');
645
+ return;
646
+ }
647
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
475
648
  this.themeName = nextTheme(this.themeName);
476
649
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
477
650
  this.rerenderReaderDoc();
478
651
  this.draw();
479
652
  return;
480
653
  }
481
- if (ev.char === 'y') {
654
+ if (this.keybinds.matches('reader.copyPath', ev)) {
482
655
  await this.copySelectedPath();
483
656
  return;
484
657
  }
485
- if ((ev.char === 'o' || ev.char === 'F') && this.activeFilePreview) {
658
+ if (this.keybinds.matches('reader.openFullscreen', ev) && this.activeFilePreview) {
486
659
  await this.openInFullscreenTerminal(this.activeFilePreview.filePath, this.activeDoc?.activeMode);
487
660
  return;
488
661
  }
489
- if (ev.ctrl && ev.name === 'g') {
662
+ if (this.keybinds.matches('reader.openGitPanel', ev)) {
490
663
  await this.openGitPanel();
491
664
  return;
492
665
  }
493
- if ((ev.char === 'E' || (ev.char === 'e' && !isJsonTree)) && this.activeFilePreview) {
666
+ if (this.keybinds.matches('reader.openEditor', ev) &&
667
+ !(isJsonTree && this.keybinds.matches('reader.jsonExpandAll', ev)) &&
668
+ this.activeFilePreview) {
494
669
  await this.openFileInEditor(this.activeFilePreview.filePath, 'reader');
495
670
  return;
496
671
  }
497
- if (ev.name === 'tab' && this.activeDoc && this.activeDoc.modes.length > 1) {
672
+ if (this.keybinds.matches('reader.toggleMode', ev) && this.activeDoc && this.activeDoc.modes.length > 1) {
498
673
  const idx = this.activeDoc.modes.indexOf(this.activeDoc.activeMode);
499
674
  this.preferredMode = this.activeDoc.modes[(idx + 1) % this.activeDoc.modes.length];
500
675
  this.readerScroll = 0;
@@ -504,19 +679,19 @@ export class ExploreioApp {
504
679
  this.draw();
505
680
  return;
506
681
  }
507
- if (ev.char === '/') {
682
+ if (this.keybinds.matches('reader.search', ev)) {
508
683
  this.promptKind = 'search';
509
684
  this.promptInput = this.readerSearchQuery;
510
685
  this.draw();
511
686
  return;
512
687
  }
513
- if (ev.char === 'n' && this.readerSearchMatches.length > 0) {
688
+ if (this.keybinds.matches('reader.searchNext', ev) && this.readerSearchMatches.length > 0) {
514
689
  this.readerSearchCursor = (this.readerSearchCursor + 1) % this.readerSearchMatches.length;
515
690
  this.jumpToMatch(this.readerSearchCursor);
516
691
  this.draw();
517
692
  return;
518
693
  }
519
- if (ev.char === 'N' && this.readerSearchMatches.length > 0) {
694
+ if (this.keybinds.matches('reader.searchPrev', ev) && this.readerSearchMatches.length > 0) {
520
695
  this.readerSearchCursor =
521
696
  (this.readerSearchCursor - 1 + this.readerSearchMatches.length) % this.readerSearchMatches.length;
522
697
  this.jumpToMatch(this.readerSearchCursor);
@@ -526,7 +701,7 @@ export class ExploreioApp {
526
701
  // Interações exclusivas da Árvore JSON (expandir/recolher)
527
702
  if (isJsonTree && this.activeDoc) {
528
703
  const row = this.activeDoc.jsonTreeRows[this.readerCursor];
529
- if (ev.name === 'enter' || ev.name === 'space') {
704
+ if (this.keybinds.matches('reader.jsonToggleNode', ev)) {
530
705
  if (row?.collapsible) {
531
706
  if (this.collapsedJsonPaths.has(row.path))
532
707
  this.collapsedJsonPaths.delete(row.path);
@@ -537,7 +712,7 @@ export class ExploreioApp {
537
712
  this.draw();
538
713
  return;
539
714
  }
540
- if (ev.name === 'left' || ev.char === 'h') {
715
+ if (this.keybinds.matches('reader.jsonCollapseNode', ev)) {
541
716
  if (row?.collapsible && !row.collapsed) {
542
717
  this.collapsedJsonPaths.add(row.path);
543
718
  this.rerenderReaderDoc();
@@ -545,7 +720,7 @@ export class ExploreioApp {
545
720
  this.draw();
546
721
  return;
547
722
  }
548
- if (ev.name === 'right' || ev.char === 'l') {
723
+ if (this.keybinds.matches('reader.jsonExpandNode', ev)) {
549
724
  if (row?.collapsible && row.collapsed) {
550
725
  this.collapsedJsonPaths.delete(row.path);
551
726
  this.rerenderReaderDoc();
@@ -553,14 +728,14 @@ export class ExploreioApp {
553
728
  this.draw();
554
729
  return;
555
730
  }
556
- if (ev.char === 'e') {
731
+ if (this.keybinds.matches('reader.jsonExpandAll', ev)) {
557
732
  this.collapsedJsonPaths.clear();
558
733
  this.rerenderReaderDoc();
559
734
  this.toastMessage = 'Todos os nós JSON expandidos';
560
735
  this.draw();
561
736
  return;
562
737
  }
563
- if (ev.char === 'c' && this.activeFilePreview) {
738
+ if (this.keybinds.matches('reader.jsonCollapseAll', ev) && this.activeFilePreview) {
564
739
  try {
565
740
  const parsed = JSON.parse(this.activeFilePreview.text);
566
741
  const all = collectAllCollapsiblePaths(parsed).filter((p) => p !== '$');
@@ -579,7 +754,7 @@ export class ExploreioApp {
579
754
  }
580
755
  // Scroll & navegação vertical no leitor
581
756
  const maxScroll = Math.max(0, totalLines - bodyHeight);
582
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
757
+ if (this.keybinds.matches('reader.moveUp', ev) || ev.name === 'wheel_up') {
583
758
  if (isJsonTree) {
584
759
  this.readerCursor = Math.max(0, this.readerCursor - 1);
585
760
  if (this.readerCursor < this.readerScroll)
@@ -589,7 +764,7 @@ export class ExploreioApp {
589
764
  this.readerScroll = Math.max(0, this.readerScroll - (ev.name === 'wheel_up' ? 3 : 1));
590
765
  }
591
766
  }
592
- else if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
767
+ else if (this.keybinds.matches('reader.moveDown', ev) || ev.name === 'wheel_down') {
593
768
  if (isJsonTree) {
594
769
  this.readerCursor = Math.min(Math.max(0, totalLines - 1), this.readerCursor + 1);
595
770
  if (this.readerCursor >= this.readerScroll + bodyHeight) {
@@ -600,21 +775,21 @@ export class ExploreioApp {
600
775
  this.readerScroll = Math.min(maxScroll, this.readerScroll + (ev.name === 'wheel_down' ? 3 : 1));
601
776
  }
602
777
  }
603
- else if (ev.name === 'pageup' || ev.char === 'b') {
778
+ else if (this.keybinds.matches('reader.pageUp', ev)) {
604
779
  const step = Math.max(4, bodyHeight - 2);
605
780
  this.readerScroll = Math.max(0, this.readerScroll - step);
606
781
  this.readerCursor = Math.max(0, this.readerCursor - step);
607
782
  }
608
- else if (ev.name === 'pagedown' || ev.name === 'space') {
783
+ else if (this.keybinds.matches('reader.pageDown', ev)) {
609
784
  const step = Math.max(4, bodyHeight - 2);
610
785
  this.readerScroll = Math.min(maxScroll, this.readerScroll + step);
611
786
  this.readerCursor = Math.min(Math.max(0, totalLines - 1), this.readerCursor + step);
612
787
  }
613
- else if (ev.name === 'home' || ev.char === 'g') {
788
+ else if (this.keybinds.matches('reader.goTop', ev)) {
614
789
  this.readerScroll = 0;
615
790
  this.readerCursor = 0;
616
791
  }
617
- else if (ev.name === 'end' || ev.char === 'G') {
792
+ else if (this.keybinds.matches('reader.goBottom', ev)) {
618
793
  this.readerScroll = maxScroll;
619
794
  this.readerCursor = Math.max(0, totalLines - 1);
620
795
  }
@@ -839,24 +1014,46 @@ export class ExploreioApp {
839
1014
  statusMessage: this.editorStatusMessage,
840
1015
  statusIsError: this.editorStatusIsError,
841
1016
  })
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,
1017
+ : this.view === 'keybinds'
1018
+ ? buildKeybindsPanelFrame({
1019
+ width,
1020
+ height,
1021
+ theme,
1022
+ registry: this.keybinds,
1023
+ configPath: this.configPath,
855
1024
  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);
1025
+ state: {
1026
+ activeTab: this.keybindsTab,
1027
+ selectedIndex: this.keybindsSelectedIndex,
1028
+ scrollOffset: this.keybindsScroll,
1029
+ filterQuery: this.keybindsFilterQuery,
1030
+ captureMode: this.keybindsCaptureMode,
1031
+ dirty: this.keybindsDirty,
1032
+ statusMessage: this.toastMessage,
1033
+ },
1034
+ })
1035
+ : this.view === 'git' && this.gitSnapshot
1036
+ ? buildGitPanelFrame({
1037
+ snapshot: this.gitSnapshot,
1038
+ github: this.gitHubData,
1039
+ activeTab: this.gitTab,
1040
+ selectedIndex: this.gitSelectedIndex,
1041
+ listScroll: this.gitListScroll,
1042
+ detailTitle: this.gitDetailTitle,
1043
+ detailLines: this.gitDetailLines,
1044
+ detailScroll: this.gitDetailScroll,
1045
+ showQuickPalette: this.gitShowQuickPalette,
1046
+ quickPaletteIndex: this.gitQuickPaletteIndex,
1047
+ busyMessage: this.gitBusyMessage,
1048
+ footerLine: this.buildFooterBar(width, theme),
1049
+ }, width, height, theme)
1050
+ : this.view === 'reader'
1051
+ ? this.buildReaderFrame(width, height, theme)
1052
+ : this.buildBrowserFrame(width, height, theme);
1053
+ if (this.createModal) {
1054
+ const modalLines = renderCreateEntryModalOverlay(this.createModal, this.currentDir, width, height, theme);
1055
+ applyModalOverlay(lines, modalLines, height);
1056
+ }
860
1057
  if (this.showHelp) {
861
1058
  this.overlayHelpModal(lines, width, height, theme);
862
1059
  }
@@ -981,18 +1178,29 @@ export class ExploreioApp {
981
1178
  filter: 'Filtrar arquivos: ',
982
1179
  search: 'Buscar no arquivo: ',
983
1180
  create: 'Criar arquivo ou pasta/ : ',
1181
+ duplicate: 'Duplicar para: ',
984
1182
  rename: 'Renomear para: ',
985
1183
  delete: `Excluir "${this.currentEntries[this.selectedIndex]?.name ?? ''}"? (y/N): `,
986
1184
  'git-commit': 'git commit -m : ',
987
1185
  'git-branch-create': 'Nova branch (git checkout -b): ',
988
1186
  'git-confirm': `${this.gitPendingConfirm?.label ?? 'Confirmar operação Git'}? (y/N): `,
1187
+ 'keybinds-filter': 'Filtrar keybinds: ',
1188
+ 'keybinds-reset-confirm': 'Restaurar TODOS os keybinds para o padrão? (y/N): ',
989
1189
  };
990
1190
  const text = ` ${labels[this.promptKind]}${this.promptInput}█`;
991
1191
  return `${bg(theme.selectionBg)}${fg(theme.selectionFg)}${BOLD}${fitAnsi(text, width)}${RESET}`;
992
1192
  }
1193
+ if (this.view === 'keybinds' && this.keybindsCaptureMode) {
1194
+ const modeText = this.keybindsCaptureMode === 'replace' ? 'SUBSTITUIR tecla principal' : 'ADICIONAR tecla alternativa';
1195
+ return `${bg(theme.selectionBg)}${fg(theme.selectionFg)}${BOLD}${fitAnsi(` ◉ Pressione a nova tecla para ${modeText} (Esc cancela)`, width)}${RESET}`;
1196
+ }
993
1197
  if (this.toastMessage) {
994
1198
  return `${bg(theme.statusBg)}${fg(theme.warning)}${BOLD}${fitAnsi(` ◆ ${this.toastMessage}`, width)}${RESET}`;
995
1199
  }
1200
+ if (this.view === 'keybinds') {
1201
+ 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';
1202
+ return `${bg(theme.statusBg)}${fg(theme.statusFg)}${fitAnsi(hint, width)}${RESET}`;
1203
+ }
996
1204
  if (this.view === 'reader') {
997
1205
  const isJsonTree = this.activeDoc?.kind === 'json' && this.activeDoc.activeMode === 'tree';
998
1206
  const exitLabel = this.singleFile ? 'Esc/q Fechar' : 'Esc Voltar';
@@ -1013,50 +1221,64 @@ export class ExploreioApp {
1013
1221
  }
1014
1222
  const pos = this.currentEntries.length > 0 ? `${this.selectedIndex + 1}/${this.currentEntries.length}` : '0/0';
1015
1223
  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`;
1224
+ const kbKey = this.keybinds.formatActionKeys('global.openKeybinds', '/');
1225
+ const helpKey = this.keybinds.formatActionKeys('global.help', '/');
1226
+ const quitKey = this.keybinds.formatActionKeys('global.quit', '/');
1227
+ const hint = ` ${pos}${filterTag} · Enter Ler · Tab/Ctrl+G Git · e Vim · ${kbKey} Binds · t Tema · ${helpKey} Ajuda · ${quitKey} Sair`;
1017
1228
  return `${bg(theme.statusBg)}${fg(theme.statusFg)}${fitAnsi(hint, width)}${RESET}`;
1018
1229
  }
1019
1230
  overlayHelpModal(lines, width, height, theme) {
1020
- const boxW = Math.min(78, width - 4);
1231
+ const boxW = Math.min(82, width - 4);
1232
+ const k = (id) => this.keybinds.formatActionKeys(id, '/');
1233
+ const row = (keys, desc) => ` ${keys.padEnd(18).slice(0, 18)} ${desc}`;
1234
+ const kbKey = k('global.openKeybinds');
1021
1235
  const helpItems = [
1022
1236
  ' 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)',
1237
+ row(`${k('browser.moveUp')} · ${k('browser.moveDown')}`, 'Mover seleção (roda do mouse suportada)'),
1238
+ row(k('browser.open'), 'Entrar na pasta ou ABRIR ARQUIVO NO LEITOR'),
1239
+ row(k('browser.parentDir'), 'Subir para diretório pai'),
1240
+ row(k('browser.filter'), 'Filtrar arquivos (fuzzy)'),
1241
+ row(k('browser.toggleHidden'), 'Mostrar/ocultar arquivos ocultos'),
1242
+ row(k('browser.copyPath'), 'Copiar caminho selecionado (arquivo ou pasta)'),
1243
+ row(`${k('browser.createFile')} / ${k('browser.createFolder')}`, 'Novo arquivo (com extensão) / Nova pasta cross-OS'),
1244
+ row(`${k('browser.duplicateEntry')} / ${k('browser.renameEntry')} / ${k('browser.deleteEntry')}`, 'Duplicar / Renomear / Excluir (com confirmação)'),
1245
+ row(k('browser.openGitPanel'), 'Abrir PAINEL GIT / GITHUB (status, árvore, branches, PRs)'),
1031
1246
  '',
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)',
1247
+ ' PAINEL GIT / GITHUB',
1248
+ row(`1-4 / ${k('git.nextTab')}`, 'Alternar abas (Status/Parados · Árvore · Branches · GitHub)'),
1249
+ row(`${k('git.stageToggle')} · ${k('git.stageAll')} · ${k('git.commit')}`, 'Stage/Unstage · Stage All · Commit com mensagem'),
1250
+ row(`${k('git.pull')}/${k('git.push')}/${k('git.fetch')}/${k('git.createBranch')}`, `Pull · Push · Fetch · Nova branch (${k('git.quickPalette')} paleta)`),
1036
1251
  '',
1037
1252
  ' 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)',
1253
+ row(k('reader.toggleMode'), 'Alternar modo (Rendered↔Raw | Tree↔Pretty | Reader↔Source)'),
1254
+ row(k('reader.openFullscreen'), 'Abrir arquivo em novo terminal TELA CHEIA'),
1255
+ row(`${k('reader.jsonToggleNode')}`, `JSON Tree: alternar nó (${k('reader.jsonExpandAll')}=tudo, ${k('reader.jsonCollapseAll')}=recolher)`),
1256
+ row(`${k('reader.search')} · ${k('reader.searchNext')}/${k('reader.searchPrev')}`, 'Buscar texto no arquivo e saltar ocorrências'),
1257
+ row(k('reader.openEditor'), 'Abrir arquivo no EDITOR VIM NATIVO'),
1258
+ row(k('global.cycleTheme'), 'Alternar tema (Midnight · Parchment Light · Nord)'),
1259
+ row(k('reader.back'), 'Voltar ao navegador (ou sair)'),
1260
+ '',
1261
+ ' CUSTOMIZAÇÃO DE KEYBINDS (Pressione ' + kbKey + ' agora para editar!)',
1262
+ row(kbKey, 'Abrir PAINEL INTERATIVO DE EDIÇÃO DE BINDS'),
1263
+ row('~/.exploreiorc.json', 'Config base (rode "exploreio --init-config" para gerar)'),
1046
1264
  '',
1047
1265
  ' 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>',
1266
+ row('i/I/a/A/o/O · Esc', 'Entrar em INSERT · voltar para NORMAL'),
1267
+ row(':w · :wq · :q!', 'Salvar · Salvar e sair · Sair sem salvar · :<linha>'),
1052
1268
  ];
1053
1269
  const startRow = Math.max(1, Math.floor((height - (helpItems.length + 4)) / 2));
1054
1270
  const padLeft = ' '.repeat(Math.max(0, Math.floor((width - boxW) / 2)));
1055
1271
  const innerW = boxW - 2;
1056
1272
  const modalLines = [
1057
1273
  `${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}`),
1274
+ `${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}`,
1275
+ ...helpItems.map((item) => {
1276
+ const isHeader = item.startsWith(' NAVEGADOR') ||
1277
+ item.startsWith(' PAINEL') ||
1278
+ item.startsWith(' MODO') ||
1279
+ item.startsWith(' CUSTOMIZAÇÃO');
1280
+ return `${padLeft}${fg(theme.borderActive)}│${bg(theme.statusBg)}${fg(isHeader ? theme.accentAlt : theme.text)}${fitAnsi(item, innerW)}${RESET}${fg(theme.borderActive)}│${RESET}`;
1281
+ }),
1060
1282
  `${padLeft}${fg(theme.borderActive)}${BOLD}╰${'─'.repeat(innerW)}╯${RESET}`,
1061
1283
  ];
1062
1284
  modalLines.forEach((mLine, offset) => {
@@ -1387,19 +1609,23 @@ export class ExploreioApp {
1387
1609
  }
1388
1610
  return;
1389
1611
  }
1390
- if (ev.name === 'escape' || ev.char === 'q') {
1612
+ if (this.keybinds.matches('git.back', ev)) {
1391
1613
  this.view = 'browser';
1392
1614
  await this.reloadDirectory();
1393
1615
  this.draw();
1394
1616
  return;
1395
1617
  }
1396
- if (ev.char === 't') {
1618
+ if (this.keybinds.matches('global.cycleTheme', ev)) {
1397
1619
  this.themeName = nextTheme(this.themeName);
1398
1620
  this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
1399
1621
  this.draw();
1400
1622
  return;
1401
1623
  }
1402
- if (ev.char === '?' && this.gitSnapshot?.isGitRepo) {
1624
+ if (this.keybinds.matches('global.openKeybinds', ev) && !this.keybinds.matches('git.detailUp', ev)) {
1625
+ this.openKeybindsPanel('git');
1626
+ return;
1627
+ }
1628
+ if (this.keybinds.matches('git.quickPalette', ev) && this.gitSnapshot?.isGitRepo) {
1403
1629
  this.gitShowQuickPalette = true;
1404
1630
  this.gitQuickPaletteIndex = 0;
1405
1631
  this.draw();
@@ -1409,7 +1635,7 @@ export class ExploreioApp {
1409
1635
  this.draw();
1410
1636
  return;
1411
1637
  }
1412
- // Troca de abas (1..4 ou Tab / Shift+Tab)
1638
+ // Troca de abas (1..4 ou nextTab / prevTab)
1413
1639
  const tabOrder = ['status', 'graph', 'branches', 'github'];
1414
1640
  if (ev.char === '1' || ev.char === '2' || ev.char === '3' || ev.char === '4') {
1415
1641
  const nextTab = tabOrder[Number(ev.char) - 1] ?? 'status';
@@ -1423,9 +1649,10 @@ export class ExploreioApp {
1423
1649
  this.draw();
1424
1650
  return;
1425
1651
  }
1426
- if (ev.name === 'tab') {
1652
+ if (this.keybinds.matches('git.prevTab', ev) || this.keybinds.matches('git.nextTab', ev)) {
1427
1653
  const idx = tabOrder.indexOf(this.gitTab);
1428
- const nextIdx = ev.shift ? (idx - 1 + tabOrder.length) % tabOrder.length : (idx + 1) % tabOrder.length;
1654
+ const goPrev = this.keybinds.matches('git.prevTab', ev);
1655
+ const nextIdx = goPrev ? (idx - 1 + tabOrder.length) % tabOrder.length : (idx + 1) % tabOrder.length;
1429
1656
  this.gitTab = tabOrder[nextIdx] ?? 'status';
1430
1657
  this.gitSelectedIndex = 0;
1431
1658
  this.gitListScroll = 0;
@@ -1435,68 +1662,76 @@ export class ExploreioApp {
1435
1662
  return;
1436
1663
  }
1437
1664
  // Navegação na lista
1438
- if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
1665
+ if (this.keybinds.matches('git.moveUp', ev) || ev.name === 'wheel_up') {
1439
1666
  this.moveGitSelection(-1);
1440
1667
  await this.refreshGitDetail();
1441
1668
  this.draw();
1442
1669
  return;
1443
1670
  }
1444
- if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
1671
+ if (this.keybinds.matches('git.moveDown', ev) || ev.name === 'wheel_down') {
1445
1672
  this.moveGitSelection(1);
1446
1673
  await this.refreshGitDetail();
1447
1674
  this.draw();
1448
1675
  return;
1449
1676
  }
1450
1677
  // Rolagem do painel direito (diff / detalhes)
1451
- if (ev.char === 'J' || ev.name === 'pagedown') {
1678
+ if (this.keybinds.matches('git.detailDown', ev)) {
1452
1679
  this.gitDetailScroll = Math.min(Math.max(0, this.gitDetailLines.length - 5), this.gitDetailScroll + 8);
1453
1680
  this.draw();
1454
1681
  return;
1455
1682
  }
1456
- if (ev.char === 'K' || ev.name === 'pageup') {
1683
+ if (this.keybinds.matches('git.detailUp', ev)) {
1457
1684
  this.gitDetailScroll = Math.max(0, this.gitDetailScroll - 8);
1458
1685
  this.draw();
1459
1686
  return;
1460
1687
  }
1461
1688
  // Ações rápidas diretas
1462
- if (ev.char === 'r') {
1689
+ if (this.keybinds.matches('git.refresh', ev)) {
1463
1690
  await this.refreshGitPanelData(true);
1464
1691
  this.toastMessage = 'Painel Git/GitHub atualizado.';
1465
1692
  this.draw();
1466
1693
  return;
1467
1694
  }
1468
- if (ev.char === 'f') {
1695
+ if (this.keybinds.matches('git.fetch', ev)) {
1469
1696
  await this.triggerGitQuickAction('fetch');
1470
1697
  return;
1471
1698
  }
1472
- if (ev.char === 'p') {
1699
+ if (this.keybinds.matches('git.pull', ev)) {
1473
1700
  await this.triggerGitQuickAction('pull');
1474
1701
  return;
1475
1702
  }
1476
- if (ev.char === 'P') {
1703
+ if (this.keybinds.matches('git.push', ev)) {
1477
1704
  await this.triggerGitQuickAction('push');
1478
1705
  return;
1479
1706
  }
1480
- if (ev.char === 'c') {
1707
+ if (this.keybinds.matches('git.commit', ev)) {
1481
1708
  await this.triggerGitQuickAction('commit');
1482
1709
  return;
1483
1710
  }
1484
- if (ev.char === 'b') {
1711
+ if (this.keybinds.matches('git.createBranch', ev)) {
1485
1712
  await this.triggerGitQuickAction('create-branch');
1486
1713
  return;
1487
1714
  }
1488
- if (ev.char === 'S') {
1715
+ if (this.keybinds.matches('git.stageAll', ev)) {
1489
1716
  await this.triggerGitQuickAction('stage-all');
1490
1717
  return;
1491
1718
  }
1492
- if (ev.char === 'U') {
1719
+ if (this.keybinds.matches('git.unstageAll', ev)) {
1493
1720
  const res = await gitUnstageAll(this.gitSnapshot.repoRoot);
1494
1721
  this.toastMessage = res.ok ? 'Todas as alterações removidas do stage.' : (res.errorMessage ?? 'Erro no unstage.');
1495
1722
  await this.refreshGitPanelData(false);
1496
1723
  return;
1497
1724
  }
1725
+ if (this.keybinds.matches('git.stashPush', ev)) {
1726
+ await this.triggerGitQuickAction('stash-push');
1727
+ return;
1728
+ }
1729
+ if (this.keybinds.matches('git.stashPop', ev)) {
1730
+ await this.triggerGitQuickAction('stash-pop');
1731
+ return;
1732
+ }
1498
1733
  // Stage / Unstage individual na aba Status
1499
- if ((ev.char === 's' || ev.name === 'space') && this.gitTab === 'status') {
1734
+ if (this.keybinds.matches('git.stageToggle', ev) && this.gitTab === 'status') {
1500
1735
  const item = buildStatusListItems(this.gitSnapshot)[this.gitSelectedIndex];
1501
1736
  if (item?.kind === 'file') {
1502
1737
  const res = item.entry.section === 'staged'
@@ -1510,7 +1745,7 @@ export class ExploreioApp {
1510
1745
  return;
1511
1746
  }
1512
1747
  // Descartar alterações de um arquivo (com confirmação obrigatória)
1513
- if (ev.char === 'x' && this.gitTab === 'status') {
1748
+ if (this.keybinds.matches('git.discard', ev) && this.gitTab === 'status') {
1514
1749
  const item = buildStatusListItems(this.gitSnapshot)[this.gitSelectedIndex];
1515
1750
  if (item?.kind === 'file' && item.entry.section !== 'staged') {
1516
1751
  const entry = item.entry;
@@ -1524,12 +1759,12 @@ export class ExploreioApp {
1524
1759
  return;
1525
1760
  }
1526
1761
  // Copiar hash / path / branch / URL
1527
- if (ev.char === 'y') {
1762
+ if (this.keybinds.matches('git.copyItem', ev)) {
1528
1763
  await this.copyActiveGitItem();
1529
1764
  return;
1530
1765
  }
1531
1766
  // Enter contextual por aba
1532
- if (ev.name === 'enter') {
1767
+ if (this.keybinds.matches('git.openItem', ev)) {
1533
1768
  if (this.gitTab === 'branches') {
1534
1769
  const br = this.gitSnapshot.branches[this.gitSelectedIndex];
1535
1770
  if (br && !br.isCurrent) {
@@ -1704,5 +1939,189 @@ export class ExploreioApp {
1704
1939
  : `Falha ao copiar: ${stripUnsafeAnsi(res.error ?? 'clipboard indisponível')}`;
1705
1940
  this.draw();
1706
1941
  }
1942
+ // ==================== PAINEL DE EDIÇÃO DE KEYBINDS (SPEC-006) ====================
1943
+ openKeybindsPanel(returnTo) {
1944
+ this.keybindsReturnView = returnTo;
1945
+ this.view = 'keybinds';
1946
+ this.keybindsCaptureMode = null;
1947
+ this.toastMessage = '';
1948
+ this.clampKeybindsSelection();
1949
+ this.draw();
1950
+ }
1951
+ clampKeybindsSelection() {
1952
+ const items = getFilteredKeybindDefinitions(this.keybinds, this.keybindsTab, this.keybindsFilterQuery);
1953
+ const { height } = this.screen.getSize();
1954
+ const bodyHeight = Math.max(4, height - 3);
1955
+ if (items.length === 0) {
1956
+ this.keybindsSelectedIndex = 0;
1957
+ this.keybindsScroll = 0;
1958
+ return;
1959
+ }
1960
+ this.keybindsSelectedIndex = Math.max(0, Math.min(items.length - 1, this.keybindsSelectedIndex));
1961
+ if (this.keybindsSelectedIndex < this.keybindsScroll) {
1962
+ this.keybindsScroll = this.keybindsSelectedIndex;
1963
+ }
1964
+ else if (this.keybindsSelectedIndex >= this.keybindsScroll + bodyHeight) {
1965
+ this.keybindsScroll = this.keybindsSelectedIndex - bodyHeight + 1;
1966
+ }
1967
+ }
1968
+ saveKeybindsNow() {
1969
+ const res = saveKeybindsConfig(this.keybinds, this.configPath, this.themeName);
1970
+ if (res.ok) {
1971
+ this.keybindsDirty = false;
1972
+ this.toastMessage = `Keybinds salvos em ${stripUnsafeAnsi(this.configPath)}`;
1973
+ }
1974
+ else {
1975
+ this.toastMessage = `Erro ao salvar keybinds: ${stripUnsafeAnsi(res.error ?? 'falha de escrita')}`;
1976
+ }
1977
+ }
1978
+ async handleKeybindsKey(ev) {
1979
+ this.toastMessage = '';
1980
+ const items = getFilteredKeybindDefinitions(this.keybinds, this.keybindsTab, this.keybindsFilterQuery);
1981
+ const selected = items[this.keybindsSelectedIndex];
1982
+ // Modo de captura de tecla ao vivo
1983
+ if (this.keybindsCaptureMode) {
1984
+ if (ev.name === 'escape') {
1985
+ this.keybindsCaptureMode = null;
1986
+ this.toastMessage = 'Captura de tecla cancelada.';
1987
+ this.draw();
1988
+ return;
1989
+ }
1990
+ const captured = formatKeyEvent(ev);
1991
+ const mode = this.keybindsCaptureMode;
1992
+ this.keybindsCaptureMode = null;
1993
+ if (!captured || !selected) {
1994
+ this.toastMessage = 'Tecla não suportada para bind.';
1995
+ this.draw();
1996
+ return;
1997
+ }
1998
+ const changed = mode === 'replace'
1999
+ ? this.keybinds.replacePrimaryKey(selected.id, captured)
2000
+ : this.keybinds.addKey(selected.id, captured);
2001
+ if (changed) {
2002
+ this.keybindsDirty = true;
2003
+ const conflicts = this.keybinds.getConflictsForAction(selected.id);
2004
+ const label = formatKeyForDisplay(captured);
2005
+ this.toastMessage =
2006
+ conflicts.length > 0
2007
+ ? `Tecla [${label}] aplicada com ⚠ conflito em ${selected.context} (pressione s para salvar).`
2008
+ : `Tecla [${label}] aplicada em "${selected.label}" (pressione s para salvar).`;
2009
+ }
2010
+ else {
2011
+ this.toastMessage = `Tecla [${formatKeyForDisplay(captured)}] já estava atribuída.`;
2012
+ }
2013
+ this.draw();
2014
+ return;
2015
+ }
2016
+ if (ev.name === 'escape' || ev.char === 'q') {
2017
+ if (this.keybindsDirty) {
2018
+ this.saveKeybindsNow();
2019
+ }
2020
+ this.view = this.keybindsReturnView;
2021
+ this.draw();
2022
+ return;
2023
+ }
2024
+ if (ev.char === 't') {
2025
+ this.themeName = nextTheme(this.themeName);
2026
+ this.toastMessage = `Tema ativo: ${getTheme(this.themeName).label}`;
2027
+ this.draw();
2028
+ return;
2029
+ }
2030
+ // Troca de aba por número (1..5) ou Tab / Shift+Tab
2031
+ if (ev.char && ev.char >= '1' && ev.char <= '5') {
2032
+ const tab = KEYBINDS_TABS[Number(ev.char) - 1];
2033
+ if (tab) {
2034
+ this.keybindsTab = tab.id;
2035
+ this.keybindsSelectedIndex = 0;
2036
+ this.keybindsScroll = 0;
2037
+ this.clampKeybindsSelection();
2038
+ }
2039
+ this.draw();
2040
+ return;
2041
+ }
2042
+ if (ev.name === 'tab') {
2043
+ const idx = KEYBINDS_TABS.findIndex((t) => t.id === this.keybindsTab);
2044
+ const nextIdx = ev.shift
2045
+ ? (idx - 1 + KEYBINDS_TABS.length) % KEYBINDS_TABS.length
2046
+ : (idx + 1) % KEYBINDS_TABS.length;
2047
+ this.keybindsTab = KEYBINDS_TABS[nextIdx]?.id ?? 'all';
2048
+ this.keybindsSelectedIndex = 0;
2049
+ this.keybindsScroll = 0;
2050
+ this.clampKeybindsSelection();
2051
+ this.draw();
2052
+ return;
2053
+ }
2054
+ if (ev.char === '/') {
2055
+ this.promptKind = 'keybinds-filter';
2056
+ this.promptInput = this.keybindsFilterQuery;
2057
+ this.draw();
2058
+ return;
2059
+ }
2060
+ if (ev.char === 's') {
2061
+ this.saveKeybindsNow();
2062
+ this.draw();
2063
+ return;
2064
+ }
2065
+ if (ev.char === 'R') {
2066
+ this.promptKind = 'keybinds-reset-confirm';
2067
+ this.promptInput = '';
2068
+ this.draw();
2069
+ return;
2070
+ }
2071
+ // Navegação vertical
2072
+ if (ev.name === 'up' || ev.char === 'k' || ev.name === 'wheel_up') {
2073
+ this.keybindsSelectedIndex = Math.max(0, this.keybindsSelectedIndex - 1);
2074
+ this.clampKeybindsSelection();
2075
+ this.draw();
2076
+ return;
2077
+ }
2078
+ if (ev.name === 'down' || ev.char === 'j' || ev.name === 'wheel_down') {
2079
+ this.keybindsSelectedIndex = Math.min(Math.max(0, items.length - 1), this.keybindsSelectedIndex + 1);
2080
+ this.clampKeybindsSelection();
2081
+ this.draw();
2082
+ return;
2083
+ }
2084
+ if (ev.name === 'pageup') {
2085
+ this.keybindsSelectedIndex = Math.max(0, this.keybindsSelectedIndex - 10);
2086
+ this.clampKeybindsSelection();
2087
+ this.draw();
2088
+ return;
2089
+ }
2090
+ if (ev.name === 'pagedown') {
2091
+ this.keybindsSelectedIndex = Math.min(Math.max(0, items.length - 1), this.keybindsSelectedIndex + 10);
2092
+ this.clampKeybindsSelection();
2093
+ this.draw();
2094
+ return;
2095
+ }
2096
+ if (!selected)
2097
+ return;
2098
+ if (ev.name === 'enter') {
2099
+ this.keybindsCaptureMode = 'replace';
2100
+ this.draw();
2101
+ return;
2102
+ }
2103
+ if (ev.char === '+' || ev.char === 'a') {
2104
+ this.keybindsCaptureMode = 'add';
2105
+ this.draw();
2106
+ return;
2107
+ }
2108
+ if (ev.char === 'd' || ev.name === 'backspace') {
2109
+ if (this.keybinds.removeLastKey(selected.id)) {
2110
+ this.keybindsDirty = true;
2111
+ this.toastMessage = `Última tecla removida de "${selected.label}" (pressione s para salvar).`;
2112
+ }
2113
+ else {
2114
+ this.toastMessage = 'Cada ação precisa manter pelo menos 1 tecla ativa.';
2115
+ }
2116
+ this.draw();
2117
+ return;
2118
+ }
2119
+ if (ev.char === 'r') {
2120
+ this.keybinds.resetAction(selected.id);
2121
+ this.keybindsDirty = true;
2122
+ this.toastMessage = `Ação "${selected.label}" restaurada para o padrão.`;
2123
+ this.draw();
2124
+ }
2125
+ }
1707
2126
  }
1708
2127
  //# sourceMappingURL=app.js.map