linecraft 0.5.4 → 0.5.6
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/LICENSE +21 -59
- package/README.md +30 -0
- package/lib/components/code-debug.d.ts +2 -0
- package/lib/components/code-debug.d.ts.map +1 -1
- package/lib/components/code-debug.js +104 -198
- package/lib/components/code-debug.js.map +1 -1
- package/lib/components/code-debug.test.d.ts +2 -0
- package/lib/components/code-debug.test.d.ts.map +1 -0
- package/lib/components/code-debug.test.js +245 -0
- package/lib/components/code-debug.test.js.map +1 -0
- package/lib/components/fill.d.ts +2 -1
- package/lib/components/fill.d.ts.map +1 -1
- package/lib/components/fill.js.map +1 -1
- package/lib/components/progress-bar-grid.d.ts.map +1 -1
- package/lib/components/progress-bar-grid.js +5 -3
- package/lib/components/progress-bar-grid.js.map +1 -1
- package/lib/components/prompt.js +1 -1
- package/lib/components/prompt.js.map +1 -1
- package/lib/components/section.js +1 -1
- package/lib/components/section.js.map +1 -1
- package/lib/components/segments.js +4 -4
- package/lib/components/segments.js.map +1 -1
- package/lib/components/spinner.d.ts +2 -1
- package/lib/components/spinner.d.ts.map +1 -1
- package/lib/components/spinner.js +1 -1
- package/lib/components/spinner.js.map +1 -1
- package/lib/components/styled.d.ts +3 -2
- package/lib/components/styled.d.ts.map +1 -1
- package/lib/components/styled.js +1 -1
- package/lib/components/styled.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/layout/grid.d.ts.map +1 -1
- package/lib/layout/grid.js +1 -2
- package/lib/layout/grid.js.map +1 -1
- package/lib/layout/grid.test.js +3 -3
- package/lib/layout/grid.test.js.map +1 -1
- package/lib/native/region.test.js +1 -1
- package/lib/native/region.test.js.map +1 -1
- package/lib/region-resize.test.js +3 -3
- package/lib/region-resize.test.js.map +1 -1
- package/lib/types.d.ts +6 -5
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/colors.d.ts.map +1 -1
- package/lib/utils/colors.js +50 -8
- package/lib/utils/colors.js.map +1 -1
- package/lib/utils/colors.test.js.map +1 -1
- package/lib/utils/debug-log.js +1 -1
- package/lib/utils/debug-log.js.map +1 -1
- package/lib/utils/terminal-theme.d.ts +17 -28
- package/lib/utils/terminal-theme.d.ts.map +1 -1
- package/lib/utils/terminal-theme.js +66 -38
- package/lib/utils/terminal-theme.js.map +1 -1
- package/lib/utils/text.d.ts +62 -2
- package/lib/utils/text.d.ts.map +1 -1
- package/lib/utils/text.js +396 -37
- package/lib/utils/text.js.map +1 -1
- package/lib/utils/text.test.d.ts +2 -0
- package/lib/utils/text.test.d.ts.map +1 -0
- package/lib/utils/text.test.js +237 -0
- package/lib/utils/text.test.js.map +1 -0
- package/lib/utils/wait-for-spacebar.js +1 -1
- package/lib/utils/wait-for-spacebar.js.map +1 -1
- package/package.json +2 -8
|
@@ -1,37 +1,26 @@
|
|
|
1
|
+
import type { Color, TextStyle } from '../types.js';
|
|
1
2
|
/**
|
|
2
3
|
* Detect if the terminal has a dark or light background
|
|
3
|
-
*
|
|
4
|
-
* Uses the COLORFGBG environment variable which has format "foreground;background"
|
|
5
|
-
* where background values 0-7 indicate dark background, 8-15 indicate light background.
|
|
6
|
-
*
|
|
7
|
-
* If COLORFGBG is not available, defaults to assuming dark background (most common).
|
|
8
|
-
*
|
|
9
|
-
* @returns true if terminal has dark background, false if light
|
|
10
4
|
*/
|
|
11
5
|
export declare function isDarkTerminal(): boolean;
|
|
12
6
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* On dark terminals: returns 'brightBlack' (will be dimmed for less contrast)
|
|
16
|
-
* On light terminals: returns 'black' (darker gray, less contrasty)
|
|
17
|
-
*
|
|
18
|
-
* These colors provide minimal contrast while remaining subtle and not distracting
|
|
19
|
-
* from the main code content. On dark terminals, the color should be applied with
|
|
20
|
-
* dim=true to reduce contrast further.
|
|
21
|
-
*
|
|
22
|
-
* @returns Color name suitable for line numbers
|
|
7
|
+
* Resolve a value based on the current terminal theme
|
|
23
8
|
*/
|
|
24
|
-
export declare function
|
|
9
|
+
export declare function resolveThemeColor<T>(colors: {
|
|
10
|
+
dark: T;
|
|
11
|
+
light: T;
|
|
12
|
+
}, forceTheme?: 'dark' | 'light'): T;
|
|
13
|
+
export type AutoColor = 'base' | 'muted' | 'highlight' | 'accent' | 'warning' | 'error' | 'info' | 'location' | 'success';
|
|
25
14
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* On dark terminals: returns 'blue' (muted, less contrasty blue)
|
|
29
|
-
* On light terminals: returns 'brightBlue' (muted, less contrasty blue)
|
|
30
|
-
*
|
|
31
|
-
* This provides a subtle, less contrasty color for line numbers that still
|
|
32
|
-
* has a blue shade, working well in both dark and light terminal themes.
|
|
33
|
-
*
|
|
34
|
-
* @returns Color name suitable for colored line numbers
|
|
15
|
+
* Checks if a string is a semantic auto-color token
|
|
35
16
|
*/
|
|
36
|
-
export declare function
|
|
17
|
+
export declare function isAutoColor(color: string): color is AutoColor;
|
|
18
|
+
/**
|
|
19
|
+
* Automatically picks the right ANSI color for a semantic token based on light/dark theme
|
|
20
|
+
*/
|
|
21
|
+
export declare function autoColor(token: AutoColor, override?: 'dark' | 'light'): Color;
|
|
22
|
+
/**
|
|
23
|
+
* Automatically picks the right full style for a semantic token
|
|
24
|
+
*/
|
|
25
|
+
export declare function autoStyle(token: AutoColor, override?: 'dark' | 'light'): TextStyle;
|
|
37
26
|
//# sourceMappingURL=terminal-theme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-theme.d.ts","sourceRoot":"","sources":["../../src/utils/terminal-theme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"terminal-theme.d.ts","sourceRoot":"","sources":["../../src/utils/terminal-theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIpD;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAkBxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,MAAM,EAAE;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,EAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,GAC5B,CAAC,CAIH;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AA2C1H;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAE7D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,CAE9E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAGlF"}
|
|
@@ -1,62 +1,90 @@
|
|
|
1
1
|
// Terminal theme detection utilities
|
|
2
2
|
/**
|
|
3
3
|
* Detect if the terminal has a dark or light background
|
|
4
|
-
*
|
|
5
|
-
* Uses the COLORFGBG environment variable which has format "foreground;background"
|
|
6
|
-
* where background values 0-7 indicate dark background, 8-15 indicate light background.
|
|
7
|
-
*
|
|
8
|
-
* If COLORFGBG is not available, defaults to assuming dark background (most common).
|
|
9
|
-
*
|
|
10
|
-
* @returns true if terminal has dark background, false if light
|
|
11
4
|
*/
|
|
12
5
|
export function isDarkTerminal() {
|
|
6
|
+
if (process.env.TERMINAL_THEME === 'light')
|
|
7
|
+
return false;
|
|
8
|
+
if (process.env.TERMINAL_THEME === 'dark')
|
|
9
|
+
return true;
|
|
13
10
|
const colorfgbg = process.env.COLORFGBG;
|
|
14
11
|
if (!colorfgbg) {
|
|
15
|
-
// Default to dark (most terminals are dark)
|
|
16
12
|
return true;
|
|
17
13
|
}
|
|
18
|
-
// COLORFGBG format: "foreground;background" or just "background"
|
|
19
14
|
const parts = colorfgbg.split(';');
|
|
20
15
|
const background = parts.length > 1 ? parts[1] : parts[0];
|
|
21
16
|
const bgNum = parseInt(background, 10);
|
|
22
17
|
if (isNaN(bgNum)) {
|
|
23
|
-
// Can't parse, default to dark
|
|
24
18
|
return true;
|
|
25
19
|
}
|
|
26
|
-
// Background values 0-7 = dark, 8-15 = light
|
|
27
20
|
return bgNum < 8;
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
* Resolve a value based on the current terminal theme
|
|
24
|
+
*/
|
|
25
|
+
export function resolveThemeColor(colors, forceTheme) {
|
|
26
|
+
if (forceTheme === 'dark')
|
|
27
|
+
return colors.dark;
|
|
28
|
+
if (forceTheme === 'light')
|
|
29
|
+
return colors.light;
|
|
30
|
+
return isDarkTerminal() ? colors.dark : colors.light;
|
|
31
|
+
}
|
|
32
|
+
const semanticPalette = {
|
|
33
|
+
base: {
|
|
34
|
+
dark: { color: 'gray' },
|
|
35
|
+
light: { color: 'gray' }
|
|
36
|
+
},
|
|
37
|
+
muted: {
|
|
38
|
+
dark: { color: 'white', dim: true },
|
|
39
|
+
light: { color: 'gray', dim: true }
|
|
40
|
+
},
|
|
41
|
+
highlight: {
|
|
42
|
+
dark: { color: 'white' },
|
|
43
|
+
light: { color: 'black', bold: true }
|
|
44
|
+
},
|
|
45
|
+
accent: {
|
|
46
|
+
dark: { color: 'blue', bold: true },
|
|
47
|
+
light: { color: 'blue', bold: true }
|
|
48
|
+
},
|
|
49
|
+
location: {
|
|
50
|
+
dark: { color: 'magenta' },
|
|
51
|
+
light: { color: 'magenta' }
|
|
52
|
+
},
|
|
53
|
+
success: {
|
|
54
|
+
dark: { color: 'brightGreen' },
|
|
55
|
+
light: { color: 'green' }
|
|
56
|
+
},
|
|
57
|
+
warning: {
|
|
58
|
+
dark: { color: 'brightYellow' },
|
|
59
|
+
light: { color: 'brightMagenta' }
|
|
60
|
+
},
|
|
61
|
+
error: {
|
|
62
|
+
dark: { color: 'brightRed' },
|
|
63
|
+
light: { color: 'red' }
|
|
64
|
+
},
|
|
65
|
+
info: {
|
|
66
|
+
dark: { color: 'blue' },
|
|
67
|
+
light: { color: 'blue' }
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const autoColorSet = new Set(['base', 'muted', 'highlight', 'accent', 'warning', 'error', 'info', 'location', 'success']);
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a string is a semantic auto-color token
|
|
73
|
+
*/
|
|
74
|
+
export function isAutoColor(color) {
|
|
75
|
+
return autoColorSet.has(color);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Automatically picks the right ANSI color for a semantic token based on light/dark theme
|
|
40
79
|
*/
|
|
41
|
-
export function
|
|
42
|
-
|
|
43
|
-
// On light terminals, use black (darker gray, less contrasty)
|
|
44
|
-
return isDarkTerminal() ? 'brightBlack' : 'black';
|
|
80
|
+
export function autoColor(token, override) {
|
|
81
|
+
return autoStyle(token, override).color;
|
|
45
82
|
}
|
|
46
83
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* On dark terminals: returns 'blue' (muted, less contrasty blue)
|
|
50
|
-
* On light terminals: returns 'brightBlue' (muted, less contrasty blue)
|
|
51
|
-
*
|
|
52
|
-
* This provides a subtle, less contrasty color for line numbers that still
|
|
53
|
-
* has a blue shade, working well in both dark and light terminal themes.
|
|
54
|
-
*
|
|
55
|
-
* @returns Color name suitable for colored line numbers
|
|
84
|
+
* Automatically picks the right full style for a semantic token
|
|
56
85
|
*/
|
|
57
|
-
export function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return isDarkTerminal() ? 'blue' : 'brightBlue';
|
|
86
|
+
export function autoStyle(token, override) {
|
|
87
|
+
const choice = semanticPalette[token];
|
|
88
|
+
return resolveThemeColor(choice, override);
|
|
61
89
|
}
|
|
62
90
|
//# sourceMappingURL=terminal-theme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-theme.js","sourceRoot":"","sources":["../../src/utils/terminal-theme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"terminal-theme.js","sourceRoot":"","sources":["../../src/utils/terminal-theme.ts"],"names":[],"mappings":"AAEA,qCAAqC;AAErC;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACzD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAEvD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAEvC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,GAAG,CAAC,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA6B,EAC7B,UAA6B;IAE7B,IAAI,UAAU,KAAK,MAAM;QAAE,OAAO,MA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E,WAAW,EAAE;QAC5B,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;KACxB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;QACvB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;KACzB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;AAE1H;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB,EAAE,QAA2B;IACrE,OAAO,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAc,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB,EAAE,QAA2B;IACrE,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC"}
|
package/lib/utils/text.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export declare function stripAnsi(text: string): string;
|
|
|
15
15
|
* Truncate text to a maximum visual width while preserving ANSI escape codes
|
|
16
16
|
*
|
|
17
17
|
* This function truncates text based on its visual width (ignoring ANSI codes),
|
|
18
|
-
* but preserves all ANSI escape sequences in the output.
|
|
19
|
-
*
|
|
18
|
+
* but preserves all ANSI escape sequences in the output. Active ANSI codes are
|
|
19
|
+
* preserved in the truncated result.
|
|
20
20
|
*
|
|
21
21
|
* @param text - Text that may contain ANSI escape codes
|
|
22
22
|
* @param maxWidth - Maximum visual width (number of visible characters)
|
|
@@ -29,6 +29,9 @@ export declare function truncateToWidth(text: string, maxWidth: number): string;
|
|
|
29
29
|
/**
|
|
30
30
|
* Truncate text with ellipsis at the end, preserving ANSI escape codes
|
|
31
31
|
*
|
|
32
|
+
* Active ANSI codes from the truncated portion are preserved, and the ellipsis
|
|
33
|
+
* is added after the truncated text (without ANSI codes).
|
|
34
|
+
*
|
|
32
35
|
* @param text - Text that may contain ANSI escape codes
|
|
33
36
|
* @param maxWidth - Maximum visual width (number of visible characters)
|
|
34
37
|
* @returns Truncated text with '...' at the end, ANSI codes preserved
|
|
@@ -40,6 +43,10 @@ export declare function truncateEnd(text: string, maxWidth: number): string;
|
|
|
40
43
|
/**
|
|
41
44
|
* Truncate text with ellipsis at the beginning, preserving ANSI escape codes
|
|
42
45
|
*
|
|
46
|
+
* When truncating from the start, we preserve ANSI codes that are active in the
|
|
47
|
+
* remaining portion. The ellipsis is added at the beginning (without ANSI codes),
|
|
48
|
+
* and active codes from the original text are re-applied to the remaining portion.
|
|
49
|
+
*
|
|
43
50
|
* @param text - Text that may contain ANSI escape codes
|
|
44
51
|
* @param maxWidth - Maximum visual width (number of visible characters)
|
|
45
52
|
* @returns Truncated text with '...' at the beginning, ANSI codes preserved
|
|
@@ -51,6 +58,9 @@ export declare function truncateStart(text: string, maxWidth: number): string;
|
|
|
51
58
|
/**
|
|
52
59
|
* Truncate text with ellipsis in the middle, preserving ANSI escape codes
|
|
53
60
|
*
|
|
61
|
+
* When truncating in the middle, we preserve ANSI codes from the start portion
|
|
62
|
+
* and re-apply them to the end portion to maintain consistent styling.
|
|
63
|
+
*
|
|
54
64
|
* @param text - Text that may contain ANSI escape codes
|
|
55
65
|
* @param maxWidth - Maximum visual width (number of visible characters)
|
|
56
66
|
* @returns Truncated text with '...' in the middle, ANSI codes preserved
|
|
@@ -59,6 +69,56 @@ export declare function truncateStart(text: string, maxWidth: number): string;
|
|
|
59
69
|
* truncateMiddle('\x1b[31mHello World\x1b[0m', 8) // '\x1b[31mHel...ld\x1b[0m'
|
|
60
70
|
*/
|
|
61
71
|
export declare function truncateMiddle(text: string, maxWidth: number): string;
|
|
72
|
+
/**
|
|
73
|
+
* Map an original column position to its display position in truncated text
|
|
74
|
+
*
|
|
75
|
+
* This function takes the original text, the truncated result, and the visible range
|
|
76
|
+
* that was shown, and maps an original column to where it appears in the truncated text.
|
|
77
|
+
*
|
|
78
|
+
* @param originalText - The original text (plain, no ANSI)
|
|
79
|
+
* @param truncatedText - The truncated text result (may have ellipsis)
|
|
80
|
+
* @param visibleStartCol - The first column that was shown (1-based, includes truncated before)
|
|
81
|
+
* @param visibleEndCol - The last column that was shown (1-based, includes truncated after)
|
|
82
|
+
* @param originalCol - The original column to map (1-based)
|
|
83
|
+
* @param rangeStartCol - The start column of the main range (1-based, optional, for better accuracy)
|
|
84
|
+
* @param rangeEndCol - The end column of the main range (1-based, optional, for better accuracy)
|
|
85
|
+
* @returns The display position in the truncated text (1-based, visible characters)
|
|
86
|
+
*/
|
|
87
|
+
export declare function mapColumnToDisplay(originalText: string, truncatedText: string, visibleStartCol: number, visibleEndCol: number, originalCol: number, rangeStartCol?: number, rangeEndCol?: number): number;
|
|
88
|
+
/**
|
|
89
|
+
* Result of truncateFocusRange, including information about what range was shown
|
|
90
|
+
*/
|
|
91
|
+
export interface TruncateFocusRangeResult {
|
|
92
|
+
/** The truncated text with target range visible */
|
|
93
|
+
text: string;
|
|
94
|
+
/** The first column that was shown (1-based, includes truncated before portion) */
|
|
95
|
+
visibleStartCol: number;
|
|
96
|
+
/** The last column that was shown (1-based, includes truncated after portion) */
|
|
97
|
+
visibleEndCol: number;
|
|
98
|
+
/** The start column of the main range (1-based, the focused portion) */
|
|
99
|
+
rangeStartCol: number;
|
|
100
|
+
/** The end column of the main range (1-based, the focused portion) */
|
|
101
|
+
rangeEndCol: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Truncate text to show a specific column range, with ellipsis as needed
|
|
105
|
+
*
|
|
106
|
+
* This function ensures a target range (startCol to endCol) is visible in the output,
|
|
107
|
+
* adding ellipsis at the start, end, or both as needed to fit within maxWidth.
|
|
108
|
+
* All ANSI codes and OSC 8 hyperlinks are preserved.
|
|
109
|
+
*
|
|
110
|
+
* @param text - Text that may contain ANSI escape codes
|
|
111
|
+
* @param maxWidth - Maximum visual width (number of visible characters)
|
|
112
|
+
* @param targetStartCol - Start column of target range (1-based)
|
|
113
|
+
* @param targetEndCol - End column of target range (1-based, optional)
|
|
114
|
+
* @param maxColumn - Maximum column to show (optional, for limiting display)
|
|
115
|
+
* @returns Truncated text with target range visible, ANSI codes preserved, and visible range info
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* truncateFocusRange('console.log("hello world");', 20, 1, 11)
|
|
119
|
+
* // Returns text showing columns 1-11 with ellipsis if needed
|
|
120
|
+
*/
|
|
121
|
+
export declare function truncateFocusRange(text: string, maxWidth: number, targetStartCol: number, targetEndCol?: number, maxColumn?: number): TruncateFocusRangeResult;
|
|
62
122
|
/**
|
|
63
123
|
* Wrap text to fit within a width, breaking on spaces
|
|
64
124
|
* Never breaks words mid-word - if a word is too long, it will extend the line
|
package/lib/utils/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAwDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAwDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EA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