This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-09 22:15:10 -05:00
1 parent 32eab0c1dd
commit 867c0eadad
6 files changed
+128 -41

No files matched your search

@@ -1231,10 +1231,15 @@
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
use:tooltip={gitStatusTooltip(fileGitStatus, entry)}
>
<span class="text-green-600 dark:text-green-400"
>+{fileGitStatus.additions ?? 0}</span
>
<span class="text-red-500 dark:text-red-400">-{fileGitStatus.deletions ?? 0}</span>
{#if fileGitStatus.binary}
<span class={entryGitDecoration.badgeColor}>{entryGitDecoration.char}</span>
{:else}
<span class="text-green-600 dark:text-green-400"
>+{fileGitStatus.additions ?? 0}</span
>
<span class="text-red-500 dark:text-red-400">-{fileGitStatus.deletions ?? 0}</span
>
{/if}
</span>
{/if}
{#if entry.type !== 'directory' && entry.size !== null}
@@ -1026,6 +1026,17 @@
return `${(bytes / 1048576).toFixed(1)} MB`;
}
function gitStatusChar(status: string): string {
const chars: Record<string, string> = {
added: 'A',
untracked: 'U',
modified: 'M',
deleted: 'D',
renamed: 'R'
};
return chars[status] ?? '?';
}
onDestroy(() => {
destroyEditor();
revokeBinaryUrl();
@@ -1041,8 +1052,12 @@
<span class="file-name scrollbar-none">{fileData.name}</span>
{#if currentFileStatus}
<span class="file-git-stats">
<span class="file-git-additions">+{currentFileStatus.additions ?? 0}</span>
<span class="file-git-deletions">-{currentFileStatus.deletions ?? 0}</span>
{#if currentFileStatus.binary}
<span class="file-git-status">{gitStatusChar(currentFileStatus.status)}</span>
{:else}
<span class="file-git-additions">+{currentFileStatus.additions ?? 0}</span>
<span class="file-git-deletions">-{currentFileStatus.deletions ?? 0}</span>
{/if}
</span>
{/if}
</span>
@@ -1325,6 +1340,10 @@
color: #ef4444;
}
.file-git-status {
color: var(--color-gray-500);
}
:global(.dark) .file-git-additions {
color: #4ade80;
}
+40 -9
View File
@@ -44,6 +44,7 @@
unstaged?: boolean;
staged_status?: string;
unstaged_status?: string;
binary?: boolean;
additions?: number;
deletions?: number;
};
@@ -673,6 +674,25 @@
return `${Math.floor(s / 86400)}d`;
}
function statusChar(status: string): { char: string; color: string } {
switch (status) {
case 'added':
return { char: 'A', color: 'text-green-500' };
case 'untracked':
return { char: 'U', color: 'text-green-500' };
case 'modified':
return { char: 'M', color: 'text-amber-500' };
case 'deleted':
return { char: 'D', color: 'text-red-400' };
case 'renamed':
return { char: 'R', color: 'text-blue-400' };
case 'conflict':
return { char: '!', color: 'text-orange-500' };
default:
return { char: '?', color: 'text-gray-400' };
}
}
const syncAction = $derived.by(() => {
if (!gitStatus) return { label: $t('git.fetch'), icon: 'refresh', action: doFetch };
if (gitStatus.behind > 0)
@@ -799,9 +819,11 @@
{#if totalChanges > 0}<span
class="mx-1.5 block min-w-0 max-w-20 shrink truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
>{$t('git.changedCount', { count: totalChanges })}</span
><span class="mx-1.5 flex shrink-0 items-center gap-1 text-[0.625rem] font-mono"
><span class="text-green-600 dark:text-green-400">+{totalAdditions}</span>
<span class="text-red-500 dark:text-red-400">-{totalDeletions}</span></span
>{#if totalAdditions || totalDeletions}<span
class="mx-1.5 flex shrink-0 items-center gap-1 text-[0.625rem] font-mono"
><span class="text-green-600 dark:text-green-400">+{totalAdditions}</span>
<span class="text-red-500 dark:text-red-400">-{totalDeletions}</span></span
>{/if}
>{/if}
{#if actionMsg}<span
class="ml-auto min-w-0 max-w-32 truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
@@ -1235,6 +1257,7 @@
<div class="min-w-0 flex-1 overflow-x-hidden overflow-y-auto">
{#each gitStatus?.files ?? [] as file (file.path)}
{@const fp = fPath(file.path)}
{@const sc = statusChar(file.status)}
<button
class="group flex min-w-0 items-center gap-1.5 w-full h-7 px-2.5 text-left transition-colors duration-75
{selectedFile === file.path
@@ -1273,12 +1296,20 @@
}}>{fp.name}</span
>
</span>
<span
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
>
<span class="text-green-600 dark:text-green-400">+{file.additions ?? 0}</span>
<span class="text-red-500 dark:text-red-400">-{file.deletions ?? 0}</span>
</span>
{#if file.binary}
<span class="shrink-0 text-[0.625rem] font-mono font-bold {sc.color}"
>{sc.char}</span
>
{:else}
<span
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
>
<span class="text-green-600 dark:text-green-400"
>+{file.additions ?? 0}</span
>
<span class="text-red-500 dark:text-red-400">-{file.deletions ?? 0}</span>
</span>
{/if}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<span
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
+44 -20
View File
@@ -17,6 +17,7 @@
path: string;
status: string;
staged: boolean;
binary: boolean;
diffFiles: DiffFile[];
additions: number;
deletions: number;
@@ -98,6 +99,7 @@
path: file.path,
status: file.status,
staged: file.staged,
binary: file.binary ?? false,
diffFiles,
additions: counts.additions,
deletions: counts.deletions,
@@ -150,6 +152,17 @@
if (slash < 0) return { dir: '', name: path };
return { dir: path.slice(0, slash + 1), name: path.slice(slash + 1) };
}
function statusChar(status: string): string {
const chars: Record<string, string> = {
added: 'A',
untracked: 'U',
modified: 'M',
deleted: 'D',
renamed: 'R'
};
return chars[status] ?? '?';
}
</script>
<div
@@ -201,12 +214,14 @@
<span class="ml-1 font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
>{$t('git.changedCount', { count: totalChanges })}</span
>
<span class="ml-2 font-mono text-[0.625rem] text-green-600 dark:text-green-400"
>+{totalAdditions}</span
>
<span class="font-mono text-[0.625rem] text-red-500 dark:text-red-400"
>-{totalDeletions}</span
>
{#if totalAdditions || totalDeletions}
<span class="ml-2 font-mono text-[0.625rem] text-green-600 dark:text-green-400"
>+{totalAdditions}</span
>
<span class="font-mono text-[0.625rem] text-red-500 dark:text-red-400"
>-{totalDeletions}</span
>
{/if}
{/if}
</div>
@@ -252,12 +267,14 @@
<span class="ml-auto text-[0.6875rem] text-gray-400 dark:text-gray-600"
>{$t('git.change', { count: totalChanges })}</span
>
<span class="ml-2 font-mono text-[0.6875rem] text-green-600 dark:text-green-400"
>+{totalAdditions}</span
>
<span class="font-mono text-[0.6875rem] text-red-500 dark:text-red-400"
>-{totalDeletions}</span
>
{#if totalAdditions || totalDeletions}
<span class="ml-2 font-mono text-[0.6875rem] text-green-600 dark:text-green-400"
>+{totalAdditions}</span
>
<span class="font-mono text-[0.6875rem] text-red-500 dark:text-red-400"
>-{totalDeletions}</span
>
{/if}
</div>
{/if}
@@ -312,14 +329,21 @@
>
{/if}
</div>
<span
class="shrink-0 font-mono text-[0.6875rem] font-medium text-green-600 dark:text-green-400"
>+{file.additions}</span
>
<span
class="shrink-0 font-mono text-[0.6875rem] font-medium text-red-500 dark:text-red-400"
>-{file.deletions}</span
>
{#if file.binary}
<span
class="shrink-0 font-mono text-[0.6875rem] font-medium text-gray-500 dark:text-gray-400"
>{statusChar(file.status)}</span
>
{:else}
<span
class="shrink-0 font-mono text-[0.6875rem] font-medium text-green-600 dark:text-green-400"
>+{file.additions}</span
>
<span
class="shrink-0 font-mono text-[0.6875rem] font-medium text-red-500 dark:text-red-400"
>-{file.deletions}</span
>
{/if}
<span
class="shrink-0 rounded px-1.5 py-0.5 text-[0.625rem] font-medium text-rose-500 bg-rose-50 dark:bg-rose-500/10 dark:text-rose-300"
@@ -17,6 +17,7 @@ export interface GitFile {
unstaged?: boolean;
staged_status?: string;
unstaged_status?: string;
binary?: boolean;
additions?: number;
deletions?: number;
}
+13 -6
View File
@@ -105,7 +105,10 @@ async def status(root: str) -> dict[str, Any]:
continue
added, deleted, path = parts[0], parts[1], parts[2]
entry = files_by_path.get(path)
if not entry or added == "-" or deleted == "-":
if not entry:
continue
if added == "-" or deleted == "-":
entry["binary"] = True
continue
entry["additions"] = entry.get("additions", 0) + int(added)
entry["deletions"] = entry.get("deletions", 0) + int(deleted)
@@ -142,8 +145,12 @@ async def status(root: str) -> dict[str, Any]:
path = line[2:]
add_file(path, "untracked", unstaged=True)
entry = files_by_path[path]
entry["additions"] = _count_text_lines(os.path.join(root, path))
entry["deletions"] = 0
line_count = _count_text_lines(os.path.join(root, path))
if line_count is None:
entry["binary"] = True
else:
entry["additions"] = line_count
entry["deletions"] = 0
elif line.startswith("u "):
# Unmerged
parts = line.split(" ", 10)
@@ -184,14 +191,14 @@ def _status_char(c: str) -> str:
}.get(c, c)
def _count_text_lines(path: str) -> int:
def _count_text_lines(path: str) -> int | None:
try:
with open(path, "rb") as f:
data = f.read()
except OSError:
return 0
return None
if b"\0" in data:
return 0
return None
if not data:
return 0
return data.count(b"\n") + (0 if data.endswith(b"\n") else 1)