rich-ruby 1.0.1 → 1.0.2

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.
data/README.md CHANGED
@@ -1,547 +1,547 @@
1
- # Rich Ruby (rich-ruby)
2
-
3
- A Pure Ruby library for rich text and beautiful formatting in the terminal.
4
-
5
- Rich Ruby provides an elegant API for creating stylish terminal output with colors,
6
- tables, panels, trees, progress bars, syntax highlighting, and more. It is inspired
7
- by the Python Rich library but is a complete Ruby-native implementation.
8
-
9
- ---
10
-
11
- ## Table of Contents
12
-
13
- 1. [Features](#features)
14
- 2. [Requirements](#requirements)
15
- 3. [Installation](#installation)
16
- 4. [Quick Start](#quick-start)
17
- 5. [Usage Guide](#usage-guide)
18
- - [Colors and Styles](#colors-and-styles)
19
- - [Text and Markup](#text-and-markup)
20
- - [Panels](#panels)
21
- - [Tables](#tables)
22
- - [Trees](#trees)
23
- - [Progress Bars and Spinners](#progress-bars-and-spinners)
24
- - [Syntax Highlighting](#syntax-highlighting)
25
- - [Markdown Rendering](#markdown-rendering)
26
- - [JSON Output](#json-output)
27
- 6. [API Reference](#api-reference)
28
- 7. [Testing](#testing)
29
- 8. [License](#license)
30
-
31
- ---
32
-
33
- ## Features
34
-
35
- - **Colors**: Full support for 16-color, 256-color, and TrueColor (24-bit) terminals
36
- - **Styles**: Bold, italic, underline, strikethrough, blink, reverse, and more
37
- - **Markup**: Simple markup syntax like `[bold red]text[/]` for inline styling
38
- - **Panels**: Bordered boxes with titles and subtitles
39
- - **Tables**: Data tables with column alignment and styling
40
- - **Trees**: Hierarchical tree views with different guide styles
41
- - **Progress**: Animated progress bars and spinners
42
- - **Syntax**: Code syntax highlighting for Ruby, Python, JavaScript, SQL, and more
43
- - **Markdown**: Render Markdown documents in the terminal
44
- - **Windows**: Full Windows Console API support with automatic ANSI enabling
45
- - **Zero Dependencies**: Pure Ruby with no external gem dependencies
46
-
47
- ---
48
-
49
- ## Requirements
50
-
51
- This library was developed and tested on:
52
-
53
- - **Ruby**: 3.4.8 (MSVC build)
54
- - **Platform**: Windows 10 64-bit (21H2)
55
- - **Compiler**: Visual Studio 2026 (MSVC)
56
-
57
- The library should work on:
58
-
59
- - Ruby 3.0 or later
60
- - Windows, macOS, Linux
61
- - Any terminal supporting ANSI escape codes
62
-
63
- ### Windows Native Support
64
-
65
- For Windows users, the library provides **native integration** with the Windows Console API using [Fiddle](https://ruby-doc.org/stdlib/libdoc/fiddle/rdoc/Fiddle.html). This allows it to:
66
-
67
- 1. **Enable ANSI/VT Processing**: Automatically configures the console to handle ANSI escape codes, even on older versions of Windows 10.
68
- 2. **Fallback to Console API**: On legacy systems where ANSI is not supported, it uses the Windows Console API (e.g., `SetConsoleTextAttribute`) to provide color and styling.
69
- 3. **Accurate Console Dimensions**: Uses native API calls to determine the exact width and height of the console window.
70
- 4. **Hardware Features**: Full control over cursor visibility, window titles, and screen clearing via native calls.
71
-
72
- This works out-of-the-box with Windows Terminal, PowerShell, and the classic Command Prompt.
73
-
74
- ---
75
-
76
- ## Installation
77
-
78
- ### From RubyGems
79
-
80
- ```bash
81
- gem install rich-ruby
82
- ```
83
-
84
- ### From source
85
-
86
- ```bash
87
- git clone https://github.com/tigel-agm/rich-ruby.git
88
- cd rich
89
- gem build rich-ruby.gemspec
90
- gem install rich-ruby-0.1.0.gem
91
- ```
92
-
93
- ### In your Gemfile
94
-
95
- ```ruby
96
- gem 'rich-ruby'
97
- ```
98
-
99
- ---
100
-
101
- ## Quick Start
102
-
103
- ```ruby
104
- require 'rich'
105
-
106
- # Simple styled output
107
- Rich.print("[bold cyan]Hello[/] [yellow]World![/]")
108
-
109
- # Create a console instance for more control
110
- console = Rich::Console.new
111
- console.print("Welcome!", style: "bold green")
112
-
113
- # Display a panel
114
- panel = Rich::Panel.new(
115
- "This is important information.",
116
- title: "Notice",
117
- border_style: "cyan"
118
- )
119
- puts panel.render(max_width: 50)
120
-
121
- # Display a table
122
- table = Rich::Table.new(title: "Users")
123
- table.add_column("Name", header_style: "bold")
124
- table.add_column("Role")
125
- table.add_row("Alice", "Admin")
126
- table.add_row("Bob", "User")
127
- puts table.render(max_width: 40)
128
- ```
129
-
130
- ---
131
-
132
- ## Documentation
133
-
134
- For more detailed information, check out our guides:
135
-
136
- - [**How-To Use**](docs/how-to-use.md): Tiered guide for all levels.
137
- - [**Troubleshooting & FAQ**](docs/troubleshooting.md): Solutions for common issues.
138
- - [**Customization**](docs/customization.md): Learn how to extend the library.
139
- - [**Cheat Sheet**](docs/cheat-sheet.md): Quick reference for styles and colors.
140
- - [**Windows Notes**](docs/windows-notes.md): Technical details on Windows support.
141
- - [**Architecture**](docs/architecture.md): Internal design and data flow.
142
- - [**Test Report**](docs/test-report.md): Verification and performance results.
143
-
144
- ---
145
-
146
- ## Usage Guide
147
-
148
- ### Colors and Styles
149
-
150
- Rich Ruby supports multiple color systems:
151
-
152
- ```ruby
153
- # Standard 16 colors
154
- style = Rich::Style.parse("red")
155
- style = Rich::Style.parse("bright_blue")
156
-
157
- # 256-color palette
158
- style = Rich::Style.parse("color(42)")
159
-
160
- # TrueColor (24-bit)
161
- style = Rich::Style.parse("#ff5500")
162
- style = Rich::Style.parse("rgb(255, 85, 0)")
163
-
164
- # Background colors
165
- style = Rich::Style.parse("white on blue")
166
- style = Rich::Style.parse("black on #ffcc00")
167
- ```
168
-
169
- Available text attributes:
170
-
171
- | Attribute | Description |
172
- |-----------|-------------|
173
- | `bold` | Bold text |
174
- | `dim` | Dimmed text |
175
- | `italic` | Italic text |
176
- | `underline` | Underlined text |
177
- | `underline2` | Double underline |
178
- | `overline` | Overlined text |
179
- | `blink` | Blinking text |
180
- | `reverse` | Reversed colors |
181
- | `conceal` | Hidden text |
182
- | `strike` | Strikethrough |
183
-
184
- Combine multiple attributes:
185
-
186
- ```ruby
187
- style = Rich::Style.parse("bold italic red on white")
188
- ```
189
-
190
- ### Text and Markup
191
-
192
- The markup syntax provides an easy way to style text inline:
193
-
194
- ```ruby
195
- # Basic markup
196
- Rich.print("[bold]Bold text[/bold]")
197
- Rich.print("[red]Red text[/red]")
198
-
199
- # Shorthand close tag
200
- Rich.print("[bold]Bold text[/]")
201
-
202
- # Nested styles
203
- Rich.print("[bold][red]Bold and red[/red][/bold]")
204
-
205
- # Combined styles
206
- Rich.print("[bold italic cyan on black]Styled[/]")
207
-
208
- # In strings
209
- text = Rich::Markup.parse("Name: [cyan]Alice[/] Age: [yellow]30[/]")
210
- puts Rich::Segment.render(text.to_segments)
211
- ```
212
-
213
- ### Panels
214
-
215
- Create bordered panels to highlight content:
216
-
217
- ```ruby
218
- # Simple panel
219
- panel = Rich::Panel.new("Hello World")
220
- puts panel.render(max_width: 40)
221
-
222
- # Panel with title and subtitle
223
- panel = Rich::Panel.new(
224
- "Important information goes here.",
225
- title: "Alert",
226
- subtitle: "Read carefully",
227
- border_style: "red",
228
- title_style: "bold white"
229
- )
230
- puts panel.render(max_width: 50)
231
-
232
- # Different box styles
233
- panel = Rich::Panel.new("Content", box: Rich::Box::DOUBLE)
234
- panel = Rich::Panel.new("Content", box: Rich::Box::ROUNDED)
235
- panel = Rich::Panel.new("Content", box: Rich::Box::HEAVY)
236
- panel = Rich::Panel.new("Content", box: Rich::Box::ASCII)
237
- ```
238
-
239
- ### Tables
240
-
241
- Create formatted data tables:
242
-
243
- ```ruby
244
- # Create a table
245
- table = Rich::Table.new(title: "Sales Report", border_style: "blue")
246
-
247
- # Add columns with styling
248
- table.add_column("Product", header_style: "bold cyan")
249
- table.add_column("Price", justify: :right, header_style: "bold cyan")
250
- table.add_column("Quantity", justify: :center)
251
-
252
- # Add data rows
253
- table.add_row("Widget", "$10.00", "100")
254
- table.add_row("Gadget", "$25.50", "50")
255
- table.add_row("Gizmo", "$5.99", "200")
256
-
257
- # Render
258
- puts table.render(max_width: 60)
259
- ```
260
-
261
- Column justification options: `:left`, `:center`, `:right`
262
-
263
- ### Trees
264
-
265
- Display hierarchical data:
266
-
267
- ```ruby
268
- # Create a tree
269
- tree = Rich::Tree.new("Project", style: "bold yellow")
270
-
271
- # Add nodes
272
- src = tree.add("src/", style: "bold")
273
- src.add("main.rb", style: "green")
274
- src.add("config.rb", style: "green")
275
-
276
- lib = tree.add("lib/")
277
- lib.add("utils.rb")
278
-
279
- tree.add("README.md", style: "cyan")
280
-
281
- # Render
282
- puts tree.render
283
- ```
284
-
285
- Different guide styles:
286
-
287
- ```ruby
288
- tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::ASCII)
289
- tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::ROUNDED)
290
- tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::BOLD)
291
- ```
292
-
293
- ### Progress Bars and Spinners
294
-
295
- Show progress for long-running tasks:
296
-
297
- ```ruby
298
- # Progress bar
299
- bar = Rich::ProgressBar.new(total: 100, width: 40)
300
-
301
- 100.times do |i|
302
- bar.update(i + 1)
303
- print "\rProgress: #{bar.render}"
304
- sleep(0.05)
305
- end
306
- puts ""
307
-
308
- # Spinner
309
- spinner = Rich::Spinner.new(frames: Rich::ProgressStyle::DOTS)
310
-
311
- 20.times do
312
- print "\r#{spinner.frame} Loading..."
313
- spinner.advance
314
- sleep(0.1)
315
- end
316
- puts "\rDone! "
317
- ```
318
-
319
- Available spinner styles:
320
- - `Rich::ProgressStyle::DOTS`
321
- - `Rich::ProgressStyle::LINE`
322
- - `Rich::ProgressStyle::CIRCLE`
323
- - `Rich::ProgressStyle::BOUNCE`
324
-
325
- ### Syntax Highlighting
326
-
327
- Highlight source code:
328
-
329
- ```ruby
330
- code = <<~RUBY
331
- def greet(name)
332
- puts "Hello, #{name}!"
333
- end
334
- RUBY
335
-
336
- # Basic highlighting
337
- syntax = Rich::Syntax.new(code, language: "ruby")
338
- puts syntax.render
339
-
340
- # With line numbers
341
- syntax = Rich::Syntax.new(code, language: "ruby", line_numbers: true)
342
- puts syntax.render
343
-
344
- # With a theme
345
- syntax = Rich::Syntax.new(code, language: "python", theme: :monokai)
346
- syntax = Rich::Syntax.new(code, language: "javascript", theme: :dracula)
347
- ```
348
-
349
- Supported languages: Ruby, Python, JavaScript, SQL, JSON, YAML, Bash
350
-
351
- Available themes: `:default`, `:monokai`, `:dracula`
352
-
353
- ### Markdown Rendering
354
-
355
- Render Markdown in the terminal:
356
-
357
- ```ruby
358
- markdown = <<~MD
359
- # Welcome
360
-
361
- This is **bold** and *italic* text.
362
-
363
- ## Features
364
-
365
- - Item one
366
- - Item two
367
-
368
- ```ruby
369
- puts "Code block"
370
- ```
371
-
372
- | Column A | Column B |
373
- |----------|----------|
374
- | Value 1 | Value 2 |
375
- MD
376
-
377
- md = Rich::Markdown.new(markdown)
378
- puts md.render(max_width: 70)
379
- ```
380
-
381
- Supported Markdown elements:
382
- - Headings (H1-H6)
383
- - Bold, italic, strikethrough
384
- - Inline code
385
- - Code blocks with language
386
- - Ordered and unordered lists
387
- - Blockquotes
388
- - Tables
389
- - Links
390
- - Horizontal rules
391
-
392
- ### JSON Output
393
-
394
- Pretty-print JSON with syntax highlighting:
395
-
396
- ```ruby
397
- data = {
398
- "name" => "Alice",
399
- "age" => 30,
400
- "active" => true,
401
- "roles" => ["admin", "user"]
402
- }
403
-
404
- puts Rich::JSON.to_s(data)
405
-
406
- # Highlight existing JSON string
407
- json_str = '{"key": "value"}'
408
- puts Rich::JSON.highlight(json_str)
409
- ```
410
-
411
- ---
412
-
413
- ## API Reference
414
-
415
- ### Core Classes
416
-
417
- | Class | Description |
418
- |-------|-------------|
419
- | `Rich::Console` | Main console interface |
420
- | `Rich::Color` | Color representation and parsing |
421
- | `Rich::Style` | Text style with color and attributes |
422
- | `Rich::Segment` | Styled text segment |
423
- | `Rich::Text` | Rich text with spans |
424
- | `Rich::Markup` | Markup parser |
425
-
426
- ### Components
427
-
428
- | Class | Description |
429
- |-------|-------------|
430
- | `Rich::Panel` | Bordered panel |
431
- | `Rich::Table` | Data table |
432
- | `Rich::Tree` | Tree view |
433
- | `Rich::ProgressBar` | Progress bar |
434
- | `Rich::Spinner` | Animated spinner |
435
- | `Rich::Syntax` | Syntax highlighter |
436
- | `Rich::Markdown` | Markdown renderer |
437
- | `Rich::JSON` | JSON formatter |
438
-
439
- ### Module Methods
440
-
441
- ```ruby
442
- Rich.print(*objects, style: nil) # Print with markup support
443
- Rich.print_json(data) # Print formatted JSON
444
- Rich.rule(title) # Print horizontal rule
445
- Rich.get_console # Get global console instance
446
- Rich.reconfigure(**options) # Reconfigure global console
447
- ```
448
-
449
- ---
450
-
451
- ## Testing
452
-
453
- Run the full test suite:
454
-
455
- ```bash
456
- cd rich
457
- ruby -W0 -Ilib -Itest -e "Dir['test/test_*.rb'].each { |f| require_relative f }"
458
- ```
459
-
460
- > [!TIP]
461
- > Use the `-W0` flag to suppress environmental warnings (like the `io-nonblock` extension warning) for a cleaner test output.
462
-
463
- Or with Rake (if rake is available):
464
-
465
- ```bash
466
- rake test
467
- ```
468
-
469
- Run individual test files:
470
-
471
- ```bash
472
- ruby -W0 -Ilib -Itest test/test_color.rb
473
- ruby -W0 -Ilib -Itest test/test_style.rb
474
- ```
475
-
476
- Run stress tests:
477
-
478
- ```bash
479
- ruby examples/stress_test.rb
480
- ```
481
-
482
- ---
483
-
484
- ## Project Structure
485
-
486
- ```
487
- rich/
488
- lib/
489
- rich.rb # Main entry point
490
- rich/
491
- color.rb # Color handling
492
- style.rb # Text styles
493
- text.rb # Rich text
494
- markup.rb # Markup parser
495
- panel.rb # Panel component
496
- table.rb # Table component
497
- tree.rb # Tree component
498
- progress.rb # Progress bars and spinners
499
- syntax.rb # Syntax highlighting
500
- markdown.rb # Markdown rendering
501
- json.rb # JSON formatting
502
- console.rb # Console interface
503
- ...
504
- test/
505
- test_*.rb # Test files
506
- examples/
507
- demo.rb # Basic demo
508
- showcase.rb # Interactive showcase
509
- stress_test.rb # Stress tests
510
- ```
511
-
512
- ---
513
-
514
- ## License
515
-
516
- This project is licensed under the MIT License.
517
-
518
- This means:
519
- - You can use, modify, and distribute this software for any purpose
520
- - You can use it in commercial projects
521
- - You must include the original copyright and license notice
522
-
523
- See the [LICENSE](LICENSE) file for the full license text.
524
-
525
- ---
526
-
527
- ## Credits
528
-
529
- This library is an original Ruby implementation inspired by the concepts of the
530
- Python Rich library by Will McGugan. All code is original and written specifically
531
- for Ruby.
532
-
533
- Developed on Ruby 3.4.8 (MSVC) on Windows 10 64-bit (21H2) with Visual Studio 2026.
534
-
535
- ---
536
-
537
- ## Contributing
538
-
539
- Contributions are welcome! Please:
540
-
541
- 1. Fork the repository
542
- 2. Create a feature branch
543
- 3. Make your changes
544
- 4. Add tests for new functionality
545
- 5. Submit a pull request
546
-
547
- All contributions must be compatible with the MIT license.
1
+ # Rich Ruby (rich-ruby)
2
+
3
+ A Pure Ruby library for rich text and beautiful formatting in the terminal.
4
+
5
+ Rich Ruby provides an elegant API for creating stylish terminal output with colors,
6
+ tables, panels, trees, progress bars, syntax highlighting, and more. It is inspired
7
+ by the Python Rich library but is a complete Ruby-native implementation.
8
+
9
+ ---
10
+
11
+ ## Table of Contents
12
+
13
+ 1. [Features](#features)
14
+ 2. [Requirements](#requirements)
15
+ 3. [Installation](#installation)
16
+ 4. [Quick Start](#quick-start)
17
+ 5. [Usage Guide](#usage-guide)
18
+ - [Colors and Styles](#colors-and-styles)
19
+ - [Text and Markup](#text-and-markup)
20
+ - [Panels](#panels)
21
+ - [Tables](#tables)
22
+ - [Trees](#trees)
23
+ - [Progress Bars and Spinners](#progress-bars-and-spinners)
24
+ - [Syntax Highlighting](#syntax-highlighting)
25
+ - [Markdown Rendering](#markdown-rendering)
26
+ - [JSON Output](#json-output)
27
+ 6. [API Reference](#api-reference)
28
+ 7. [Testing](#testing)
29
+ 8. [License](#license)
30
+
31
+ ---
32
+
33
+ ## Features
34
+
35
+ - **Colors**: Full support for 16-color, 256-color, and TrueColor (24-bit) terminals
36
+ - **Styles**: Bold, italic, underline, strikethrough, blink, reverse, and more
37
+ - **Markup**: Simple markup syntax like `[bold red]text[/]` for inline styling
38
+ - **Panels**: Bordered boxes with titles and subtitles
39
+ - **Tables**: Data tables with column alignment and styling
40
+ - **Trees**: Hierarchical tree views with different guide styles
41
+ - **Progress**: Animated progress bars and spinners
42
+ - **Syntax**: Code syntax highlighting for Ruby, Python, JavaScript, SQL, and more
43
+ - **Markdown**: Render Markdown documents in the terminal
44
+ - **Windows**: Full Windows Console API support with automatic ANSI enabling
45
+ - **Zero Dependencies**: Pure Ruby with no external gem dependencies
46
+
47
+ ---
48
+
49
+ ## Requirements
50
+
51
+ This library was developed and tested on:
52
+
53
+ - **Ruby**: 3.4.8 (MSVC build)
54
+ - **Platform**: Windows 10 64-bit (21H2)
55
+ - **Compiler**: Visual Studio 2026 (MSVC)
56
+
57
+ The library should work on:
58
+
59
+ - Ruby 3.4 or later (see `required_ruby_version` in the gemspec)
60
+ - Windows, macOS, Linux
61
+ - Any terminal supporting ANSI escape codes
62
+
63
+ ### Windows Native Support
64
+
65
+ For Windows users, the library provides **native integration** with the Windows Console API using [Fiddle](https://ruby-doc.org/stdlib/libdoc/fiddle/rdoc/Fiddle.html). This allows it to:
66
+
67
+ 1. **Enable ANSI/VT Processing**: Automatically configures the console to handle ANSI escape codes, even on older versions of Windows 10.
68
+ 2. **Fallback to Console API**: On legacy systems where ANSI is not supported, it uses the Windows Console API (e.g., `SetConsoleTextAttribute`) to provide color and styling.
69
+ 3. **Accurate Console Dimensions**: Uses native API calls to determine the exact width and height of the console window.
70
+ 4. **Hardware Features**: Full control over cursor visibility, window titles, and screen clearing via native calls.
71
+
72
+ This works out-of-the-box with Windows Terminal, PowerShell, and the classic Command Prompt.
73
+
74
+ ---
75
+
76
+ ## Installation
77
+
78
+ ### From RubyGems
79
+
80
+ ```bash
81
+ gem install rich-ruby
82
+ ```
83
+
84
+ ### From source
85
+
86
+ ```bash
87
+ git clone https://github.com/tigel-agm/rich-ruby.git
88
+ cd rich-ruby
89
+ gem build rich-ruby.gemspec
90
+ gem install ./rich-ruby-*.gem
91
+ ```
92
+
93
+ ### In your Gemfile
94
+
95
+ ```ruby
96
+ gem 'rich-ruby'
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Quick Start
102
+
103
+ ```ruby
104
+ require 'rich'
105
+
106
+ # Simple styled output
107
+ Rich.print("[bold cyan]Hello[/] [yellow]World![/]")
108
+
109
+ # Create a console instance for more control
110
+ console = Rich::Console.new
111
+ console.print("Welcome!", style: "bold green")
112
+
113
+ # Display a panel
114
+ panel = Rich::Panel.new(
115
+ "This is important information.",
116
+ title: "Notice",
117
+ border_style: "cyan"
118
+ )
119
+ puts panel.render(max_width: 50)
120
+
121
+ # Display a table
122
+ table = Rich::Table.new(title: "Users")
123
+ table.add_column("Name", header_style: "bold")
124
+ table.add_column("Role")
125
+ table.add_row("Alice", "Admin")
126
+ table.add_row("Bob", "User")
127
+ puts table.render(max_width: 40)
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Documentation
133
+
134
+ For more detailed information, check out our guides:
135
+
136
+ - [**How-To Use**](docs/how-to-use.md): Tiered guide for all levels.
137
+ - [**Troubleshooting & FAQ**](docs/troubleshooting.md): Solutions for common issues.
138
+ - [**Customization**](docs/customization.md): Learn how to extend the library.
139
+ - [**Cheat Sheet**](docs/cheat-sheet.md): Quick reference for styles and colors.
140
+ - [**Windows Notes**](docs/windows-notes.md): Technical details on Windows support.
141
+ - [**Architecture**](docs/architecture.md): Internal design and data flow.
142
+ - [**Test Report**](docs/test-report.md): Verification and performance results.
143
+
144
+ ---
145
+
146
+ ## Usage Guide
147
+
148
+ ### Colors and Styles
149
+
150
+ Rich Ruby supports multiple color systems:
151
+
152
+ ```ruby
153
+ # Standard 16 colors
154
+ style = Rich::Style.parse("red")
155
+ style = Rich::Style.parse("bright_blue")
156
+
157
+ # 256-color palette
158
+ style = Rich::Style.parse("color(42)")
159
+
160
+ # TrueColor (24-bit)
161
+ style = Rich::Style.parse("#ff5500")
162
+ style = Rich::Style.parse("rgb(255, 85, 0)")
163
+
164
+ # Background colors
165
+ style = Rich::Style.parse("white on blue")
166
+ style = Rich::Style.parse("black on #ffcc00")
167
+ ```
168
+
169
+ Available text attributes:
170
+
171
+ | Attribute | Description |
172
+ |-----------|-------------|
173
+ | `bold` | Bold text |
174
+ | `dim` | Dimmed text |
175
+ | `italic` | Italic text |
176
+ | `underline` | Underlined text |
177
+ | `underline2` | Double underline |
178
+ | `overline` | Overlined text |
179
+ | `blink` | Blinking text |
180
+ | `reverse` | Reversed colors |
181
+ | `conceal` | Hidden text |
182
+ | `strike` | Strikethrough |
183
+
184
+ Combine multiple attributes:
185
+
186
+ ```ruby
187
+ style = Rich::Style.parse("bold italic red on white")
188
+ ```
189
+
190
+ ### Text and Markup
191
+
192
+ The markup syntax provides an easy way to style text inline:
193
+
194
+ ```ruby
195
+ # Basic markup
196
+ Rich.print("[bold]Bold text[/bold]")
197
+ Rich.print("[red]Red text[/red]")
198
+
199
+ # Shorthand close tag
200
+ Rich.print("[bold]Bold text[/]")
201
+
202
+ # Nested styles
203
+ Rich.print("[bold][red]Bold and red[/red][/bold]")
204
+
205
+ # Combined styles
206
+ Rich.print("[bold italic cyan on black]Styled[/]")
207
+
208
+ # In strings
209
+ text = Rich::Markup.parse("Name: [cyan]Alice[/] Age: [yellow]30[/]")
210
+ puts Rich::Segment.render(text.to_segments)
211
+ ```
212
+
213
+ ### Panels
214
+
215
+ Create bordered panels to highlight content:
216
+
217
+ ```ruby
218
+ # Simple panel
219
+ panel = Rich::Panel.new("Hello World")
220
+ puts panel.render(max_width: 40)
221
+
222
+ # Panel with title and subtitle
223
+ panel = Rich::Panel.new(
224
+ "Important information goes here.",
225
+ title: "Alert",
226
+ subtitle: "Read carefully",
227
+ border_style: "red",
228
+ title_style: "bold white"
229
+ )
230
+ puts panel.render(max_width: 50)
231
+
232
+ # Different box styles
233
+ panel = Rich::Panel.new("Content", box: Rich::Box::DOUBLE)
234
+ panel = Rich::Panel.new("Content", box: Rich::Box::ROUNDED)
235
+ panel = Rich::Panel.new("Content", box: Rich::Box::HEAVY)
236
+ panel = Rich::Panel.new("Content", box: Rich::Box::ASCII)
237
+ ```
238
+
239
+ ### Tables
240
+
241
+ Create formatted data tables:
242
+
243
+ ```ruby
244
+ # Create a table
245
+ table = Rich::Table.new(title: "Sales Report", border_style: "blue")
246
+
247
+ # Add columns with styling
248
+ table.add_column("Product", header_style: "bold cyan")
249
+ table.add_column("Price", justify: :right, header_style: "bold cyan")
250
+ table.add_column("Quantity", justify: :center)
251
+
252
+ # Add data rows
253
+ table.add_row("Widget", "$10.00", "100")
254
+ table.add_row("Gadget", "$25.50", "50")
255
+ table.add_row("Gizmo", "$5.99", "200")
256
+
257
+ # Render
258
+ puts table.render(max_width: 60)
259
+ ```
260
+
261
+ Column justification options: `:left`, `:center`, `:right`
262
+
263
+ ### Trees
264
+
265
+ Display hierarchical data:
266
+
267
+ ```ruby
268
+ # Create a tree
269
+ tree = Rich::Tree.new("Project", style: "bold yellow")
270
+
271
+ # Add nodes
272
+ src = tree.add("src/", style: "bold")
273
+ src.add("main.rb", style: "green")
274
+ src.add("config.rb", style: "green")
275
+
276
+ lib = tree.add("lib/")
277
+ lib.add("utils.rb")
278
+
279
+ tree.add("README.md", style: "cyan")
280
+
281
+ # Render
282
+ puts tree.render
283
+ ```
284
+
285
+ Different guide styles:
286
+
287
+ ```ruby
288
+ tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::ASCII)
289
+ tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::ROUNDED)
290
+ tree = Rich::Tree.new("Root", guide: Rich::TreeGuide::BOLD)
291
+ ```
292
+
293
+ ### Progress Bars and Spinners
294
+
295
+ Show progress for long-running tasks:
296
+
297
+ ```ruby
298
+ # Progress bar
299
+ bar = Rich::ProgressBar.new(total: 100, width: 40)
300
+
301
+ 100.times do |i|
302
+ bar.update(i + 1)
303
+ print "\rProgress: #{bar.render}"
304
+ sleep(0.05)
305
+ end
306
+ puts ""
307
+
308
+ # Spinner
309
+ spinner = Rich::Spinner.new(frames: Rich::ProgressStyle::DOTS)
310
+
311
+ 20.times do
312
+ print "\r#{spinner.frame} Loading..."
313
+ spinner.advance
314
+ sleep(0.1)
315
+ end
316
+ puts "\rDone! "
317
+ ```
318
+
319
+ Available spinner styles:
320
+ - `Rich::ProgressStyle::DOTS`
321
+ - `Rich::ProgressStyle::LINE`
322
+ - `Rich::ProgressStyle::CIRCLE`
323
+ - `Rich::ProgressStyle::BOUNCE`
324
+
325
+ ### Syntax Highlighting
326
+
327
+ Highlight source code:
328
+
329
+ ```ruby
330
+ code = <<~RUBY
331
+ def greet(name)
332
+ puts "Hello, #{name}!"
333
+ end
334
+ RUBY
335
+
336
+ # Basic highlighting
337
+ syntax = Rich::Syntax.new(code, language: "ruby")
338
+ puts syntax.render
339
+
340
+ # With line numbers
341
+ syntax = Rich::Syntax.new(code, language: "ruby", line_numbers: true)
342
+ puts syntax.render
343
+
344
+ # With a theme
345
+ syntax = Rich::Syntax.new(code, language: "python", theme: :monokai)
346
+ syntax = Rich::Syntax.new(code, language: "javascript", theme: :dracula)
347
+ ```
348
+
349
+ Supported languages: Ruby, Python, JavaScript, SQL, JSON, YAML, Bash
350
+
351
+ Available themes: `:default`, `:monokai`, `:dracula`
352
+
353
+ ### Markdown Rendering
354
+
355
+ Render Markdown in the terminal:
356
+
357
+ ```ruby
358
+ markdown = <<~MD
359
+ # Welcome
360
+
361
+ This is **bold** and *italic* text.
362
+
363
+ ## Features
364
+
365
+ - Item one
366
+ - Item two
367
+
368
+ ```ruby
369
+ puts "Code block"
370
+ ```
371
+
372
+ | Column A | Column B |
373
+ |----------|----------|
374
+ | Value 1 | Value 2 |
375
+ MD
376
+
377
+ md = Rich::Markdown.new(markdown)
378
+ puts md.render(max_width: 70)
379
+ ```
380
+
381
+ Supported Markdown elements:
382
+ - Headings (H1-H6)
383
+ - Bold, italic, strikethrough
384
+ - Inline code
385
+ - Code blocks with language
386
+ - Ordered and unordered lists
387
+ - Blockquotes
388
+ - Tables
389
+ - Links
390
+ - Horizontal rules
391
+
392
+ ### JSON Output
393
+
394
+ Pretty-print JSON with syntax highlighting:
395
+
396
+ ```ruby
397
+ data = {
398
+ "name" => "Alice",
399
+ "age" => 30,
400
+ "active" => true,
401
+ "roles" => ["admin", "user"]
402
+ }
403
+
404
+ puts Rich::JSON.to_s(data)
405
+
406
+ # Highlight existing JSON string (highlight returns segments)
407
+ json_str = '{"key": "value"}'
408
+ puts Rich::Segment.render(Rich::JSON.highlight(json_str))
409
+ ```
410
+
411
+ ---
412
+
413
+ ## API Reference
414
+
415
+ ### Core Classes
416
+
417
+ | Class | Description |
418
+ |-------|-------------|
419
+ | `Rich::Console` | Main console interface |
420
+ | `Rich::Color` | Color representation and parsing |
421
+ | `Rich::Style` | Text style with color and attributes |
422
+ | `Rich::Segment` | Styled text segment |
423
+ | `Rich::Text` | Rich text with spans |
424
+ | `Rich::Markup` | Markup parser |
425
+
426
+ ### Components
427
+
428
+ | Class | Description |
429
+ |-------|-------------|
430
+ | `Rich::Panel` | Bordered panel |
431
+ | `Rich::Table` | Data table |
432
+ | `Rich::Tree` | Tree view |
433
+ | `Rich::ProgressBar` | Progress bar |
434
+ | `Rich::Spinner` | Animated spinner |
435
+ | `Rich::Syntax` | Syntax highlighter |
436
+ | `Rich::Markdown` | Markdown renderer |
437
+ | `Rich::JSON` | JSON formatter |
438
+
439
+ ### Module Methods
440
+
441
+ ```ruby
442
+ Rich.print(*objects, style: nil) # Print with markup support
443
+ Rich.print_json(data) # Print formatted JSON
444
+ Rich.rule(title) # Print horizontal rule
445
+ Rich.get_console # Get global console instance
446
+ Rich.reconfigure(**options) # Reconfigure global console
447
+ ```
448
+
449
+ ---
450
+
451
+ ## Testing
452
+
453
+ Run the full test suite:
454
+
455
+ ```bash
456
+ cd rich-ruby
457
+ ruby -W0 -Ilib -Itest -e "Dir['test/test_*.rb'].each { |f| require_relative f }"
458
+ ```
459
+
460
+ > [!TIP]
461
+ > Use the `-W0` flag to suppress environmental warnings (like the `io-nonblock` extension warning) for a cleaner test output.
462
+
463
+ Or with Rake (if rake is available):
464
+
465
+ ```bash
466
+ rake test
467
+ ```
468
+
469
+ Run individual test files:
470
+
471
+ ```bash
472
+ ruby -W0 -Ilib -Itest test/test_color.rb
473
+ ruby -W0 -Ilib -Itest test/test_style.rb
474
+ ```
475
+
476
+ Run stress tests:
477
+
478
+ ```bash
479
+ ruby examples/stress_test.rb
480
+ ```
481
+
482
+ ---
483
+
484
+ ## Project Structure
485
+
486
+ ```
487
+ rich/
488
+ lib/
489
+ rich.rb # Main entry point
490
+ rich/
491
+ color.rb # Color handling
492
+ style.rb # Text styles
493
+ text.rb # Rich text
494
+ markup.rb # Markup parser
495
+ panel.rb # Panel component
496
+ table.rb # Table component
497
+ tree.rb # Tree component
498
+ progress.rb # Progress bars and spinners
499
+ syntax.rb # Syntax highlighting
500
+ markdown.rb # Markdown rendering
501
+ json.rb # JSON formatting
502
+ console.rb # Console interface
503
+ ...
504
+ test/
505
+ test_*.rb # Test files
506
+ examples/
507
+ demo.rb # Basic demo
508
+ showcase.rb # Interactive showcase
509
+ stress_test.rb # Stress tests
510
+ ```
511
+
512
+ ---
513
+
514
+ ## License
515
+
516
+ This project is licensed under the MIT License.
517
+
518
+ This means:
519
+ - You can use, modify, and distribute this software for any purpose
520
+ - You can use it in commercial projects
521
+ - You must include the original copyright and license notice
522
+
523
+ See the [LICENSE](LICENSE) file for the full license text.
524
+
525
+ ---
526
+
527
+ ## Credits
528
+
529
+ This library is an original Ruby implementation inspired by the concepts of the
530
+ Python Rich library by Will McGugan [https://github.com/willmcgugan]. All code is original and written specifically
531
+ for Ruby.
532
+
533
+ Developed on Ruby 3.4.8 (MSVC) on Windows 10 64-bit (21H2) with Visual Studio 2026.
534
+
535
+ ---
536
+
537
+ ## Contributing
538
+
539
+ Contributions are welcome! Please:
540
+
541
+ 1. Fork the repository
542
+ 2. Create a feature branch
543
+ 3. Make your changes
544
+ 4. Add tests for new functionality
545
+ 5. Submit a pull request
546
+
547
+ All contributions must be compatible with the MIT license.