linecraft 0.5.3 → 0.5.5

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.
Files changed (42) hide show
  1. package/README.md +41 -7
  2. package/lib/components/code-debug.d.ts +2 -0
  3. package/lib/components/code-debug.d.ts.map +1 -1
  4. package/lib/components/code-debug.js +224 -255
  5. package/lib/components/code-debug.js.map +1 -1
  6. package/lib/components/code-debug.test.d.ts +2 -0
  7. package/lib/components/code-debug.test.d.ts.map +1 -0
  8. package/lib/components/code-debug.test.js +253 -0
  9. package/lib/components/code-debug.test.js.map +1 -0
  10. package/lib/components/styled.d.ts +1 -0
  11. package/lib/components/styled.d.ts.map +1 -1
  12. package/lib/components/styled.js +36 -7
  13. package/lib/components/styled.js.map +1 -1
  14. package/lib/layout/grid.d.ts +3 -2
  15. package/lib/layout/grid.d.ts.map +1 -1
  16. package/lib/layout/grid.js +93 -45
  17. package/lib/layout/grid.js.map +1 -1
  18. package/lib/layout/grid.test.js +67 -0
  19. package/lib/layout/grid.test.js.map +1 -1
  20. package/lib/native/diff.test.js.map +1 -1
  21. package/lib/native/region-renderer.d.ts +1 -0
  22. package/lib/native/region-renderer.d.ts.map +1 -1
  23. package/lib/native/region-renderer.js +31 -1
  24. package/lib/native/region-renderer.js.map +1 -1
  25. package/lib/region.d.ts.map +1 -1
  26. package/lib/region.js +0 -46
  27. package/lib/region.js.map +1 -1
  28. package/lib/utils/cursor-position.d.ts.map +1 -1
  29. package/lib/utils/cursor-position.js +4 -13
  30. package/lib/utils/cursor-position.js.map +1 -1
  31. package/lib/utils/text.d.ts +64 -2
  32. package/lib/utils/text.d.ts.map +1 -1
  33. package/lib/utils/text.js +670 -102
  34. package/lib/utils/text.js.map +1 -1
  35. package/lib/utils/text.test.d.ts +2 -0
  36. package/lib/utils/text.test.d.ts.map +1 -0
  37. package/lib/utils/text.test.js +237 -0
  38. package/lib/utils/text.test.js.map +1 -0
  39. package/lib/utils/wait-for-spacebar.d.ts.map +1 -1
  40. package/lib/utils/wait-for-spacebar.js +0 -7
  41. package/lib/utils/wait-for-spacebar.js.map +1 -1
  42. package/package.json +1 -1
@@ -1,107 +1,21 @@
1
1
  // Code debug component for displaying code errors/warnings with context
2
2
  import { callComponent } from '../component.js';
3
3
  import { applyStyle } from '../utils/colors.js';
4
- import { wrapText, stripAnsi, truncateToWidth } from '../utils/text.js';
4
+ import { stripAnsi, truncateToWidth, truncateFocusRange, mapColumnToDisplay, countVisibleChars, splitAtVisiblePos } from '../utils/text.js';
5
+ import { logToFile } from '../utils/debug-log.js';
6
+ import { fileLink } from '../utils/file-link.js';
7
+ import { Styled } from './styled.js';
5
8
  import { grid as Grid } from '../layout/grid.js';
6
9
  import { getLineNumberColor, isDarkTerminal } from '../utils/terminal-theme.js';
7
- function calculateVisibleRange(code, availableWidth, targetStartCol, targetEndCol, maxColumn) {
8
- const plainCode = stripAnsi(code);
9
- const codeLength = plainCode.length;
10
- // If code fits, show everything
11
- if (codeLength <= availableWidth) {
12
- return {
13
- startCol: 1,
14
- endCol: codeLength,
15
- hasEllipsisStart: false,
16
- hasEllipsisEnd: false,
17
- };
18
- }
19
- // If maxColumn is set, we need to ensure we don't show beyond it
20
- const effectiveMaxCol = maxColumn ? Math.min(maxColumn, codeLength) : codeLength;
21
- // Calculate how much space we need for the target columns
22
- const targetWidth = targetEndCol
23
- ? targetEndCol - targetStartCol + 1
24
- : 1; // Just the arrow
25
- // If target doesn't fit, we'll need to truncate
26
- if (targetWidth > availableWidth - 6) { // -6 for ellipsis on both sides if needed
27
- // Target is too wide, just show middle with ellipsis
28
- const midPoint = Math.floor((availableWidth - 6) / 2);
29
- const startCol = Math.max(1, targetStartCol - midPoint);
30
- const endCol = Math.min(effectiveMaxCol, startCol + availableWidth - 6);
31
- return {
32
- startCol,
33
- endCol,
34
- hasEllipsisStart: startCol > 1,
35
- hasEllipsisEnd: endCol < codeLength,
36
- };
37
- }
38
- // Try to center the target in the available space
39
- const padding = Math.floor((availableWidth - targetWidth) / 2);
40
- let startCol = Math.max(1, targetStartCol - padding);
41
- let endCol = Math.min(effectiveMaxCol, startCol + availableWidth - 1);
42
- // Adjust if we hit boundaries
43
- if (endCol - startCol + 1 > availableWidth) {
44
- endCol = startCol + availableWidth - 1;
45
- }
46
- if (endCol > effectiveMaxCol) {
47
- endCol = effectiveMaxCol;
48
- startCol = Math.max(1, endCol - availableWidth + 1);
49
- }
50
- if (startCol < 1) {
51
- startCol = 1;
52
- endCol = Math.min(effectiveMaxCol, availableWidth);
53
- }
54
- // Check if we need ellipsis
55
- const hasEllipsisStart = startCol > 1;
56
- const hasEllipsisEnd = endCol < codeLength;
57
- return {
58
- startCol,
59
- endCol,
60
- hasEllipsisStart,
61
- hasEllipsisEnd,
62
- };
63
- }
64
- /**
65
- * Truncate code line to show specific column range with ellipsis
66
- */
67
- function truncateCodeLine(code, visibleRange, availableWidth) {
68
- const { startCol, endCol, hasEllipsisStart, hasEllipsisEnd } = visibleRange;
69
- const plainCode = stripAnsi(code);
70
- if (!hasEllipsisStart && !hasEllipsisEnd) {
71
- // No truncation needed, but ensure it fits
72
- return truncateToWidth(code, availableWidth);
73
- }
74
- // Extract the visible portion (1-based columns in plain text)
75
- const visiblePlain = plainCode.substring(startCol - 1, endCol);
76
- // Calculate available width for code (minus ellipsis)
77
- const ellipsisWidth = (hasEllipsisStart ? 3 : 0) + (hasEllipsisEnd ? 3 : 0);
78
- const codeWidth = availableWidth - ellipsisWidth;
79
- // Truncate the visible portion if it's still too wide
80
- let truncatedPlain = visiblePlain;
81
- if (stripAnsi(visiblePlain).length > codeWidth) {
82
- truncatedPlain = truncateToWidth(visiblePlain, codeWidth);
83
- }
84
- if (hasEllipsisStart && hasEllipsisEnd) {
85
- // Truncate both ends - show middle portion
86
- const midPoint = Math.floor(codeWidth / 2);
87
- const startPart = truncateToWidth(truncatedPlain, midPoint);
88
- const endPart = truncateToWidth(truncatedPlain.substring(stripAnsi(truncatedPlain).length - (codeWidth - midPoint)), codeWidth - midPoint);
89
- return `...${startPart}...${endPart}...`;
90
- }
91
- else if (hasEllipsisStart) {
92
- return `...${truncatedPlain}`;
93
- }
94
- else {
95
- return `${truncatedPlain}...`;
96
- }
97
- }
98
10
  /**
99
11
  * CodeDebug component - displays code errors/warnings with context
100
12
  */
101
13
  export function CodeDebug(options) {
102
14
  return (ctx) => {
103
- const { startLine, startColumn, endLine, endColumn, lineBefore, errorLine, lineAfter, message, errorCode, shortMessage, filePath, fullPath, baseDir, type = 'error', maxColumn, } = options;
104
- const availableWidth = ctx.availableWidth;
15
+ const { startLine, startColumn, endColumn, lineBefore, errorLine, lineAfter, message, errorCode, shortMessage, shortMessagePlacement = 'auto', filePath, fullPath, baseDir, type = 'error', maxColumn, } = options;
16
+ // If availableWidth is Infinity (during Grid measurement), use a reasonable default
17
+ // Otherwise use the actual available width
18
+ const availableWidth = Number.isFinite(ctx.availableWidth) ? ctx.availableWidth : 80;
105
19
  // Color scheme based on type
106
20
  const colors = {
107
21
  error: { primary: 'red', secondary: 'brightRed', message: 'brightRed' },
@@ -111,6 +25,8 @@ export function CodeDebug(options) {
111
25
  const colorScheme = colors[type];
112
26
  // Get appropriate line number color based on terminal theme (muted color)
113
27
  const lineNumberColor = getLineNumberColor(); // For line numbers (muted)
28
+ // Use brightBlack for line numbers (visible but not too bright)
29
+ const lineNumColor = isDarkTerminal() ? 'brightBlack' : 'black';
114
30
  // Calculate available width for code (reserve space for line numbers, separator, and spaces)
115
31
  // Calculate the maximum width needed for any line number that will be displayed
116
32
  const lineNumbersToCheck = [startLine];
@@ -122,226 +38,279 @@ export function CodeDebug(options) {
122
38
  }
123
39
  const lineNumWidth = Math.max(...lineNumbersToCheck.map(n => String(n).length));
124
40
  const codeAreaWidth = availableWidth - lineNumWidth - 3; // -3 for " │ " (space, pipe, space)
125
- // Calculate visible range for error line
41
+ // Use truncateFocusRange to show the target range with proper truncation
126
42
  const targetEndCol = endColumn ?? startColumn;
127
- const plainErrorLine = stripAnsi(errorLine);
128
- const effectiveMaxCol = maxColumn ? Math.min(maxColumn, plainErrorLine.length) : plainErrorLine.length;
129
- const visibleRange = calculateVisibleRange(errorLine, codeAreaWidth, startColumn, targetEndCol, effectiveMaxCol);
130
- // Truncate error line
131
- const truncatedErrorLine = truncateCodeLine(errorLine, visibleRange, codeAreaWidth);
132
- // Calculate arrow/underline position relative to the truncated error line display
133
- // Map original column positions to display positions
134
- const truncatedPlain = stripAnsi(truncatedErrorLine);
135
- // Helper to map original column to display position
136
- const mapColumnToDisplay = (originalCol) => {
137
- if (visibleRange.hasEllipsisStart && visibleRange.hasEllipsisEnd) {
138
- // Format: "...start...end..."
139
- // Visible range is in the middle
140
- if (originalCol < visibleRange.startCol) {
141
- return 1; // Before visible, point to start
142
- }
143
- else if (originalCol > visibleRange.endCol) {
144
- return truncatedPlain.length; // After visible, point to end
145
- }
146
- else {
147
- // In visible range: position = 4 (for "...") + (col - startCol + 1)
148
- return 4 + (originalCol - visibleRange.startCol);
149
- }
150
- }
151
- else if (visibleRange.hasEllipsisStart) {
152
- // Format: "...code"
153
- if (originalCol < visibleRange.startCol) {
154
- return 1;
155
- }
156
- else {
157
- return 4 + (originalCol - visibleRange.startCol);
158
- }
159
- }
160
- else if (visibleRange.hasEllipsisEnd) {
161
- // Format: "code..."
162
- if (originalCol > visibleRange.endCol) {
163
- return truncatedPlain.length;
164
- }
165
- else {
166
- return originalCol;
167
- }
168
- }
169
- else {
170
- // No ellipsis, direct mapping
171
- return originalCol;
43
+ const defaultCodeColor = isDarkTerminal() ? 'brightBlack' : 'black';
44
+ const styledErrorLine = applyStyle(errorLine, { color: defaultCodeColor });
45
+ const truncateResult = truncateFocusRange(styledErrorLine, codeAreaWidth, startColumn, targetEndCol, maxColumn);
46
+ const truncatedErrorLine = truncateResult.text;
47
+ const visibleStartCol = truncateResult.visibleStartCol;
48
+ const visibleEndCol = truncateResult.visibleEndCol;
49
+ const rangeStartCol = truncateResult.rangeStartCol;
50
+ const rangeEndCol = truncateResult.rangeEndCol;
51
+ // Helper to map original column to display position using the actual visible range
52
+ const mapColumnToDisplayLocal = (originalCol) => {
53
+ const result = mapColumnToDisplay(errorLine, truncatedErrorLine, visibleStartCol, visibleEndCol, originalCol, rangeStartCol, rangeEndCol);
54
+ // Debug logging
55
+ if (originalCol === startColumn || originalCol === endColumn) {
56
+ const truncatedPlain = stripAnsi(truncatedErrorLine);
57
+ const charAtPos = truncatedPlain[result - 1] || '?';
58
+ const expectedChar = errorLine[originalCol - 1] || '?';
59
+ logToFile(`[code-debug] Width: ${codeAreaWidth}, OriginalCol: ${originalCol}, DisplayPos: ${result}, Char: '${charAtPos}' (expected '${expectedChar}'), VisibleRange: ${visibleStartCol}-${visibleEndCol}, Truncated: "${truncatedPlain.substring(0, 50)}..."`);
172
60
  }
61
+ return result;
173
62
  };
174
63
  // Build the code block lines
175
64
  const codeLines = [];
176
65
  // Icon and message at the top (Oxlint style)
66
+ // Use grid to handle wrapping automatically
177
67
  const icon = type === 'error' ? '✖' : type === 'warning' ? '⚠' : 'ℹ';
178
68
  const iconStyled = applyStyle(icon, { color: colorScheme.message });
179
- // Build the message text with optional error code
180
- let messageText = message;
69
+ // Build the combined message text: errorCode (if present) + message
70
+ // The errorCode should be underlined and bold, followed by ": ", then the message
71
+ // All parts should have the message color
72
+ let messageText;
181
73
  if (errorCode) {
182
- // Error code with underline - only underline the code, not the colon and space
183
74
  const errorCodeStyled = applyStyle(errorCode, {
184
75
  color: colorScheme.message,
185
76
  underline: true,
186
77
  bold: true
187
78
  });
188
- messageText = errorCodeStyled + ': ' + applyStyle(message, { color: colorScheme.message, bold: true });
79
+ // Apply message color to ": " and message parts so they maintain color after errorCode's reset
80
+ const colonAndMessage = applyStyle(': ' + message, { color: colorScheme.message });
81
+ messageText = errorCodeStyled + colonAndMessage;
189
82
  }
190
83
  else {
191
- messageText = applyStyle(message, { color: colorScheme.message, bold: true });
84
+ messageText = message;
192
85
  }
193
- // Use grid to layout: [icon (1 char)] [message (flex)]
194
- // This ensures the message doesn't overflow under the icon
195
- // Calculate available width for message (icon + gap + message column)
196
- const iconWidth = 1; // Icon is 1 character
197
- const gapWidth = 1; // columnGap is 1
198
- const messageAvailableWidth = ctx.availableWidth - iconWidth - gapWidth;
199
- // Wrap the message text to fit in the available width
200
- // First, get the plain text to calculate wrapping
201
- const plainMessageText = stripAnsi(messageText);
202
- const wrappedPlainLines = wrapText(plainMessageText, messageAvailableWidth);
203
- // Now we need to preserve ANSI codes in the wrapped lines
204
- // For simplicity, if the message wraps, we'll create a component that returns multiple lines
205
- const messageComponent = (msgCtx) => {
206
- // Recalculate available width for this context
207
- const msgWidth = msgCtx.availableWidth - iconWidth - gapWidth;
208
- const wrapped = wrapText(plainMessageText, msgWidth);
209
- // For each wrapped line, we need to preserve the ANSI styling
210
- // Since the message text has ANSI codes, we need to split it while preserving codes
211
- if (wrapped.length === 1) {
212
- // Single line - return as is
213
- return messageText;
214
- }
215
- // Multiple lines - we need to split the styled text
216
- // This is complex because we need to preserve ANSI codes across splits
217
- // For now, let's use a simpler approach: wrap the plain text and re-apply styling
218
- const wrappedStyled = [];
219
- let currentPos = 0;
220
- for (const wrappedLine of wrapped) {
221
- // Find the corresponding portion in the original styled text
222
- // We'll use a simple approach: measure visible characters
223
- const lineLength = wrappedLine.length;
224
- let styledPortion = '';
225
- let visibleCount = 0;
226
- let idx = currentPos;
227
- while (idx < messageText.length && visibleCount < lineLength) {
228
- if (messageText[idx] === '\x1b') {
229
- // ANSI code - include it
230
- let end = idx + 1;
231
- while (end < messageText.length && messageText[end] !== 'm') {
232
- end++;
233
- }
234
- if (end < messageText.length) {
235
- end++;
236
- }
237
- styledPortion += messageText.substring(idx, end);
238
- idx = end;
239
- }
240
- else {
241
- styledPortion += messageText[idx];
242
- idx++;
243
- visibleCount++;
244
- }
245
- }
246
- wrappedStyled.push(styledPortion);
247
- currentPos = idx;
248
- }
249
- return wrappedStyled;
250
- };
86
+ // Use Styled component to handle wrapping - it uses wrapText which prevents mid-word breaks
87
+ // Note: messageText may already have ANSI codes, so Styled will preserve them
88
+ const messageComponent = Styled({ color: colorScheme.message, overflow: 'wrap' }, messageText);
89
+ // Use 2-column grid: [icon, message (with optional errorCode)]
251
90
  const messageGrid = Grid({ template: [1, '1*'], columnGap: 1 }, iconStyled, messageComponent);
252
91
  const messageResult = callComponent(messageGrid, ctx);
92
+ const messageLines = [];
253
93
  if (messageResult && typeof messageResult === 'string') {
254
- codeLines.push(messageResult);
94
+ messageLines.push(messageResult);
255
95
  }
256
96
  else if (Array.isArray(messageResult)) {
257
- codeLines.push(...messageResult);
97
+ messageLines.push(...messageResult);
258
98
  }
259
99
  else {
260
- // Fallback if grid returns null - just concatenate with space
261
- codeLines.push(iconStyled + ' ' + messageText);
100
+ messageLines.push(iconStyled + ' ' + message);
262
101
  }
102
+ codeLines.push(...messageLines);
263
103
  // Add blank line after message before code block
264
104
  codeLines.push('');
265
105
  // Filename in brackets with line:column, connected with curved border (Oxlint style)
266
- // The curve should align with the line number column (accounting for line number width)
267
106
  const pathText = baseDir && filePath.startsWith(baseDir)
268
107
  ? filePath.substring(baseDir.length + 1)
269
108
  : filePath;
270
- // Only make the filename blue/bold, not the brackets, colons, or line/column numbers
271
- const locationText = '[' +
272
- applyStyle(pathText, { color: 'blue', bold: true }) +
273
- ':' +
274
- String(startLine) +
275
- ':' +
276
- String(startColumn) +
277
- ']';
278
- // Align curve with line numbers: lineNumWidth spaces + 1 space (for the space after line number)
109
+ // Build location line parts
279
110
  const curveIndent = ' '.repeat(lineNumWidth + 1);
280
- const locationLine = curveIndent + applyStyle('╭─', { color: 'brightBlack' }) + locationText;
281
- codeLines.push(locationLine);
111
+ const curve = applyStyle('╭─', { color: 'brightBlack' });
112
+ const bracketOpen = '[';
113
+ const colon1 = ':';
114
+ // Apply subtle color to line/column numbers (not colons) - use magenta for location line
115
+ const locationNumColor = isDarkTerminal() ? 'magenta' : 'magenta';
116
+ const lineNum = applyStyle(String(startLine), { color: locationNumColor });
117
+ const colon2 = ':';
118
+ const colNum = applyStyle(String(startColumn), { color: locationNumColor });
119
+ const bracketClose = ']';
120
+ // Calculate max width for path: available width minus fixed parts
121
+ // Fixed parts: curveIndent + ╭─ + [ + : + lineNum + : + colNum + ]
122
+ // Note: lineNum and colNum are now styled, so we need to use plain strings for width calculation
123
+ const lineNumPlain = String(startLine);
124
+ const colNumPlain = String(startColumn);
125
+ const fixedParts = curveIndent + curve + bracketOpen + colon1 + lineNumPlain + colon2 + colNumPlain + bracketClose;
126
+ const fixedPartsWidth = countVisibleChars(fixedParts);
127
+ // Ensure pathMaxWidth is finite and reasonable (cap at 40 to prevent extremely long paths)
128
+ const pathMaxWidth = Math.max(10, Math.min(40, availableWidth - fixedPartsWidth));
129
+ // Create clickable file link with styling and max width constraint
130
+ const pathWithLink = fileLink(fullPath, pathText);
131
+ const pathStyled = Styled({ color: 'blue', bold: true, overflow: 'ellipsis-start', max: pathMaxWidth }, pathWithLink);
132
+ // Use Grid with auto columns (content-based width, no padding)
133
+ // Template: [curveIndent (auto)][╭─ (auto)][[ (auto)][path (auto)][: (auto)][line (auto)][: (auto)][column (auto)][] (auto)]
134
+ const locationGrid = Grid({
135
+ template: ['auto', 'auto', 'auto', 'auto', 'auto', 'auto', 'auto', 'auto', 'auto'],
136
+ columnGap: 0
137
+ }, curveIndent, curve, bracketOpen, pathStyled, colon1, lineNum, colon2, colNum, bracketClose);
138
+ const locationResult = callComponent(locationGrid, ctx);
139
+ if (locationResult && typeof locationResult === 'string') {
140
+ codeLines.push(locationResult);
141
+ }
142
+ else if (Array.isArray(locationResult)) {
143
+ codeLines.push(...locationResult);
144
+ }
145
+ else {
146
+ // Fallback
147
+ const locationLine = curveIndent + curve + bracketOpen + pathText + colon1 + lineNum + colon2 + colNum + bracketClose;
148
+ codeLines.push(locationLine);
149
+ }
282
150
  // Line before (if exists)
283
151
  if (lineBefore !== null && lineBefore !== undefined) {
284
152
  const beforeLineNum = String(startLine - 1);
285
153
  const beforeLineNumPadded = beforeLineNum.padStart(lineNumWidth);
286
154
  const truncatedBefore = truncateToWidth(lineBefore, codeAreaWidth);
287
- codeLines.push(applyStyle(`${beforeLineNumPadded} `, { color: lineNumberColor, dim: isDarkTerminal() }) +
288
- applyStyle('│ ', { color: 'brightBlack' }) + truncatedBefore);
155
+ // Make non-error lines slightly dimmer: darker on dark terminals, whiter on light terminals
156
+ const dimmedBefore = isDarkTerminal()
157
+ ? applyStyle(truncatedBefore, { dim: true })
158
+ : applyStyle(truncatedBefore, { color: 'brightBlack' });
159
+ codeLines.push(applyStyle(`${beforeLineNumPadded} `, { color: lineNumColor }) +
160
+ applyStyle('│ ', { color: 'brightBlack' }) + dimmedBefore);
289
161
  }
290
162
  // Error line (with space before code)
163
+ // truncatedErrorLine already has the default color applied
164
+ let highlightedErrorLine = truncatedErrorLine;
165
+ // Highlight the error range if endColumn is specified
166
+ if (endColumn && endColumn > startColumn) {
167
+ // Map columns to display positions in the truncated (and styled) text
168
+ // We need to map based on the plain truncated text, then account for ANSI codes
169
+ const truncatedPlain = stripAnsi(truncatedErrorLine);
170
+ const highlightStart = mapColumnToDisplayLocal(startColumn); // 1-based display position
171
+ const highlightEnd = mapColumnToDisplayLocal(endColumn); // 1-based display position
172
+ // Split at highlight start and end positions (splitAtVisiblePos uses 0-based)
173
+ const { before: beforeHighlight, after: remainingAfterStart } = splitAtVisiblePos(highlightedErrorLine, highlightStart - 1);
174
+ const highlightLength = highlightEnd - highlightStart + 1;
175
+ const { before: highlightRange, after: afterHighlight } = splitAtVisiblePos(remainingAfterStart, highlightLength);
176
+ // Strip existing ANSI codes from highlight range and apply new highlight color
177
+ // This ensures the highlight color properly overrides the default code color
178
+ const highlightColor = isDarkTerminal() ? 'white' : 'black';
179
+ const highlightPlain = stripAnsi(highlightRange);
180
+ const highlightedRangeStyled = applyStyle(highlightPlain, { color: highlightColor });
181
+ highlightedErrorLine = beforeHighlight + highlightedRangeStyled + afterHighlight;
182
+ }
291
183
  const errorLineNum = String(startLine);
292
184
  const errorLineNumPadded = errorLineNum.padStart(lineNumWidth);
293
- let errorLineDisplay = applyStyle(`${errorLineNumPadded} `, { color: lineNumberColor, dim: isDarkTerminal() }) +
294
- applyStyle('│ ', { color: 'brightBlack' }) + truncatedErrorLine;
185
+ let errorLineDisplay = applyStyle(`${errorLineNumPadded} `, { color: lineNumColor }) +
186
+ applyStyle('│ ', { color: 'brightBlack' }) + highlightedErrorLine;
295
187
  codeLines.push(errorLineDisplay);
296
188
  // Underline line (Oxlint style)
297
189
  // Format: "[lineNumWidth spaces][1 space][│][1 space][dots][underline]"
298
190
  // Calculate positions relative to the code (after "│ ")
299
- const underlineStartInCode = mapColumnToDisplay(startColumn);
300
- const underlineEndInCode = endColumn ? mapColumnToDisplay(endColumn) : underlineStartInCode;
191
+ const underlineStartInCode = mapColumnToDisplayLocal(startColumn);
192
+ const underlineEndInCode = endColumn ? mapColumnToDisplayLocal(endColumn) : underlineStartInCode;
301
193
  const underlineLength = underlineEndInCode - underlineStartInCode + 1;
302
- // Spaces to align with the start of the underline (position in code, 1-based, minus 1 for 0-based)
194
+ // Spaces to align with the start of the underline
195
+ // underlineStartInCode is position in truncated text (which is what's displayed after │ )
196
+ // The ellipsis is PART of the displayed text, so we use the position directly
197
+ // Position is 1-based, so spacesBefore = underlineStartInCode - 1
303
198
  const spacesBefore = Math.max(0, underlineStartInCode - 1);
304
199
  // Underline line: line number width + space + │ + space + spaces + underline
305
- let underlineLine = ' '.repeat(lineNumWidth) + ' ' + applyStyle('│', { color: 'brightBlack' }) + ' ';
306
- if (shortMessage && underlineLength > 1) {
307
- // Multi-character underline with T-bar in the middle for short message
308
- const connectPosInUnderline = Math.floor(underlineLength / 2);
309
- const leftPart = '─'.repeat(connectPosInUnderline);
310
- const rightPart = '─'.repeat(underlineLength - connectPosInUnderline - 1);
311
- underlineLine += ' '.repeat(spacesBefore) +
312
- applyStyle(leftPart + '┬' + rightPart, { color: colorScheme.primary });
313
- }
314
- else if (shortMessage) {
315
- // Single character with T-bar for short message
316
- underlineLine += ' '.repeat(spacesBefore) +
317
- applyStyle('┬', { color: colorScheme.primary });
200
+ let indicatorLine = ' '.repeat(lineNumWidth) + ' ' + applyStyle('│', { color: 'brightBlack' }) + ' ' +
201
+ ' '.repeat(spacesBefore);
202
+ // Calculate connectCol for short message (if present)
203
+ // This is the position where the T-bar (┬) will be, which is the middle of the underline
204
+ // Use positions in the truncated text (which is what's displayed)
205
+ const connectCol = shortMessage && underlineLength > 1
206
+ ? underlineStartInCode + Math.floor(underlineLength / 2)
207
+ : underlineStartInCode;
208
+ // Calculate the position of the T-bar within the indicator line (after │ and space)
209
+ // This is: lineNumWidth + 1 (space) + 1 (│) + 1 (space) + spacesBefore + connectPosInUnderline
210
+ const connectPosInIndicator = lineNumWidth + 1 + 1 + 1 + spacesBefore + (connectCol - underlineStartInCode);
211
+ logToFile(`[code-debug] lineNumWidth: ${lineNumWidth}, spacesBefore: ${spacesBefore}, connectCol: ${connectCol}, underlineStartInCode: ${underlineStartInCode}, connectPosInIndicator: ${connectPosInIndicator}`);
212
+ const underlineStartCol = underlineStartInCode;
213
+ const underlineEndCol = underlineEndInCode;
214
+ if (endColumn && underlineEndCol > underlineStartCol) {
215
+ // Underline with curved edges facing up
216
+ // Use underlineLength which was already calculated correctly (end - start + 1)
217
+ const underlineLen = underlineLength;
218
+ if (shortMessage) {
219
+ // With short message: T-bar in the middle
220
+ const connectPosInUnderline = connectCol - underlineStartInCode; // Position within the underline
221
+ if (underlineLen >= 3) {
222
+ // Build underline with T-bar: left curve, dashes, T-bar, dashes, right curve
223
+ // Total length = 1 (┖) + left dashes + 1 (┬) + right dashes + 1 (┚) = underlineLen
224
+ // So: left dashes + right dashes = underlineLen - 3
225
+ // T-bar is at position connectPosInUnderline (0-indexed from start), so:
226
+ // - left dashes = connectPosInUnderline - 1 (before T-bar, after ┖)
227
+ // - right dashes = underlineLen - 3 - (connectPosInUnderline - 1) = underlineLen - connectPosInUnderline - 2
228
+ const leftPart = '─'.repeat(Math.max(0, connectPosInUnderline - 1));
229
+ const rightPart = '─'.repeat(Math.max(0, underlineLen - connectPosInUnderline - 2));
230
+ indicatorLine += applyStyle('┖' + leftPart + '┬' + rightPart + '┚', { color: colorScheme.primary });
231
+ }
232
+ else if (underlineLen === 2) {
233
+ // Exactly 2 characters: just the brackets, no T-bar
234
+ indicatorLine += applyStyle('┖┚', { color: colorScheme.primary });
235
+ }
236
+ else {
237
+ // Single character, just use T
238
+ indicatorLine += applyStyle('╿', { color: colorScheme.primary });
239
+ }
240
+ }
241
+ else {
242
+ // No short message: flat underline with curved ends (no T-bar)
243
+ // For underlineLen=2: ┖┚ (no dashes), for underlineLen=3: ┖─┚ (1 dash), etc.
244
+ const dashes = '─'.repeat(Math.max(0, underlineLen - 2));
245
+ indicatorLine += applyStyle('┖' + dashes + '┚', { color: colorScheme.primary });
246
+ }
318
247
  }
319
248
  else {
320
- // No short message, just underline the code
321
- const underlineChars = ''.repeat(underlineLength);
322
- underlineLine += ' '.repeat(spacesBefore) +
323
- applyStyle(underlineChars, { color: colorScheme.primary });
249
+ // Single point - use ┬ (T pointing up) which has horizontal bar pointing to code, vertical line going down
250
+ indicatorLine += applyStyle('', { color: colorScheme.primary });
324
251
  }
325
- codeLines.push(underlineLine);
252
+ codeLines.push(indicatorLine);
326
253
  // Short message connected to underline (if provided)
327
254
  if (shortMessage) {
328
- const connectCol = underlineLength > 1
329
- ? underlineStartInCode + Math.floor(underlineLength / 2)
330
- : underlineStartInCode;
331
- // Short message line: line number width + space + │ + space + spaces + connector + message
332
- const shortMessageLine = ' '.repeat(lineNumWidth) + ' ' + applyStyle('│', { color: 'brightBlack' }) + ' ' +
333
- ' '.repeat(Math.max(0, connectCol - 1)) +
334
- applyStyle('╰── ', { color: colorScheme.primary }) +
335
- applyStyle(shortMessage, { color: colorScheme.message });
336
- codeLines.push(shortMessageLine);
255
+ // Determine placement: 'auto' means calculate which side has more available space
256
+ let placement = shortMessagePlacement === 'auto'
257
+ ? (() => {
258
+ const shortMessageWidth = countVisibleChars(shortMessage);
259
+ const connectorWidth = 4; // " ──╯" or "╰── " is 4 characters
260
+ const totalWidth = shortMessageWidth + connectorWidth;
261
+ // Available space on left: from start of code area to connectCol
262
+ const availableLeft = connectCol - 1;
263
+ // Available space on right: from connectCol to end of code area
264
+ const availableRight = codeAreaWidth - connectCol;
265
+ // Place on left if left has more space, otherwise right
266
+ return availableLeft >= availableRight ? 'left' : 'right';
267
+ })()
268
+ : shortMessagePlacement;
269
+ if (placement === 'left') {
270
+ // Short message on left: message + connector pointing right (curved up)
271
+ // The connector " ──╯" is 4 chars: space + dash + dash + ╯
272
+ // The ╯ should be at connectPosInIndicator
273
+ // So: linePrefixWidth + spacesBeforeMessage + messageWidth + connectorWidth = connectPosInIndicator
274
+ // Where connectorWidth = 4 (space + 2 dashes + ╯)
275
+ const messageWidth = countVisibleChars(shortMessage);
276
+ const linePrefixWidth = lineNumWidth + 3; // lineNumWidth + space + │ + space
277
+ const connectorWidth = 4; // " ──╯" is 4 characters
278
+ const spacesBeforeMessage = Math.max(0, connectPosInIndicator - linePrefixWidth - messageWidth - connectorWidth);
279
+ const shortMessageLine = ' '.repeat(lineNumWidth) + ' ' + applyStyle('│', { color: 'brightBlack' }) + ' ' +
280
+ ' '.repeat(spacesBeforeMessage) +
281
+ applyStyle(shortMessage, { color: colorScheme.message }) +
282
+ applyStyle(' ──╯', { color: colorScheme.primary });
283
+ codeLines.push(shortMessageLine);
284
+ }
285
+ else {
286
+ // Short message on right: connector pointing left (curved up) + message
287
+ // The connector "╰── " is 4 chars, and the last dash should connect to the T-bar
288
+ // The T-bar is at connectPosInIndicator, so the last dash is at connectPosInIndicator
289
+ // The connector "╰── " has the last dash at position 3 (0-indexed), so:
290
+ // connectorStartPos + 3 = connectPosInIndicator
291
+ // Therefore: connectorStartPos = connectPosInIndicator - 3
292
+ const linePrefixWidth = lineNumWidth + 3; // lineNumWidth + space + │ + space
293
+ const connectorStartPos = connectPosInIndicator - 3; // Connector "╰── " ends at connectPosInIndicator
294
+ const spacesBeforeConnector = Math.max(0, connectorStartPos - linePrefixWidth);
295
+ const shortMessageLine = ' '.repeat(lineNumWidth) + ' ' + applyStyle('│', { color: 'brightBlack' }) + ' ' +
296
+ ' '.repeat(spacesBeforeConnector) +
297
+ applyStyle('╰── ', { color: colorScheme.primary }) +
298
+ ' ' + // Single space between connector and message
299
+ applyStyle(shortMessage, { color: colorScheme.message });
300
+ codeLines.push(shortMessageLine);
301
+ }
337
302
  }
338
303
  // Line after (if exists)
339
304
  if (lineAfter !== null && lineAfter !== undefined) {
340
305
  const afterLineNum = String(startLine + 1);
341
306
  const afterLineNumPadded = afterLineNum.padStart(lineNumWidth);
342
307
  const truncatedAfter = truncateToWidth(lineAfter, codeAreaWidth);
343
- codeLines.push(applyStyle(`${afterLineNumPadded} `, { color: lineNumberColor, dim: isDarkTerminal() }) +
344
- applyStyle('│ ', { color: 'brightBlack' }) + truncatedAfter);
308
+ // Make non-error lines slightly dimmer: darker on dark terminals, whiter on light terminals
309
+ const dimmedAfter = isDarkTerminal()
310
+ ? applyStyle(truncatedAfter, { dim: true })
311
+ : applyStyle(truncatedAfter, { color: 'brightBlack' });
312
+ codeLines.push(applyStyle(`${afterLineNumPadded} `, { color: lineNumColor }) +
313
+ applyStyle('│ ', { color: 'brightBlack' }) + dimmedAfter);
345
314
  }
346
315
  // Bottom curve to close the box (Oxlint style)
347
316
  const bottomCurveIndent = ' '.repeat(lineNumWidth + 1);