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.
@@ -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")