linecraft 0.2.3 → 0.2.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.
- package/README.md +84 -7
- package/lib/components/code-debug.d.ts +7 -1
- package/lib/components/code-debug.d.ts.map +1 -1
- package/lib/components/code-debug.js +261 -232
- 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 +253 -0
- package/lib/components/code-debug.test.js.map +1 -0
- package/lib/components/progress-bar-grid.d.ts.map +1 -1
- package/lib/components/progress-bar-grid.js +2 -1
- package/lib/components/progress-bar-grid.js.map +1 -1
- package/lib/components/progress-bar-grid.test.js +8 -7
- package/lib/components/progress-bar-grid.test.js.map +1 -1
- package/lib/components/prompt.d.ts.map +1 -1
- package/lib/components/prompt.js +2 -1
- package/lib/components/prompt.js.map +1 -1
- package/lib/components/segments.d.ts.map +1 -1
- package/lib/components/segments.js +0 -7
- package/lib/components/segments.js.map +1 -1
- package/lib/components/style.test.js +12 -11
- package/lib/components/style.test.js.map +1 -1
- package/lib/components/styled.d.ts +1 -0
- package/lib/components/styled.d.ts.map +1 -1
- package/lib/components/styled.js +38 -8
- package/lib/components/styled.js.map +1 -1
- package/lib/components/styled.test.js +12 -11
- package/lib/components/styled.test.js.map +1 -1
- package/lib/layout/grid.d.ts +3 -2
- package/lib/layout/grid.d.ts.map +1 -1
- package/lib/layout/grid.js +166 -81
- package/lib/layout/grid.js.map +1 -1
- package/lib/layout/grid.test.js +70 -3
- package/lib/layout/grid.test.js.map +1 -1
- package/lib/native/diff.d.ts.map +1 -1
- package/lib/native/diff.js +2 -1
- package/lib/native/diff.js.map +1 -1
- package/lib/native/diff.test.js.map +1 -1
- package/lib/native/region-old.js +4 -4
- package/lib/native/region-old.js.map +1 -1
- package/lib/native/region-renderer.d.ts +3 -2
- package/lib/native/region-renderer.d.ts.map +1 -1
- package/lib/native/region-renderer.js +39 -9
- package/lib/native/region-renderer.js.map +1 -1
- package/lib/native/region-simple.d.ts.map +1 -1
- package/lib/native/region-simple.js +1 -1
- package/lib/native/region-simple.js.map +1 -1
- package/lib/region.d.ts +3 -3
- package/lib/region.d.ts.map +1 -1
- package/lib/region.js +15 -66
- package/lib/region.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/colors.d.ts.map +1 -1
- package/lib/utils/colors.js +3 -0
- package/lib/utils/colors.js.map +1 -1
- package/lib/utils/cursor-position.d.ts.map +1 -1
- package/lib/utils/cursor-position.js +4 -15
- package/lib/utils/cursor-position.js.map +1 -1
- package/lib/utils/prompt.js +3 -3
- package/lib/utils/prompt.js.map +1 -1
- package/lib/utils/terminal-theme.d.ts +5 -4
- package/lib/utils/terminal-theme.d.ts.map +1 -1
- package/lib/utils/terminal-theme.js +7 -6
- package/lib/utils/terminal-theme.js.map +1 -1
- package/lib/utils/text.d.ts +91 -2
- package/lib/utils/text.d.ts.map +1 -1
- package/lib/utils/text.js +765 -72
- 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.d.ts.map +1 -1
- package/lib/utils/wait-for-spacebar.js +2 -9
- package/lib/utils/wait-for-spacebar.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -41,6 +41,49 @@ r.set(
|
|
|
41
41
|
r.destroy(true);
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
## Terminal Management Features
|
|
45
|
+
|
|
46
|
+
Linecraft provides advanced terminal management capabilities that go beyond basic terminal logging:
|
|
47
|
+
|
|
48
|
+
### Color-Aware Line Wrapping
|
|
49
|
+
|
|
50
|
+
Unlike basic terminal output, Linecraft's text wrapping is **fully ANSI-aware**. When text wraps across multiple lines, ANSI color codes are preserved and correctly re-applied to each wrapped line. This means:
|
|
51
|
+
|
|
52
|
+
- **Color preservation**: Colored text maintains its styling across line breaks
|
|
53
|
+
- **Accurate width calculation**: Wrapping is based on visible character width, not raw string length
|
|
54
|
+
- **Smart word breaking**: Text never breaks mid-word, ensuring readability
|
|
55
|
+
- **Multi-line styling**: Complex styled text (like error codes with underlines) wraps correctly
|
|
56
|
+
|
|
57
|
+
This is especially important for components like `CodeDebug`, where error messages with colored error codes need to wrap across multiple lines while maintaining their visual styling.
|
|
58
|
+
|
|
59
|
+
### ANSI Code Handling
|
|
60
|
+
|
|
61
|
+
Linecraft correctly handles ANSI escape sequences throughout the rendering pipeline:
|
|
62
|
+
|
|
63
|
+
- **Width measurement**: All width calculations account for ANSI codes (colors, styles, cursor movements)
|
|
64
|
+
- **Text splitting**: When truncating or splitting text, ANSI codes are preserved and re-applied
|
|
65
|
+
- **Grid layouts**: Grid components correctly measure and align ANSI-styled content
|
|
66
|
+
- **Text alignment**: Alignment operations work correctly with styled text
|
|
67
|
+
|
|
68
|
+
### Terminal State Management
|
|
69
|
+
|
|
70
|
+
Linecraft manages terminal state to prevent common terminal UI issues:
|
|
71
|
+
|
|
72
|
+
- **Auto-wrap disabled**: Prevents unwanted line breaks from terminal auto-wrapping
|
|
73
|
+
- **Cursor positioning**: Precise cursor control using absolute positioning
|
|
74
|
+
- **Viewport awareness**: Only renders visible content within the terminal viewport
|
|
75
|
+
- **Clean restoration**: Properly restores terminal state on cleanup
|
|
76
|
+
|
|
77
|
+
### Responsive Layouts
|
|
78
|
+
|
|
79
|
+
Components automatically adapt to terminal size changes:
|
|
80
|
+
|
|
81
|
+
- **Grid layouts**: Flex columns adjust to available width
|
|
82
|
+
- **Text wrapping**: Wraps at appropriate boundaries based on terminal width
|
|
83
|
+
- **Component sizing**: Components receive updated `availableWidth` context on resize
|
|
84
|
+
|
|
85
|
+
These features make Linecraft suitable for building complex, interactive terminal UIs that work reliably across different terminal sizes and configurations.
|
|
86
|
+
|
|
44
87
|
## Performance
|
|
45
88
|
|
|
46
89
|
Linecraft is built for high-performance terminal rendering from Node.js. The renderer includes several optimizations to minimize terminal updates and CPU usage:
|
|
@@ -99,6 +142,36 @@ ref.delete(); // Remove it
|
|
|
99
142
|
r.destroy(true); // Clean up and restore terminal (true = clear first)
|
|
100
143
|
```
|
|
101
144
|
|
|
145
|
+
## Semantic Themes
|
|
146
|
+
|
|
147
|
+
Linecraft includes a built-in semantic theme system that automatically adapts colors based on whether the terminal is in light or dark mode. Instead of hardcoding ANSI colors, you can use semantic tokens:
|
|
148
|
+
|
|
149
|
+
- `base`: The default text color (gray in both themes)
|
|
150
|
+
- `muted`: Dimmed text for line numbers or separators (dimmed white on dark, dimmed gray on light)
|
|
151
|
+
- `highlight`: Emphasized text (white on dark, bold black on light)
|
|
152
|
+
- `accent`: Primary accent color (bold blue in both themes)
|
|
153
|
+
- `location`: For file paths and locations (magenta in both themes)
|
|
154
|
+
- `success`: Success messages (bright green on dark, green on light)
|
|
155
|
+
- `warning`: Warning messages (bright yellow on dark, bright magenta on light)
|
|
156
|
+
- `error`: Error messages (bright red on dark, red on light)
|
|
157
|
+
- `info`: Informational messages (blue in both themes)
|
|
158
|
+
|
|
159
|
+
You can use these tokens anywhere a `Color` is expected:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { Styled } from 'linecraft';
|
|
163
|
+
|
|
164
|
+
// Automatically uses appropriate color based on terminal theme
|
|
165
|
+
const text = Styled({ color: 'base' }, 'Auto-themed text');
|
|
166
|
+
const error = Styled({ color: 'error' }, 'Error message');
|
|
167
|
+
const path = Styled({ color: 'location' }, '/path/to/file.ts');
|
|
168
|
+
|
|
169
|
+
// You can also resolve them manually if needed
|
|
170
|
+
import { autoColor, autoStyle } from 'linecraft';
|
|
171
|
+
const color = autoColor('warning'); // Returns just the color
|
|
172
|
+
const style = autoStyle('accent'); // Returns full TextStyle (color, bold, etc.)
|
|
173
|
+
```
|
|
174
|
+
|
|
102
175
|
## Components
|
|
103
176
|
|
|
104
177
|
### Styled
|
|
@@ -150,7 +223,7 @@ r.set(Section(
|
|
|
150
223
|
|
|
151
224
|
### CodeDebug
|
|
152
225
|
|
|
153
|
-
Display code errors and warnings with line numbers, context, and clickable file paths.
|
|
226
|
+
Display code errors and warnings with line numbers, context, and clickable file paths. Perfect for linters, compilers, and development tools that need to show diagnostic information.
|
|
154
227
|
|
|
155
228
|

|
|
156
229
|
|
|
@@ -166,6 +239,8 @@ r.set(CodeDebug({
|
|
|
166
239
|
lineBefore: ' async function load() {',
|
|
167
240
|
lineAfter: ' return process(result);',
|
|
168
241
|
message: 'Type error: fetchData is not defined',
|
|
242
|
+
errorCode: 'typescript(2304)', // Optional: error code with underline
|
|
243
|
+
shortMessage: 'not defined', // Optional: short message connected to underline
|
|
169
244
|
filePath: 'src/loaders/data.ts',
|
|
170
245
|
fullPath: '/absolute/path/to/src/loaders/data.ts',
|
|
171
246
|
baseDir: process.cwd(),
|
|
@@ -174,12 +249,14 @@ r.set(CodeDebug({
|
|
|
174
249
|
```
|
|
175
250
|
|
|
176
251
|
**Features:**
|
|
177
|
-
-
|
|
178
|
-
-
|
|
179
|
-
-
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
252
|
+
- **OSC 8 Hyperlinks**: File paths are clickable in modern terminals (VS Code, iTerm2, etc.). Ctrl+Click (or Cmd+Click) opens the file at the correct line and column.
|
|
253
|
+
- **Smart Line Overflow**: Long code lines automatically truncate with ellipsis while keeping the error range visible. Supports ellipsis at start, end, or both sides.
|
|
254
|
+
- **Error Range Highlighting**: The error range (startColumn to endColumn) is highlighted with a brighter color for easy identification.
|
|
255
|
+
- **Context Lines**: Show lines before and after the error for better context (slightly dimmed for visual hierarchy).
|
|
256
|
+
- **Message Wrapping**: Long error messages wrap across multiple lines while preserving ANSI styling and color codes.
|
|
257
|
+
- **Terminal Theme Adaptation**: Line numbers and colors adapt to dark/light terminal themes automatically.
|
|
258
|
+
- **Curved Underlines**: Visual indicators with curved edges (┖─┚) point to the exact error location, with optional T-bar for short messages.
|
|
259
|
+
- **Responsive Layout**: Automatically adjusts to terminal width, truncating paths and code as needed.
|
|
183
260
|
|
|
184
261
|
### Spinner
|
|
185
262
|
|
|
@@ -15,8 +15,14 @@ export interface CodeDebugOptions {
|
|
|
15
15
|
errorLine: string;
|
|
16
16
|
/** Source code line after the error line (optional) */
|
|
17
17
|
lineAfter?: string | null;
|
|
18
|
-
/** Error or warning message */
|
|
18
|
+
/** Error or warning message (long message shown at top) */
|
|
19
19
|
message: string;
|
|
20
|
+
/** Error code/preamble to show before message (e.g., "eslint-plugin-unicorn(no-useless-length-check)") (optional) */
|
|
21
|
+
errorCode?: string;
|
|
22
|
+
/** Short message to show connected to underline (optional) */
|
|
23
|
+
shortMessage?: string;
|
|
24
|
+
/** Placement of short message: 'left' or 'right' (default: 'right', auto: 'left' when target is near end of long line) */
|
|
25
|
+
shortMessagePlacement?: 'left' | 'right' | 'auto';
|
|
20
26
|
/** Short file path to display */
|
|
21
27
|
filePath: string;
|
|
22
28
|
/** Full resolved file path for clickable link */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-debug.d.ts","sourceRoot":"","sources":["../../src/components/code-debug.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"code-debug.d.ts","sourceRoot":"","sources":["../../src/components/code-debug.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAWhE,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,qHAAqH;IACrH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0HAA0H;IAC1H,qBAAqB,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAClD,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA8Y9D"}
|