Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
689a8bd
Add interactive TUI mode with file tree side panel
armanarutiunov Feb 11, 2026
4d11f97
Add per-file addition/deletion line counts
armanarutiunov Feb 11, 2026
c434705
Add dir, border-focused, additions, deletions theme colors
armanarutiunov Feb 11, 2026
0575e48
Rewrite file tree as nested expandable tree with file icons and +N -M…
armanarutiunov Feb 11, 2026
92ae324
Add focus border indicator, ctrl+d/u half-page scroll, update sync fo…
armanarutiunov Feb 11, 2026
53d1685
Match folder color to file name header, darken tree background
armanarutiunov Feb 11, 2026
e5aed4e
Add git staging status detection with green/orange file coloring
armanarutiunov Feb 11, 2026
2cc4e2a
Add staged/partial-staged/file-selected theme colors, fix span ordering
armanarutiunov Feb 11, 2026
4096f5d
Use background-only selection for files, keep inverse for dirs
armanarutiunov Feb 11, 2026
c06368d
Fix dead ternary in FileTreePanel, use execFileSync in gitStatus
armanarutiunov Feb 12, 2026
9a533ca
Deduplicate side-by-side diff parser into single iterSideBySideDiffEv…
armanarutiunov Feb 12, 2026
6eb9fa7
Add Windows fallback for interactive mode, deduplicate TREE_WIDTH/BOR…
armanarutiunov Feb 12, 2026
df4fa57
Fix stale rendering artifacts with ERASE_TO_EOL and screen clear
armanarutiunov Feb 12, 2026
4086e02
Add 'e' key tree toggle and dynamic diff re-render on terminal resize
armanarutiunov Feb 12, 2026
a608033
Fix ttyFd leak, remove dead params, restore comments, export helpers
armanarutiunov Feb 12, 2026
211ffe4
Add unit tests for TUI helpers
armanarutiunov Feb 12, 2026
0be5f85
Make tree width configurable via split-diffs.tree-width
armanarutiunov Feb 12, 2026
6f29eee
Add 'f' key to toggle flat/folder file tree mode
armanarutiunov Mar 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix ttyFd leak, remove dead params, restore comments, export helpers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
armanarutiunov and claude committed Feb 12, 2026
commit a60803361f82b0b026da2daa0f701668f60fbd84
7 changes: 7 additions & 0 deletions src/iterSideBySideDiffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export async function* iterSideBySideDiffEvents(
fileNameB = line.slice('+++ b/'.length);
} else if (line.startsWith('--- ')) {
fileNameA = line.slice('--- '.length);
// /dev/null indicates file creation/deletion
// per git diff-format spec
if (fileNameA === '/dev/null') {
fileNameA = '';
}
Expand Down Expand Up @@ -282,6 +284,10 @@ export async function* iterSideBySideDiffEvents(
break;
}
case 'combined-diff-hunk-body': {
// Combined diffs have N+1 columns: first N show changes
// relative to each parent, last shows the merge result.
// Prefix chars: + (added), - (removed), space (unchanged).
// See: https://git-scm.com/docs/git-diff#_combined_diff_format
const linePrefix = line.slice(0, hunkParts.length - 1);
const lineSuffix = line.slice(hunkParts.length - 1);
const isLineAdded = linePrefix.includes('+');
Expand All @@ -307,6 +313,7 @@ export async function* iterSideBySideDiffEvents(
}
i++;
}
// Final part: the merge result (current commit state)
if (isLineRemoved) {
hunkParts[i].lines.push('-' + lineSuffix);
fileDeletions++;
Expand Down
18 changes: 8 additions & 10 deletions src/tui/FileTreePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type FileNode = {
type TreeNode = DirNode | FileNode;

type VisibleNode =
| { type: 'dir'; node: DirNode; depth: number }
| { type: 'file'; node: FileNode; fileIndex: number; depth: number };
| { type: 'dir'; node: DirNode }
| { type: 'file'; node: FileNode; fileIndex: number };

function buildTree(files: DiffFile[]): TreeNode[] {
export function buildTree(files: DiffFile[]): TreeNode[] {
const root: TreeNode[] = [];

for (let i = 0; i < files.length; i++) {
Expand Down Expand Up @@ -72,20 +72,19 @@ function buildTree(files: DiffFile[]): TreeNode[] {
return root;
}

function flattenVisible(nodes: TreeNode[], depth: number = 0): VisibleNode[] {
export function flattenVisible(nodes: TreeNode[]): VisibleNode[] {
const result: VisibleNode[] = [];
for (const node of nodes) {
if (node.type === 'dir') {
result.push({ type: 'dir', node, depth });
result.push({ type: 'dir', node });
if (node.expanded) {
result.push(...flattenVisible(node.children, depth + 1));
result.push(...flattenVisible(node.children));
}
} else {
result.push({
type: 'file',
node,
fileIndex: node.fileIndex,
depth,
});
}
}
Expand Down Expand Up @@ -281,8 +280,7 @@ export class FileTreePanel {
render(
screen: Screen,
startCol: number,
startRow: number,
focused: boolean
startRow: number
): void {
const {
FILE_TREE_COLOR,
Expand Down Expand Up @@ -314,7 +312,7 @@ export class FileTreePanel {

const vn = this.visibleNodes[visIdx];
const isSelected = visIdx === this.selectedIndex;
const indent = ' '.repeat(vn.depth);
const indent = ' '.repeat(vn.node.depth);

if (vn.type === 'dir') {
const icon = vn.node.expanded ? FOLDER_OPEN : FOLDER_CLOSED;
Expand Down
9 changes: 7 additions & 2 deletions src/tui/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ export type KeyHandler = (key: string, ctrl: boolean) => void;

export class InputHandler {
private ttyStream: tty.ReadStream | null = null;
private ttyFd: number = -1;
private handler: KeyHandler;

constructor(handler: KeyHandler) {
this.handler = handler;
}

start(): void {
const fd = fs.openSync('/dev/tty', 'r');
this.ttyStream = new tty.ReadStream(fd);
this.ttyFd = fs.openSync('/dev/tty', 'r');
this.ttyStream = new tty.ReadStream(this.ttyFd);
this.ttyStream.setEncoding('utf-8');
this.ttyStream.setRawMode(true);

Expand All @@ -36,5 +37,9 @@ export class InputHandler {
this.ttyStream.destroy();
this.ttyStream = null;
}
if (this.ttyFd >= 0) {
try { fs.closeSync(this.ttyFd); } catch {}
this.ttyFd = -1;
}
}
}
2 changes: 1 addition & 1 deletion src/tui/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function syncDiffToTree(
/**
* Binary search: find the last boundary <= topLine.
*/
function binarySearchBoundary(
export function binarySearchBoundary(
boundaries: number[],
topLine: number
): number {
Expand Down