mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
tui: improve diff display in session revert view
- Parse diff using diff library parsePatch function - Show changed files with addition/removal counts - Strip a/b prefixes from file paths - Use theme colors for additions (green) and deletions (red) - Only show counts when > 0 - Add top margin to file list
This commit is contained in:
parent
7844ab9855
commit
5d57607801
1 changed files with 26 additions and 14 deletions
|
|
@ -174,13 +174,17 @@ export function Session() {
|
|||
if (!diffText) return []
|
||||
|
||||
const patches = parsePatch(diffText)
|
||||
return patches.map(patch => ({
|
||||
filename: patch.oldFileName || patch.newFileName || 'unknown',
|
||||
additions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('+')).length, 0),
|
||||
deletions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('-')).length, 0)
|
||||
}))
|
||||
return patches.map(patch => {
|
||||
const filename = patch.newFileName || patch.oldFileName || 'unknown'
|
||||
const cleanFilename = filename.replace(/^[ab]\//, '')
|
||||
return {
|
||||
filename: cleanFilename,
|
||||
additions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('+')).length, 0),
|
||||
deletions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('-')).length, 0)
|
||||
}
|
||||
})
|
||||
})()
|
||||
|
||||
return {
|
||||
|
|
@ -221,13 +225,21 @@ export function Session() {
|
|||
<span style={{ fg: Theme.text }}>{keybind.print("messages_redo")}</span> or /redo to restore
|
||||
</text>
|
||||
<Show when={revert()!.diffFiles?.length}>
|
||||
<For each={revert()!.diffFiles}>
|
||||
{(file) => (
|
||||
<text fg={Theme.textMuted}>
|
||||
{file.filename}: +{file.additions} -{file.deletions}
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
<box marginTop={1}>
|
||||
<For each={revert()!.diffFiles}>
|
||||
{(file) => (
|
||||
<text>
|
||||
{file.filename}
|
||||
<Show when={file.additions > 0}>
|
||||
<span style={{ fg: Theme.diffAdded }}> +{file.additions}</span>
|
||||
</Show>
|
||||
<Show when={file.deletions > 0}>
|
||||
<span style={{ fg: Theme.diffRemoved }}> -{file.deletions}</span>
|
||||
</Show>
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
</box>
|
||||
</Show>
|
||||
</box>
|
||||
</box>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue