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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +80 -0
- data/LICENSE +21 -21
- data/README.md +547 -547
- data/docs/architecture.md +43 -0
- data/docs/cheat-sheet.md +52 -0
- data/docs/customization.md +53 -0
- data/docs/how-to-use.md +96 -0
- data/docs/test-report.md +112 -0
- data/docs/troubleshooting.md +36 -0
- data/docs/windows-notes.md +30 -0
- data/examples/demo.rb +106 -106
- data/examples/showcase.rb +420 -420
- data/examples/smoke_test.rb +41 -41
- data/examples/stress_test.rb +604 -604
- data/examples/syntax_markdown_demo.rb +166 -166
- data/examples/verify.rb +216 -215
- data/examples/visual_demo.rb +145 -145
- data/lib/rich/_palettes.rb +148 -148
- data/lib/rich/box.rb +342 -342
- data/lib/rich/cells.rb +524 -512
- data/lib/rich/color.rb +631 -628
- data/lib/rich/color_triplet.rb +227 -220
- data/lib/rich/console.rb +604 -549
- data/lib/rich/control.rb +332 -332
- data/lib/rich/json.rb +260 -254
- data/lib/rich/layout.rb +314 -314
- data/lib/rich/markdown.rb +531 -509
- data/lib/rich/markup.rb +186 -175
- data/lib/rich/panel.rb +318 -311
- data/lib/rich/progress.rb +430 -430
- data/lib/rich/segment.rb +387 -387
- data/lib/rich/style.rb +464 -433
- data/lib/rich/syntax.rb +1220 -1145
- data/lib/rich/table.rb +547 -525
- data/lib/rich/terminal_theme.rb +126 -126
- data/lib/rich/text.rb +460 -433
- data/lib/rich/tree.rb +220 -220
- data/lib/rich/version.rb +5 -5
- data/lib/rich/win32_console.rb +620 -582
- data/lib/rich.rb +108 -108
- metadata +15 -5
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Demo of Syntax Highlighting and Markdown Rendering
|
|
4
|
-
|
|
5
|
-
require_relative "../lib/rich"
|
|
6
|
-
|
|
7
|
-
console = Rich::Console.new
|
|
8
|
-
|
|
9
|
-
console.rule("Syntax Highlighting Demo", style: "bold cyan")
|
|
10
|
-
puts ""
|
|
11
|
-
|
|
12
|
-
# Ruby code
|
|
13
|
-
ruby_code = <<~RUBY
|
|
14
|
-
# Ruby example
|
|
15
|
-
class User
|
|
16
|
-
attr_accessor :name, :email
|
|
17
|
-
|
|
18
|
-
def initialize(name, email)
|
|
19
|
-
@name = name
|
|
20
|
-
@email = email
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def greet
|
|
24
|
-
puts "Hello, \#{@name}!"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
user = User.new("Alice", "alice@example.com")
|
|
29
|
-
user.greet
|
|
30
|
-
RUBY
|
|
31
|
-
|
|
32
|
-
puts "Ruby:"
|
|
33
|
-
puts ""
|
|
34
|
-
syntax = Rich::Syntax.new(ruby_code, language: "ruby", line_numbers: true)
|
|
35
|
-
puts syntax.render
|
|
36
|
-
puts ""
|
|
37
|
-
|
|
38
|
-
# Python code
|
|
39
|
-
python_code = <<~PYTHON
|
|
40
|
-
# Python example
|
|
41
|
-
import json
|
|
42
|
-
from dataclasses import dataclass
|
|
43
|
-
|
|
44
|
-
@dataclass
|
|
45
|
-
class Config:
|
|
46
|
-
name: str
|
|
47
|
-
debug: bool = False
|
|
48
|
-
|
|
49
|
-
def load_config(path: str) -> Config:
|
|
50
|
-
with open(path) as f:
|
|
51
|
-
data = json.load(f)
|
|
52
|
-
return Config(**data)
|
|
53
|
-
|
|
54
|
-
if __name__ == "__main__":
|
|
55
|
-
config = load_config("config.json")
|
|
56
|
-
print(f"Loaded: {config.name}")
|
|
57
|
-
PYTHON
|
|
58
|
-
|
|
59
|
-
puts "Python:"
|
|
60
|
-
puts ""
|
|
61
|
-
syntax = Rich::Syntax.new(python_code, language: "python", line_numbers: true, theme: :monokai)
|
|
62
|
-
puts syntax.render
|
|
63
|
-
puts ""
|
|
64
|
-
|
|
65
|
-
# JavaScript
|
|
66
|
-
js_code = <<~JS
|
|
67
|
-
// JavaScript example
|
|
68
|
-
const express = require('express');
|
|
69
|
-
const app = express();
|
|
70
|
-
|
|
71
|
-
app.get('/api/users', async (req, res) => {
|
|
72
|
-
const users = await User.findAll();
|
|
73
|
-
res.json({ data: users, count: users.length });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
app.listen(3000, () => console.log('Server running'));
|
|
77
|
-
JS
|
|
78
|
-
|
|
79
|
-
puts "JavaScript (Dracula theme):"
|
|
80
|
-
puts ""
|
|
81
|
-
syntax = Rich::Syntax.new(js_code, language: "javascript", line_numbers: true, theme: :dracula)
|
|
82
|
-
puts syntax.render
|
|
83
|
-
puts ""
|
|
84
|
-
|
|
85
|
-
# SQL
|
|
86
|
-
sql_code = <<~SQL
|
|
87
|
-
-- Get active users with their orders
|
|
88
|
-
SELECT u.name, u.email, COUNT(o.id) AS order_count
|
|
89
|
-
FROM users u
|
|
90
|
-
LEFT JOIN orders o ON u.id = o.user_id
|
|
91
|
-
WHERE u.status = 'active'
|
|
92
|
-
AND o.created_at >= '2025-01-01'
|
|
93
|
-
GROUP BY u.id
|
|
94
|
-
HAVING order_count > 5
|
|
95
|
-
ORDER BY order_count DESC
|
|
96
|
-
LIMIT 10;
|
|
97
|
-
SQL
|
|
98
|
-
|
|
99
|
-
puts "SQL:"
|
|
100
|
-
puts ""
|
|
101
|
-
syntax = Rich::Syntax.new(sql_code, language: "sql")
|
|
102
|
-
puts syntax.render
|
|
103
|
-
puts ""
|
|
104
|
-
|
|
105
|
-
console.rule("Markdown Rendering Demo", style: "bold cyan")
|
|
106
|
-
puts ""
|
|
107
|
-
|
|
108
|
-
markdown = <<~MD
|
|
109
|
-
# Welcome to Rich Markdown
|
|
110
|
-
|
|
111
|
-
This is a **full-featured** Markdown renderer for your *terminal*.
|
|
112
|
-
|
|
113
|
-
## Features
|
|
114
|
-
|
|
115
|
-
### Text Formatting
|
|
116
|
-
|
|
117
|
-
You can use **bold**, *italic*, ***bold italic***, ~~strikethrough~~, and `inline code`.
|
|
118
|
-
|
|
119
|
-
### Lists
|
|
120
|
-
|
|
121
|
-
Unordered list:
|
|
122
|
-
- First item
|
|
123
|
-
- Second item
|
|
124
|
-
- Nested item
|
|
125
|
-
- Another nested
|
|
126
|
-
|
|
127
|
-
Ordered list:
|
|
128
|
-
1. Step one
|
|
129
|
-
2. Step two
|
|
130
|
-
3. Step three
|
|
131
|
-
|
|
132
|
-
### Blockquotes
|
|
133
|
-
|
|
134
|
-
> This is a blockquote.
|
|
135
|
-
> It can span multiple lines.
|
|
136
|
-
> -- Someone Famous
|
|
137
|
-
|
|
138
|
-
### Code Blocks
|
|
139
|
-
|
|
140
|
-
```ruby
|
|
141
|
-
def hello(name)
|
|
142
|
-
puts "Hello, \#{name}!"
|
|
143
|
-
end
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Tables
|
|
147
|
-
|
|
148
|
-
| Name | Language | Stars |
|
|
149
|
-
|----------|----------|-------|
|
|
150
|
-
| Ruby | Ruby | 21k |
|
|
151
|
-
| Python | Python | 58k |
|
|
152
|
-
| Node.js | JS | 102k |
|
|
153
|
-
|
|
154
|
-
### Links
|
|
155
|
-
|
|
156
|
-
Check out [Rich Library](https://github.com/Textualize/rich) for more!
|
|
157
|
-
|
|
158
|
-
---
|
|
159
|
-
|
|
160
|
-
That's all folks!
|
|
161
|
-
MD
|
|
162
|
-
|
|
163
|
-
md = Rich::Markdown.new(markdown)
|
|
164
|
-
puts md.render(max_width: 70)
|
|
165
|
-
|
|
166
|
-
console.rule("Demo Complete!", style: "bold green")
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Demo of Syntax Highlighting and Markdown Rendering
|
|
4
|
+
|
|
5
|
+
require_relative "../lib/rich"
|
|
6
|
+
|
|
7
|
+
console = Rich::Console.new
|
|
8
|
+
|
|
9
|
+
console.rule("Syntax Highlighting Demo", style: "bold cyan")
|
|
10
|
+
puts ""
|
|
11
|
+
|
|
12
|
+
# Ruby code
|
|
13
|
+
ruby_code = <<~RUBY
|
|
14
|
+
# Ruby example
|
|
15
|
+
class User
|
|
16
|
+
attr_accessor :name, :email
|
|
17
|
+
|
|
18
|
+
def initialize(name, email)
|
|
19
|
+
@name = name
|
|
20
|
+
@email = email
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def greet
|
|
24
|
+
puts "Hello, \#{@name}!"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
user = User.new("Alice", "alice@example.com")
|
|
29
|
+
user.greet
|
|
30
|
+
RUBY
|
|
31
|
+
|
|
32
|
+
puts "Ruby:"
|
|
33
|
+
puts ""
|
|
34
|
+
syntax = Rich::Syntax.new(ruby_code, language: "ruby", line_numbers: true)
|
|
35
|
+
puts syntax.render
|
|
36
|
+
puts ""
|
|
37
|
+
|
|
38
|
+
# Python code
|
|
39
|
+
python_code = <<~PYTHON
|
|
40
|
+
# Python example
|
|
41
|
+
import json
|
|
42
|
+
from dataclasses import dataclass
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class Config:
|
|
46
|
+
name: str
|
|
47
|
+
debug: bool = False
|
|
48
|
+
|
|
49
|
+
def load_config(path: str) -> Config:
|
|
50
|
+
with open(path) as f:
|
|
51
|
+
data = json.load(f)
|
|
52
|
+
return Config(**data)
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
config = load_config("config.json")
|
|
56
|
+
print(f"Loaded: {config.name}")
|
|
57
|
+
PYTHON
|
|
58
|
+
|
|
59
|
+
puts "Python:"
|
|
60
|
+
puts ""
|
|
61
|
+
syntax = Rich::Syntax.new(python_code, language: "python", line_numbers: true, theme: :monokai)
|
|
62
|
+
puts syntax.render
|
|
63
|
+
puts ""
|
|
64
|
+
|
|
65
|
+
# JavaScript
|
|
66
|
+
js_code = <<~JS
|
|
67
|
+
// JavaScript example
|
|
68
|
+
const express = require('express');
|
|
69
|
+
const app = express();
|
|
70
|
+
|
|
71
|
+
app.get('/api/users', async (req, res) => {
|
|
72
|
+
const users = await User.findAll();
|
|
73
|
+
res.json({ data: users, count: users.length });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
app.listen(3000, () => console.log('Server running'));
|
|
77
|
+
JS
|
|
78
|
+
|
|
79
|
+
puts "JavaScript (Dracula theme):"
|
|
80
|
+
puts ""
|
|
81
|
+
syntax = Rich::Syntax.new(js_code, language: "javascript", line_numbers: true, theme: :dracula)
|
|
82
|
+
puts syntax.render
|
|
83
|
+
puts ""
|
|
84
|
+
|
|
85
|
+
# SQL
|
|
86
|
+
sql_code = <<~SQL
|
|
87
|
+
-- Get active users with their orders
|
|
88
|
+
SELECT u.name, u.email, COUNT(o.id) AS order_count
|
|
89
|
+
FROM users u
|
|
90
|
+
LEFT JOIN orders o ON u.id = o.user_id
|
|
91
|
+
WHERE u.status = 'active'
|
|
92
|
+
AND o.created_at >= '2025-01-01'
|
|
93
|
+
GROUP BY u.id
|
|
94
|
+
HAVING order_count > 5
|
|
95
|
+
ORDER BY order_count DESC
|
|
96
|
+
LIMIT 10;
|
|
97
|
+
SQL
|
|
98
|
+
|
|
99
|
+
puts "SQL:"
|
|
100
|
+
puts ""
|
|
101
|
+
syntax = Rich::Syntax.new(sql_code, language: "sql")
|
|
102
|
+
puts syntax.render
|
|
103
|
+
puts ""
|
|
104
|
+
|
|
105
|
+
console.rule("Markdown Rendering Demo", style: "bold cyan")
|
|
106
|
+
puts ""
|
|
107
|
+
|
|
108
|
+
markdown = <<~MD
|
|
109
|
+
# Welcome to Rich Markdown
|
|
110
|
+
|
|
111
|
+
This is a **full-featured** Markdown renderer for your *terminal*.
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
### Text Formatting
|
|
116
|
+
|
|
117
|
+
You can use **bold**, *italic*, ***bold italic***, ~~strikethrough~~, and `inline code`.
|
|
118
|
+
|
|
119
|
+
### Lists
|
|
120
|
+
|
|
121
|
+
Unordered list:
|
|
122
|
+
- First item
|
|
123
|
+
- Second item
|
|
124
|
+
- Nested item
|
|
125
|
+
- Another nested
|
|
126
|
+
|
|
127
|
+
Ordered list:
|
|
128
|
+
1. Step one
|
|
129
|
+
2. Step two
|
|
130
|
+
3. Step three
|
|
131
|
+
|
|
132
|
+
### Blockquotes
|
|
133
|
+
|
|
134
|
+
> This is a blockquote.
|
|
135
|
+
> It can span multiple lines.
|
|
136
|
+
> -- Someone Famous
|
|
137
|
+
|
|
138
|
+
### Code Blocks
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
def hello(name)
|
|
142
|
+
puts "Hello, \#{name}!"
|
|
143
|
+
end
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Tables
|
|
147
|
+
|
|
148
|
+
| Name | Language | Stars |
|
|
149
|
+
|----------|----------|-------|
|
|
150
|
+
| Ruby | Ruby | 21k |
|
|
151
|
+
| Python | Python | 58k |
|
|
152
|
+
| Node.js | JS | 102k |
|
|
153
|
+
|
|
154
|
+
### Links
|
|
155
|
+
|
|
156
|
+
Check out [Rich Library](https://github.com/Textualize/rich) for more!
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
That's all folks!
|
|
161
|
+
MD
|
|
162
|
+
|
|
163
|
+
md = Rich::Markdown.new(markdown)
|
|
164
|
+
puts md.render(max_width: 70)
|
|
165
|
+
|
|
166
|
+
console.rule("Demo Complete!", style: "bold green")
|