terminal-richjs 0.1.1 → 0.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
- # RichJS
1
+ # terminal-richjs
2
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.
3
+ **terminal-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
4
 
5
5
  ![License](https://img.shields.io/badge/license-MIT-blue.svg)
6
6
  ![TypeScript](https://img.shields.io/badge/language-TypeScript-blue.svg)
@@ -18,33 +18,160 @@ pnpm add terminal-richjs
18
18
 
19
19
  ## 🚀 Quick Start
20
20
 
21
- The easiest way to get started is to import `Console` and print some text.
22
-
23
21
  ```typescript
24
- import { Console } from 'terminal-richjs';
22
+ import { Console, replaceEmoji } from 'terminal-richjs';
25
23
 
26
24
  const console = new Console();
27
25
 
28
26
  console.print('Hello, [bold magenta]World[/bold magenta]!');
29
- console.print('RichJS supports [italic]styles[/], emojis :rocket:, and more.');
27
+ console.print(replaceEmoji('RichJS supports emojis :rocket: and styles :sparkles:'));
30
28
  ```
31
29
 
32
30
  ## ✨ Features
33
31
 
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`
32
+ | Feature | Description |
33
+ | ----------------------- | ------------------------------------------------------------- |
34
+ | **Rich Text** | Parse markup for color and style (`[red]bold[/red]`) |
35
+ | **Emoji Shortcodes** | 174 emojis like `:rocket:` 🚀, `:heart:` ❤️ |
36
+ | **JSON Rendering** | Pretty-printed, syntax-highlighted JSON output |
37
+ | **Columns Layout** | Responsive multi-column displays |
38
+ | **Spinners** | 45 animated spinner styles (dots, stars, moon, hearts...) |
39
+ | **Live Display** | Real-time terminal updates |
40
+ | **Status Indicator** | Animated spinners with messages |
41
+ | **Syntax Highlighting** | Token-based highlighting (Monokai, Dracula, GitHub, One Dark) |
42
+ | **Tables** | Auto-formatting with headers, footers, zebra striping |
43
+ | **Progress Bars** | Multi-bar progress with gradient colors |
44
+ | **Panels** | Bordered containers with titles and subtitles |
45
+ | **Tree Views** | Hierarchical data with customizable guide styles |
46
+ | **Tracebacks** | Beautiful error traces with code snippets |
47
+ | **Markdown** | Render Markdown files to the terminal |
48
+ | **Layouts** | Split terminal into flexible grids |
49
+ | **Logging** | Formatted log output with `RichHandler` |
50
+
51
+ ---
52
+
53
+ ## 🎯 Emoji Shortcodes
44
54
 
45
- ## 🎨 Color Support
55
+ ```typescript
56
+ import { replaceEmoji, EMOJI, listEmoji } from 'terminal-richjs';
57
+
58
+ // Replace shortcodes in text
59
+ console.log(replaceEmoji('Hello :wave: World :rocket:'));
60
+ // Output: Hello 👋 World 🚀
61
+
62
+ // Access emoji directly
63
+ console.log(EMOJI['fire']); // 🔥
64
+ console.log(EMOJI['heart']); // ❤️
65
+
66
+ // List all available emojis (174 total)
67
+ console.log(listEmoji().slice(0, 10));
68
+ // ['rocket', 'star', 'fire', 'heart', 'check', 'warning', ...]
69
+ ```
70
+
71
+ **Popular shortcodes:** `:rocket:` 🚀, `:fire:` 🔥, `:heart:` ❤️, `:star:` ⭐, `:check:` ✅, `:warning:` ⚠️, `:sparkles:` ✨, `:party:` 🎉, `:coffee:` ☕, `:bug:` 🐛
72
+
73
+ ---
74
+
75
+ ## 📋 JSON Pretty Printing
76
+
77
+ ```typescript
78
+ import { Console, JSON, Panel } from 'terminal-richjs';
79
+
80
+ const data = {
81
+ name: 'terminal-richjs',
82
+ version: '0.2.0',
83
+ features: ['emoji', 'json', 'columns', 'spinners'],
84
+ config: { theme: 'dracula', colors: true },
85
+ };
86
+
87
+ new Console().print(
88
+ new Panel(JSON.fromData(data, { sortKeys: true }), { title: 'package.json', box: 'rounded' }),
89
+ );
90
+ ```
91
+
92
+ Options: `indent`, `sortKeys`, `highlight`
93
+
94
+ ---
46
95
 
47
- RichJS supports multiple color formats:
96
+ ## 🎨 Columns Layout
97
+
98
+ ```typescript
99
+ import { Console, Columns } from 'terminal-richjs';
100
+
101
+ const files = [
102
+ '📁 src',
103
+ '📁 dist',
104
+ '📁 node_modules',
105
+ '📄 package.json',
106
+ '📄 tsconfig.json',
107
+ '📄 README.md',
108
+ '📄 LICENSE',
109
+ '📁 examples',
110
+ ];
111
+
112
+ new Console().print(new Columns(files, { padding: 2, equal: true }));
113
+ ```
114
+
115
+ **Output:**
116
+
117
+ ```
118
+ 📁 src 📁 dist 📁 node_modules
119
+ 📄 package.json 📄 tsconfig.json 📄 README.md
120
+ 📄 LICENSE 📁 examples
121
+ ```
122
+
123
+ Options: `width`, `padding`, `equal`, `columnFirst`, `rightToLeft`
124
+
125
+ ---
126
+
127
+ ## ⚙️ Spinners (45 Styles)
128
+
129
+ ```typescript
130
+ import { Spinner, listSpinners, Status, sleep } from 'terminal-richjs';
131
+
132
+ // Create a spinner
133
+ const spinner = new Spinner('dots', { text: 'Loading...', style: 'green' });
134
+ console.log(spinner.getCurrentFrame());
135
+
136
+ // Available spinners
137
+ console.log(listSpinners());
138
+ // ['dots', 'dots2', 'line', 'star', 'moon', 'hearts', 'clock', 'earth', ...]
139
+
140
+ // Status indicator (animated)
141
+ const status = new Status('Processing...', { spinnerName: 'dots' });
142
+ status.start();
143
+ await sleep(2000);
144
+ status.update('Almost done...');
145
+ await sleep(1000);
146
+ status.stop();
147
+ ```
148
+
149
+ ---
150
+
151
+ ## ⚡ Live Display
152
+
153
+ ```typescript
154
+ import { Live, sleep, Style, replaceEmoji } from 'terminal-richjs';
155
+
156
+ const live = new Live();
157
+
158
+ await live.start(async (update) => {
159
+ for (let i = 0; i <= 100; i++) {
160
+ const filled = Math.floor(i / 5);
161
+ const remaining = 20 - filled;
162
+ const bar =
163
+ Style.parse('#50fa7b').apply('━'.repeat(filled)) +
164
+ Style.parse('#3a3a3a dim').apply('━'.repeat(remaining));
165
+
166
+ update(replaceEmoji(`:rocket: Processing... ${bar} ${i}%`));
167
+ await sleep(50);
168
+ }
169
+ });
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 🎨 Color Support
48
175
 
49
176
  ```typescript
50
177
  // Named colors
@@ -53,7 +180,6 @@ console.print('[bright_cyan]Bright cyan[/bright_cyan]');
53
180
 
54
181
  // Hex colors
55
182
  console.print('[#ff79c6]Dracula Pink[/#ff79c6]');
56
- console.print('[#50fa7b]Dracula Green[/#50fa7b]');
57
183
 
58
184
  // RGB colors
59
185
  console.print('[rgb(255,121,198)]Custom RGB[/rgb(255,121,198)]');
@@ -65,6 +191,8 @@ console.print('[color(196)]256-color red[/color(196)]');
65
191
  console.print('[on #282a36]Dark background[/on #282a36]');
66
192
  ```
67
193
 
194
+ ---
195
+
68
196
  ## 📊 Tables
69
197
 
70
198
  ```typescript
@@ -74,7 +202,6 @@ const table = new Table({
74
202
  title: 'Star Wars Movies',
75
203
  box: 'rounded',
76
204
  rowStyles: ['', 'dim'], // Zebra striping
77
- caption: 'Box office data (USD)',
78
205
  });
79
206
 
80
207
  table.addColumn('Released', { justify: 'left' });
@@ -88,19 +215,7 @@ table.addRow('2015', 'The Force Awakens', '$2,068,223,624');
88
215
  new Console().print(table);
89
216
  ```
90
217
 
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
- ```
218
+ ---
104
219
 
105
220
  ## 💻 Syntax Highlighting
106
221
 
@@ -115,18 +230,15 @@ const code = `function fibonacci(n: number): number {
115
230
  const syntax = new Syntax(code, 'typescript', {
116
231
  theme: 'monokai',
117
232
  lineNumbers: true,
118
- highlightLines: [3], // Highlight specific lines
233
+ highlightLines: [3],
119
234
  });
120
235
 
121
- new Console().print(
122
- new Panel(syntax, {
123
- title: 'Fibonacci',
124
- titleAlign: 'left',
125
- }),
126
- );
236
+ new Console().print(new Panel(syntax, { title: 'Fibonacci' }));
127
237
  ```
128
238
 
129
- **Available themes:** `monokai`, `dracula`, `github`, `one-dark`
239
+ **Themes:** `monokai`, `dracula`, `github`, `one-dark`
240
+
241
+ ---
130
242
 
131
243
  ## 🌳 Tree Views
132
244
 
@@ -138,7 +250,6 @@ const src = tree.add('📁 src');
138
250
  src.add('📄 index.ts');
139
251
  src.add('📄 utils.ts');
140
252
  tree.add('📄 package.json');
141
- tree.add('📄 README.md');
142
253
 
143
254
  new Console().print(tree);
144
255
  ```
@@ -150,10 +261,11 @@ new Console().print(tree);
150
261
  ├── 📁 src
151
262
  │ ├── 📄 index.ts
152
263
  │ └── 📄 utils.ts
153
- ├── 📄 package.json
154
- └── 📄 README.md
264
+ └── 📄 package.json
155
265
  ```
156
266
 
267
+ ---
268
+
157
269
  ## 📦 Panels
158
270
 
159
271
  ```typescript
@@ -164,30 +276,23 @@ new Console().print(
164
276
  title: 'Greeting',
165
277
  titleAlign: 'left',
166
278
  subtitle: 'A simple example',
167
- subtitleAlign: 'right',
168
279
  box: 'rounded',
169
280
  borderStyle: 'cyan',
170
281
  }),
171
282
  );
172
283
  ```
173
284
 
174
- ## 🚨 Tracebacks
285
+ ---
175
286
 
176
- Beautiful error traces with syntax-highlighted code:
287
+ ## 🚨 Tracebacks
177
288
 
178
289
  ```typescript
179
- import { installTracebackHandler } from 'terminal-richjs';
290
+ import { installTracebackHandler, Console, Traceback } from 'terminal-richjs';
180
291
 
181
- // Install globally for all uncaught exceptions
182
- installTracebackHandler({
183
- theme: 'monokai',
184
- extraLines: 3,
185
- suppressInternal: true,
186
- });
292
+ // Install globally
293
+ installTracebackHandler({ theme: 'monokai', extraLines: 3 });
187
294
 
188
295
  // Or render manually
189
- import { Console, Traceback } from 'terminal-richjs';
190
-
191
296
  try {
192
297
  throw new Error('Something went wrong');
193
298
  } catch (error) {
@@ -195,43 +300,90 @@ try {
195
300
  }
196
301
  ```
197
302
 
198
- ## 📈 Progress Bars
303
+ ---
199
304
 
200
- ```typescript
201
- import { Console, Progress, ProgressBar } from 'terminal-richjs';
305
+ ## 🎯 Examples
202
306
 
203
- // Simple progress bar
204
- const bar = new ProgressBar(100, 75, {
205
- completeStyle: '#61afef',
206
- remainingStyle: 'dim',
207
- });
208
- new Console().print(bar);
307
+ Run the demos:
209
308
 
210
- // Multi-task progress
211
- const progress = new Progress();
212
- const task1 = progress.addTask('Downloading', 100);
213
- const task2 = progress.addTask('Processing', 50);
309
+ ```bash
310
+ # New features demo (Emoji, JSON, Columns, Spinners, Live)
311
+ npx tsx examples/new-features-demo.ts
214
312
 
215
- await progress.start(async () => {
216
- while (!task1.completed) {
217
- task1.advance(1);
218
- await sleep(10);
219
- }
220
- });
313
+ # Full visual demo
314
+ npx tsx examples/visual-polish-demo.ts
221
315
  ```
222
316
 
223
- ## 📚 Documentation
317
+ ---
224
318
 
225
- See [DOCS.md](./DOCS.md) for comprehensive API documentation.
226
-
227
- ## 🎯 Examples
319
+ ## 📚 API Reference
228
320
 
229
- Run the visual demo:
321
+ ### Core Exports
230
322
 
231
- ```bash
232
- npx tsx examples/visual-polish-demo.ts
323
+ ```typescript
324
+ import {
325
+ // Core
326
+ Console,
327
+ Style,
328
+ Segment,
329
+ MarkupParser,
330
+
331
+ // Renderables
332
+ Panel,
333
+ Table,
334
+ Tree,
335
+ Rule,
336
+ Text,
337
+ Padding,
338
+ Align,
339
+ Columns,
340
+ JSON,
341
+ Syntax,
342
+ Markdown,
343
+
344
+ // Progress & Status
345
+ Progress,
346
+ ProgressBar,
347
+ Spinner,
348
+ Status,
349
+ Live,
350
+ sleep,
351
+
352
+ // Emoji
353
+ replaceEmoji,
354
+ EMOJI,
355
+ listEmoji,
356
+ hasEmoji,
357
+
358
+ // Spinners
359
+ SPINNERS,
360
+ listSpinners,
361
+ getSpinner,
362
+
363
+ // Themes
364
+ Theme,
365
+ MONOKAI,
366
+ DRACULA,
367
+ GITHUB_LIGHT,
368
+ ONE_DARK,
369
+
370
+ // Utilities
371
+ Color,
372
+ getBox,
373
+ listBoxStyles,
374
+
375
+ // Error handling
376
+ Traceback,
377
+ installTracebackHandler,
378
+
379
+ // Logging
380
+ RichHandler,
381
+ Logger,
382
+ } from 'terminal-richjs';
233
383
  ```
234
384
 
385
+ ---
386
+
235
387
  ## 🤝 Contributing
236
388
 
237
389
  Contributions are welcome! Please read our contributing guide.