terminal-richjs 0.1.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/README.md +241 -0
- package/dist/index.cjs +2738 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +751 -0
- package/dist/index.d.ts +751 -0
- package/dist/index.js +2674 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.cjs +4 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/logging.d.cts +2 -0
- package/dist/logging.d.ts +2 -0
- package/dist/logging.js +3 -0
- package/dist/logging.js.map +1 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# RichJS
|
|
2
|
+
|
|
3
|
+
**RichJS** is a TypeScript library for writing rich text (with color and style) to the terminal, and for displaying advanced content such as tables, markdown, and syntax highlighted code. It is heavily inspired by the popular [Python Rich](https://github.com/Textualize/rich) library.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install richjs
|
|
13
|
+
# or
|
|
14
|
+
yarn add richjs
|
|
15
|
+
# or
|
|
16
|
+
pnpm add richjs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
The easiest way to get started is to import `Console` and print some text.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Console } from 'richjs';
|
|
25
|
+
|
|
26
|
+
const console = new Console();
|
|
27
|
+
|
|
28
|
+
console.print('Hello, [bold magenta]World[/bold magenta]!');
|
|
29
|
+
console.print('RichJS supports [italic]styles[/], emojis :rocket:, and more.');
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## ✨ Features
|
|
33
|
+
|
|
34
|
+
- **Rich Text**: Parse markup for color and style (`[red]bold[/red]`)
|
|
35
|
+
- **Syntax Highlighting**: Token-based highlighting with multiple themes (Monokai, Dracula, GitHub, One Dark)
|
|
36
|
+
- **Tables**: Auto-formatting tables with headers, footers, and zebra striping
|
|
37
|
+
- **Progress Bars**: Multi-bar progress tracking with live updates and gradient colors
|
|
38
|
+
- **Panels**: Bordered containers with titles, subtitles, and alignment options
|
|
39
|
+
- **Tree Views**: Visualize hierarchical data with customizable guide styles
|
|
40
|
+
- **Tracebacks**: Beautiful error traces with syntax-highlighted code snippets
|
|
41
|
+
- **Markdown**: Render Markdown files directly to the terminal
|
|
42
|
+
- **Layouts**: Split your terminal into flexible grids and rows/columns
|
|
43
|
+
- **Logging**: Formatted log output with `RichHandler`
|
|
44
|
+
|
|
45
|
+
## 🎨 Color Support
|
|
46
|
+
|
|
47
|
+
RichJS supports multiple color formats:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Named colors
|
|
51
|
+
console.print('[red]Red text[/red]');
|
|
52
|
+
console.print('[bright_cyan]Bright cyan[/bright_cyan]');
|
|
53
|
+
|
|
54
|
+
// Hex colors
|
|
55
|
+
console.print('[#ff79c6]Dracula Pink[/#ff79c6]');
|
|
56
|
+
console.print('[#50fa7b]Dracula Green[/#50fa7b]');
|
|
57
|
+
|
|
58
|
+
// RGB colors
|
|
59
|
+
console.print('[rgb(255,121,198)]Custom RGB[/rgb(255,121,198)]');
|
|
60
|
+
|
|
61
|
+
// 256-color palette
|
|
62
|
+
console.print('[color(196)]256-color red[/color(196)]');
|
|
63
|
+
|
|
64
|
+
// Background colors
|
|
65
|
+
console.print('[on #282a36]Dark background[/on #282a36]');
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 📊 Tables
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Console, Table } from 'richjs';
|
|
72
|
+
|
|
73
|
+
const table = new Table({
|
|
74
|
+
title: 'Star Wars Movies',
|
|
75
|
+
box: 'rounded',
|
|
76
|
+
rowStyles: ['', 'dim'], // Zebra striping
|
|
77
|
+
caption: 'Box office data (USD)',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
table.addColumn('Released', { justify: 'left' });
|
|
81
|
+
table.addColumn('Title', { justify: 'left' });
|
|
82
|
+
table.addColumn('Box Office', { justify: 'right' });
|
|
83
|
+
|
|
84
|
+
table.addRow('1977', 'A New Hope', '$775,398,007');
|
|
85
|
+
table.addRow('1980', 'The Empire Strikes Back', '$538,375,067');
|
|
86
|
+
table.addRow('2015', 'The Force Awakens', '$2,068,223,624');
|
|
87
|
+
|
|
88
|
+
new Console().print(table);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Output:**
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
Star Wars Movies
|
|
95
|
+
╭──────────┬─────────────────────────┬────────────────╮
|
|
96
|
+
│ Released │ Title │ Box Office │
|
|
97
|
+
├──────────┼─────────────────────────┼────────────────┤
|
|
98
|
+
│ 1977 │ A New Hope │ $775,398,007 │
|
|
99
|
+
│ 1980 │ The Empire Strikes Back │ $538,375,067 │
|
|
100
|
+
│ 2015 │ The Force Awakens │ $2,068,223,624 │
|
|
101
|
+
╰──────────┴─────────────────────────┴────────────────╯
|
|
102
|
+
Box office data (USD)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 💻 Syntax Highlighting
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { Console, Syntax, Panel } from 'richjs';
|
|
109
|
+
|
|
110
|
+
const code = `function fibonacci(n: number): number {
|
|
111
|
+
if (n <= 1) return n;
|
|
112
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
113
|
+
}`;
|
|
114
|
+
|
|
115
|
+
const syntax = new Syntax(code, 'typescript', {
|
|
116
|
+
theme: 'monokai',
|
|
117
|
+
lineNumbers: true,
|
|
118
|
+
highlightLines: [3], // Highlight specific lines
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
new Console().print(
|
|
122
|
+
new Panel(syntax, {
|
|
123
|
+
title: 'Fibonacci',
|
|
124
|
+
titleAlign: 'left',
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Available themes:** `monokai`, `dracula`, `github`, `one-dark`
|
|
130
|
+
|
|
131
|
+
## 🌳 Tree Views
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { Console, Tree } from 'richjs';
|
|
135
|
+
|
|
136
|
+
const tree = new Tree('📁 project');
|
|
137
|
+
const src = tree.add('📁 src');
|
|
138
|
+
src.add('📄 index.ts');
|
|
139
|
+
src.add('📄 utils.ts');
|
|
140
|
+
tree.add('📄 package.json');
|
|
141
|
+
tree.add('📄 README.md');
|
|
142
|
+
|
|
143
|
+
new Console().print(tree);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Output:**
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
📁 project
|
|
150
|
+
├── 📁 src
|
|
151
|
+
│ ├── 📄 index.ts
|
|
152
|
+
│ └── 📄 utils.ts
|
|
153
|
+
├── 📄 package.json
|
|
154
|
+
└── 📄 README.md
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 📦 Panels
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { Console, Panel } from 'richjs';
|
|
161
|
+
|
|
162
|
+
new Console().print(
|
|
163
|
+
new Panel('Hello, World!', {
|
|
164
|
+
title: 'Greeting',
|
|
165
|
+
titleAlign: 'left',
|
|
166
|
+
subtitle: 'A simple example',
|
|
167
|
+
subtitleAlign: 'right',
|
|
168
|
+
box: 'rounded',
|
|
169
|
+
borderStyle: 'cyan',
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 🚨 Tracebacks
|
|
175
|
+
|
|
176
|
+
Beautiful error traces with syntax-highlighted code:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { installTracebackHandler } from 'richjs';
|
|
180
|
+
|
|
181
|
+
// Install globally for all uncaught exceptions
|
|
182
|
+
installTracebackHandler({
|
|
183
|
+
theme: 'monokai',
|
|
184
|
+
extraLines: 3,
|
|
185
|
+
suppressInternal: true,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Or render manually
|
|
189
|
+
import { Console, Traceback } from 'richjs';
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
throw new Error('Something went wrong');
|
|
193
|
+
} catch (error) {
|
|
194
|
+
new Console().print(new Traceback(error));
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 📈 Progress Bars
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { Console, Progress, ProgressBar } from 'richjs';
|
|
202
|
+
|
|
203
|
+
// Simple progress bar
|
|
204
|
+
const bar = new ProgressBar(100, 75, {
|
|
205
|
+
completeStyle: '#61afef',
|
|
206
|
+
remainingStyle: 'dim',
|
|
207
|
+
});
|
|
208
|
+
new Console().print(bar);
|
|
209
|
+
|
|
210
|
+
// Multi-task progress
|
|
211
|
+
const progress = new Progress();
|
|
212
|
+
const task1 = progress.addTask('Downloading', 100);
|
|
213
|
+
const task2 = progress.addTask('Processing', 50);
|
|
214
|
+
|
|
215
|
+
await progress.start(async () => {
|
|
216
|
+
while (!task1.completed) {
|
|
217
|
+
task1.advance(1);
|
|
218
|
+
await sleep(10);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## 📚 Documentation
|
|
224
|
+
|
|
225
|
+
See [DOCS.md](./DOCS.md) for comprehensive API documentation.
|
|
226
|
+
|
|
227
|
+
## 🎯 Examples
|
|
228
|
+
|
|
229
|
+
Run the visual demo:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npx tsx examples/visual-polish-demo.ts
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🤝 Contributing
|
|
236
|
+
|
|
237
|
+
Contributions are welcome! Please read our contributing guide.
|
|
238
|
+
|
|
239
|
+
## 📄 License
|
|
240
|
+
|
|
241
|
+
MIT
|