@corbat-tech/coco 2.8.2 → 2.9.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/cli/index.js +1172 -1007
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +88 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import JSON5 from 'json5';
|
|
|
25
25
|
import 'events';
|
|
26
26
|
import 'minimatch';
|
|
27
27
|
import { simpleGit } from 'simple-git';
|
|
28
|
+
import { diffWords } from 'diff';
|
|
28
29
|
import hljs from 'highlight.js/lib/core';
|
|
29
30
|
import bash from 'highlight.js/lib/languages/bash';
|
|
30
31
|
import css from 'highlight.js/lib/languages/css';
|
|
@@ -18915,6 +18916,10 @@ function highlightLine(line, lang) {
|
|
|
18915
18916
|
}
|
|
18916
18917
|
|
|
18917
18918
|
// src/cli/repl/output/diff-renderer.ts
|
|
18919
|
+
var bgDeleteLine = chalk3.bgRgb(80, 20, 20);
|
|
18920
|
+
var bgAddLine = chalk3.bgRgb(20, 60, 20);
|
|
18921
|
+
var bgDeleteWord = chalk3.bgRgb(160, 40, 40);
|
|
18922
|
+
var bgAddWord = chalk3.bgRgb(40, 120, 40);
|
|
18918
18923
|
function parseDiff(raw) {
|
|
18919
18924
|
const files = [];
|
|
18920
18925
|
const lines = raw.split("\n");
|
|
@@ -19039,6 +19044,46 @@ function parseHunk(lines, start) {
|
|
|
19039
19044
|
nextIndex: i
|
|
19040
19045
|
};
|
|
19041
19046
|
}
|
|
19047
|
+
function pairAdjacentLines(lines) {
|
|
19048
|
+
const pairs = [];
|
|
19049
|
+
let i = 0;
|
|
19050
|
+
while (i < lines.length) {
|
|
19051
|
+
const deleteStart = i;
|
|
19052
|
+
while (i < lines.length && lines[i].type === "delete") i++;
|
|
19053
|
+
const deleteEnd = i;
|
|
19054
|
+
const addStart = i;
|
|
19055
|
+
while (i < lines.length && lines[i].type === "add") i++;
|
|
19056
|
+
const addEnd = i;
|
|
19057
|
+
const deleteCount = deleteEnd - deleteStart;
|
|
19058
|
+
const addCount = addEnd - addStart;
|
|
19059
|
+
if (deleteCount > 0 && addCount > 0) {
|
|
19060
|
+
const pairCount = Math.min(deleteCount, addCount);
|
|
19061
|
+
for (let j = 0; j < pairCount; j++) {
|
|
19062
|
+
pairs.push({ deleteIdx: deleteStart + j, addIdx: addStart + j });
|
|
19063
|
+
}
|
|
19064
|
+
}
|
|
19065
|
+
if (i === deleteEnd && i === addEnd) {
|
|
19066
|
+
i++;
|
|
19067
|
+
}
|
|
19068
|
+
}
|
|
19069
|
+
return pairs;
|
|
19070
|
+
}
|
|
19071
|
+
function highlightWordChanges(deletedContent, addedContent) {
|
|
19072
|
+
const changes = diffWords(deletedContent, addedContent);
|
|
19073
|
+
let styledDelete = "";
|
|
19074
|
+
let styledAdd = "";
|
|
19075
|
+
for (const change of changes) {
|
|
19076
|
+
if (change.added) {
|
|
19077
|
+
styledAdd += bgAddWord(change.value);
|
|
19078
|
+
} else if (change.removed) {
|
|
19079
|
+
styledDelete += bgDeleteWord(change.value);
|
|
19080
|
+
} else {
|
|
19081
|
+
styledDelete += bgDeleteLine(change.value);
|
|
19082
|
+
styledAdd += bgAddLine(change.value);
|
|
19083
|
+
}
|
|
19084
|
+
}
|
|
19085
|
+
return { styledDelete, styledAdd };
|
|
19086
|
+
}
|
|
19042
19087
|
var getTerminalWidth = () => process.stdout.columns || 80;
|
|
19043
19088
|
function stripAnsi(str) {
|
|
19044
19089
|
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
@@ -19107,32 +19152,64 @@ function renderFileBlock(file, opts) {
|
|
|
19107
19152
|
) + hunkLabel
|
|
19108
19153
|
);
|
|
19109
19154
|
}
|
|
19110
|
-
|
|
19155
|
+
const pairs = pairAdjacentLines(hunk.lines);
|
|
19156
|
+
const pairedDeleteIndices = new Set(pairs.map((p4) => p4.deleteIdx));
|
|
19157
|
+
const pairedAddIndices = new Set(pairs.map((p4) => p4.addIdx));
|
|
19158
|
+
const pairByAdd = new Map(pairs.map((p4) => [p4.addIdx, p4.deleteIdx]));
|
|
19159
|
+
const wordHighlights = /* @__PURE__ */ new Map();
|
|
19160
|
+
for (const pair of pairs) {
|
|
19161
|
+
const delLine = hunk.lines[pair.deleteIdx];
|
|
19162
|
+
const addLine = hunk.lines[pair.addIdx];
|
|
19163
|
+
wordHighlights.set(pair.deleteIdx, highlightWordChanges(delLine.content, addLine.content));
|
|
19164
|
+
}
|
|
19165
|
+
for (let li = 0; li < hunk.lines.length; li++) {
|
|
19166
|
+
const line = hunk.lines[li];
|
|
19111
19167
|
const lineNo = formatLineNo(line, showLineNumbers);
|
|
19112
19168
|
const prefix = line.type === "add" ? "+" : line.type === "delete" ? "-" : " ";
|
|
19113
|
-
let content = line.content;
|
|
19114
|
-
if (line.type !== "delete" && lang) {
|
|
19115
|
-
content = highlightLine(content, lang);
|
|
19116
|
-
}
|
|
19117
|
-
const lineStr = `${lineNo}${prefix} ${content}`;
|
|
19118
|
-
const plainLen = stripAnsi(lineStr).length;
|
|
19119
|
-
const pad = Math.max(0, contentWidth - plainLen);
|
|
19120
19169
|
if (line.type === "add") {
|
|
19170
|
+
const isPaired = pairedAddIndices.has(li);
|
|
19171
|
+
let content;
|
|
19172
|
+
if (isPaired) {
|
|
19173
|
+
const delIdx = pairByAdd.get(li);
|
|
19174
|
+
content = wordHighlights.get(delIdx).styledAdd;
|
|
19175
|
+
} else {
|
|
19176
|
+
content = line.content;
|
|
19177
|
+
}
|
|
19178
|
+
const innerText = `${lineNo}${prefix} ${content}`;
|
|
19179
|
+
const plainLen = stripAnsi(innerText).length + 1;
|
|
19180
|
+
const pad = Math.max(0, contentWidth - plainLen);
|
|
19121
19181
|
console.log(
|
|
19122
|
-
chalk3.magenta("\u2502") +
|
|
19182
|
+
chalk3.magenta("\u2502") + bgAddLine(` ${innerText}` + " ".repeat(pad + 2)) + chalk3.magenta("\u2502")
|
|
19123
19183
|
);
|
|
19124
19184
|
} else if (line.type === "delete") {
|
|
19185
|
+
const isPaired = pairedDeleteIndices.has(li);
|
|
19186
|
+
let content;
|
|
19187
|
+
if (isPaired) {
|
|
19188
|
+
content = wordHighlights.get(li).styledDelete;
|
|
19189
|
+
} else {
|
|
19190
|
+
content = line.content;
|
|
19191
|
+
}
|
|
19192
|
+
const innerText = `${lineNo}${prefix} ${content}`;
|
|
19193
|
+
const plainLen = stripAnsi(innerText).length + 1;
|
|
19194
|
+
const pad = Math.max(0, contentWidth - plainLen);
|
|
19125
19195
|
console.log(
|
|
19126
|
-
chalk3.magenta("\u2502") +
|
|
19196
|
+
chalk3.magenta("\u2502") + bgDeleteLine(` ${innerText}` + " ".repeat(pad + 2)) + chalk3.magenta("\u2502")
|
|
19127
19197
|
);
|
|
19128
19198
|
} else {
|
|
19199
|
+
let content = line.content;
|
|
19200
|
+
if (lang) {
|
|
19201
|
+
content = highlightLine(content, lang);
|
|
19202
|
+
}
|
|
19203
|
+
const lineStr = `${lineNo}${prefix} ${content}`;
|
|
19204
|
+
const plainLen = stripAnsi(lineStr).length;
|
|
19205
|
+
const pad = Math.max(0, contentWidth - plainLen);
|
|
19129
19206
|
console.log(
|
|
19130
19207
|
chalk3.magenta("\u2502") + chalk3.dim(` ${lineStr}`) + " ".repeat(pad) + " " + chalk3.magenta("\u2502")
|
|
19131
19208
|
);
|
|
19132
19209
|
}
|
|
19133
19210
|
}
|
|
19134
19211
|
}
|
|
19135
|
-
console.log(chalk3.magenta("\u2570" + "\u2500".repeat(maxWidth - 2) + "\u256F"));
|
|
19212
|
+
console.log(chalk3.magenta("\u2570" + "\u2500".repeat(Math.max(0, maxWidth - 2)) + "\u256F"));
|
|
19136
19213
|
}
|
|
19137
19214
|
function formatLineNo(line, show) {
|
|
19138
19215
|
if (!show) return "";
|