@heyhuynhgiabuu/pi-diff 0.2.1 → 0.2.2
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/README.md +2 -2
- package/package.json +1 -1
- package/src/index.ts +27 -18
package/README.md
CHANGED
|
@@ -126,10 +126,10 @@ Override individual diff colors in `.pi/settings.json` using hex `#RRGGBB` value
|
|
|
126
126
|
|
|
127
127
|
### Auto-Derive (Default Behavior)
|
|
128
128
|
|
|
129
|
-
When no `diffTheme` or `diffColors` is set, pi-diff **automatically derives** background colors from your pi theme's diff foreground colors. This ensures diffs look good with any pi theme and terminal background — no configuration needed.
|
|
129
|
+
When no `diffTheme` or `diffColors` is set, pi-diff **automatically derives** background colors from your pi theme's diff foreground colors and tool-state backgrounds. Added/context surfaces use `toolSuccessBg`; removed surfaces use `toolErrorBg`. This ensures diffs look good with any pi theme and terminal background — no configuration needed.
|
|
130
130
|
|
|
131
131
|
The auto-derive uses different intensity levels:
|
|
132
|
-
- **Line backgrounds**: 8–10% of the theme's diff fg color (subtle tint)
|
|
132
|
+
- **Line backgrounds**: 8–10% of the theme's diff fg color mixed into the matching tool-state background (subtle tint)
|
|
133
133
|
- **Word highlights**: 20–22% (more visible for changed characters)
|
|
134
134
|
- **Gutters**: 5–6% (subtler than line backgrounds)
|
|
135
135
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -190,8 +190,9 @@ let _autoDerivePending = true;
|
|
|
190
190
|
let _hasExplicitBgConfig = false;
|
|
191
191
|
|
|
192
192
|
/** Auto-derive all diff background colors from the pi theme's fg diff colors.
|
|
193
|
-
* Reads toolSuccessBg as the base and
|
|
194
|
-
* Falls back to black (0,0,0)
|
|
193
|
+
* Reads toolSuccessBg as the add/context base and toolErrorBg as the delete base,
|
|
194
|
+
* then mixes accent colors into each. Falls back to black (0,0,0) when a theme
|
|
195
|
+
* background is unavailable; toolErrorBg falls back to toolSuccessBg. */
|
|
195
196
|
function autoDeriveBgFromTheme(theme: any): void {
|
|
196
197
|
if (!theme?.getFgAnsi) return;
|
|
197
198
|
try {
|
|
@@ -201,34 +202,42 @@ function autoDeriveBgFromTheme(theme: any): void {
|
|
|
201
202
|
const delRgb = parseAnsiRgb(fgDel);
|
|
202
203
|
if (!addRgb || !delRgb) return;
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
let
|
|
205
|
+
let addBase = { r: 0, g: 0, b: 0 };
|
|
206
|
+
let delBase = addBase;
|
|
206
207
|
if (theme.getBgAnsi) {
|
|
207
208
|
try {
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
const successBgAnsi = theme.getBgAnsi("toolSuccessBg");
|
|
210
|
+
const successParsed = parseAnsiRgb(successBgAnsi);
|
|
211
|
+
if (successParsed) {
|
|
212
|
+
addBase = successParsed;
|
|
213
|
+
delBase = successParsed;
|
|
214
|
+
BG_BASE = successBgAnsi;
|
|
213
215
|
}
|
|
214
216
|
} catch {
|
|
215
217
|
/* no toolSuccessBg — use black */
|
|
216
218
|
}
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
const errorParsed = parseAnsiRgb(theme.getBgAnsi("toolErrorBg"));
|
|
222
|
+
if (errorParsed) delBase = errorParsed;
|
|
223
|
+
} catch {
|
|
224
|
+
/* no toolErrorBg — use toolSuccessBg/black */
|
|
225
|
+
}
|
|
217
226
|
}
|
|
218
227
|
|
|
219
|
-
// Line backgrounds — subtle accent mixed into base (8–10%)
|
|
220
|
-
BG_ADD = mixBg(
|
|
221
|
-
BG_DEL = mixBg(
|
|
228
|
+
// Line backgrounds — subtle accent mixed into the matching tool-state base (8–10%)
|
|
229
|
+
BG_ADD = mixBg(addBase, addRgb, 0.08);
|
|
230
|
+
BG_DEL = mixBg(delBase, delRgb, 0.1);
|
|
222
231
|
|
|
223
232
|
// Word-level highlights — more visible (20–22%)
|
|
224
|
-
BG_ADD_W = mixBg(
|
|
225
|
-
BG_DEL_W = mixBg(
|
|
233
|
+
BG_ADD_W = mixBg(addBase, addRgb, 0.2);
|
|
234
|
+
BG_DEL_W = mixBg(delBase, delRgb, 0.22);
|
|
226
235
|
|
|
227
236
|
// Gutters — subtler than lines (5–6%)
|
|
228
|
-
BG_GUTTER_ADD = mixBg(
|
|
229
|
-
BG_GUTTER_DEL = mixBg(
|
|
237
|
+
BG_GUTTER_ADD = mixBg(addBase, addRgb, 0.05);
|
|
238
|
+
BG_GUTTER_DEL = mixBg(delBase, delRgb, 0.06);
|
|
230
239
|
|
|
231
|
-
// Empty filler and context — match the base
|
|
240
|
+
// Empty filler and context — match the success/context base
|
|
232
241
|
BG_EMPTY = BG_BASE;
|
|
233
242
|
|
|
234
243
|
// Update RST to re-apply base bg after every reset — prevents black
|
|
@@ -467,7 +476,7 @@ let DEFAULT_DIFF_COLORS: DiffColors = { fgAdd: FG_ADD, fgDel: FG_DEL, fgCtx: FG_
|
|
|
467
476
|
|
|
468
477
|
/** Resolve diff fg colors from theme (if available), falling back to hardcoded ANSI.
|
|
469
478
|
* On first call with a valid theme, auto-derives bg colors if no explicit config was set.
|
|
470
|
-
* Always reads toolSuccessBg for BG_BASE (used for context line backgrounds). */
|
|
479
|
+
* Always reads toolSuccessBg for BG_BASE (used for context/add line backgrounds). */
|
|
471
480
|
function resolveDiffColors(theme?: any): DiffColors {
|
|
472
481
|
// Always read toolSuccessBg for BG_BASE (even with explicit config)
|
|
473
482
|
if (theme?.getBgAnsi && BG_BASE === BG_DEFAULT) {
|