fatty 0.99.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.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +2 -0
  3. data/.simplecov +23 -0
  4. data/.yardopts +4 -0
  5. data/CHANGELOG.md +34 -0
  6. data/CHANGELOG.org +38 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +31 -0
  9. data/README.org +166 -0
  10. data/Rakefile +15 -0
  11. data/TODO.org +163 -0
  12. data/examples/markdown/native-markdown.md +370 -0
  13. data/examples/markdown/ox-gfm-markdown.md +373 -0
  14. data/examples/markdown/ox-gfm-markdown.org +376 -0
  15. data/exe/fatty +275 -0
  16. data/fatty.gemspec +42 -0
  17. data/lib/fatty/accept_env.rb +32 -0
  18. data/lib/fatty/action.rb +103 -0
  19. data/lib/fatty/action_environment.rb +42 -0
  20. data/lib/fatty/actionable.rb +73 -0
  21. data/lib/fatty/alert.rb +93 -0
  22. data/lib/fatty/ansi/renderer.rb +168 -0
  23. data/lib/fatty/ansi.rb +352 -0
  24. data/lib/fatty/colors/color.rb +379 -0
  25. data/lib/fatty/colors/pairs.rb +73 -0
  26. data/lib/fatty/colors/palette.rb +73 -0
  27. data/lib/fatty/colors/rgb.txt +788 -0
  28. data/lib/fatty/colors.rb +5 -0
  29. data/lib/fatty/config.rb +86 -0
  30. data/lib/fatty/config_files/config.yml +50 -0
  31. data/lib/fatty/config_files/help.md +120 -0
  32. data/lib/fatty/config_files/help.org +124 -0
  33. data/lib/fatty/config_files/keybindings.yml +49 -0
  34. data/lib/fatty/config_files/keydefs.yml +23 -0
  35. data/lib/fatty/config_files/themes/mono.yml +76 -0
  36. data/lib/fatty/config_files/themes/nordic.yml +77 -0
  37. data/lib/fatty/config_files/themes/solarized_dark.yml +77 -0
  38. data/lib/fatty/config_files/themes/terminal.yml +90 -0
  39. data/lib/fatty/config_files/themes/wordperfect.yml +77 -0
  40. data/lib/fatty/config_files/themes/wordperfect_light.yml +77 -0
  41. data/lib/fatty/core_ext/string.rb +21 -0
  42. data/lib/fatty/core_ext.rb +3 -0
  43. data/lib/fatty/counter.rb +81 -0
  44. data/lib/fatty/curses/context.rb +279 -0
  45. data/lib/fatty/curses/curses_coder.rb +684 -0
  46. data/lib/fatty/curses/event_source.rb +230 -0
  47. data/lib/fatty/curses/key_decoder.rb +183 -0
  48. data/lib/fatty/curses/patch.rb +116 -0
  49. data/lib/fatty/curses/window_styling.rb +32 -0
  50. data/lib/fatty/curses.rb +16 -0
  51. data/lib/fatty/env.rb +100 -0
  52. data/lib/fatty/help.rb +41 -0
  53. data/lib/fatty/history/entry.rb +71 -0
  54. data/lib/fatty/history.rb +289 -0
  55. data/lib/fatty/input_buffer.rb +998 -0
  56. data/lib/fatty/input_field.rb +507 -0
  57. data/lib/fatty/key_event.rb +342 -0
  58. data/lib/fatty/key_map.rb +392 -0
  59. data/lib/fatty/keymaps/emacs.rb +189 -0
  60. data/lib/fatty/log_formats/json.rb +47 -0
  61. data/lib/fatty/log_formats/text.rb +67 -0
  62. data/lib/fatty/logger.rb +142 -0
  63. data/lib/fatty/markdown/ansi_renderer.rb +373 -0
  64. data/lib/fatty/markdown/render.rb +22 -0
  65. data/lib/fatty/markdown.rb +4 -0
  66. data/lib/fatty/menu_env.rb +22 -0
  67. data/lib/fatty/mouse_event.rb +32 -0
  68. data/lib/fatty/output_buffer.rb +78 -0
  69. data/lib/fatty/pager.rb +801 -0
  70. data/lib/fatty/prompt.rb +40 -0
  71. data/lib/fatty/renderer/curses.rb +697 -0
  72. data/lib/fatty/renderer/truecolor.rb +607 -0
  73. data/lib/fatty/renderer.rb +419 -0
  74. data/lib/fatty/screen.rb +96 -0
  75. data/lib/fatty/search.rb +43 -0
  76. data/lib/fatty/session/alert_session.rb +52 -0
  77. data/lib/fatty/session/input_session.rb +99 -0
  78. data/lib/fatty/session/isearch_session.rb +172 -0
  79. data/lib/fatty/session/keytest_session.rb +236 -0
  80. data/lib/fatty/session/modal_session.rb +61 -0
  81. data/lib/fatty/session/output_session.rb +105 -0
  82. data/lib/fatty/session/popup_session.rb +540 -0
  83. data/lib/fatty/session/prompt_session.rb +157 -0
  84. data/lib/fatty/session/search_session.rb +136 -0
  85. data/lib/fatty/session/shell_session.rb +566 -0
  86. data/lib/fatty/session.rb +173 -0
  87. data/lib/fatty/sessions.rb +14 -0
  88. data/lib/fatty/terminal/popup_owner.rb +26 -0
  89. data/lib/fatty/terminal/progress.rb +374 -0
  90. data/lib/fatty/terminal.rb +1067 -0
  91. data/lib/fatty/themes/loader.rb +136 -0
  92. data/lib/fatty/themes/manager.rb +71 -0
  93. data/lib/fatty/themes/registry.rb +64 -0
  94. data/lib/fatty/themes/resolver.rb +224 -0
  95. data/lib/fatty/themes/themes.rb +131 -0
  96. data/lib/fatty/themes.rb +6 -0
  97. data/lib/fatty/version.rb +5 -0
  98. data/lib/fatty/view/alert_view.rb +14 -0
  99. data/lib/fatty/view/cursor_view.rb +18 -0
  100. data/lib/fatty/view/input_view.rb +9 -0
  101. data/lib/fatty/view/output_view.rb +9 -0
  102. data/lib/fatty/view/status_view.rb +14 -0
  103. data/lib/fatty/view.rb +33 -0
  104. data/lib/fatty/viewport.rb +90 -0
  105. data/lib/fatty/views.rb +9 -0
  106. data/lib/fatty.rb +55 -0
  107. data/sig/fatty.rbs +4 -0
  108. metadata +250 -0
@@ -0,0 +1,370 @@
1
+ # H1 heading should be red on yellow and bold
2
+
3
+ ## H2 heading should be black on pink and bold
4
+
5
+ ### H3 heading should be magenta on lightyellow and underlined
6
+
7
+ This paragraph has **strong text**, *emphasized text*, `inline code`,
8
+ ==highlighted text==, and [a link label](https://example.com).
9
+
10
+ Autolink: https://example.org
11
+
12
+ > This block quote should have a red quote gutter.
13
+ > The quoted text itself can stay normal output for now.
14
+
15
+ ```ruby
16
+ def hello(name)
17
+ puts "hello #{name}"
18
+ end
19
+ ```
20
+
21
+ | Feature | Expected style |
22
+ | --- | --- |
23
+ | Header cells | black on lightgreen |
24
+ | Body cells | orange on navy |
25
+
26
+ ## Attribute contrast
27
+
28
+ This line compares normal output with **strong bold text** and *emphasis underline text*.
29
+
30
+ Inline code should be visually heavier or distinct: `inline code sample`.
31
+
32
+ Link role should underline the label, while URL role should be dimmer:
33
+ [bright/underlined label](https://example.com/dim-url-target)
34
+
35
+ ### Dim test
36
+
37
+ The URL below should be dimmer than the surrounding text. If dim is working,
38
+ the angle-bracket URL after the label should look subdued:
39
+
40
+ [normal label](https://example.com/this-part-should-be-dim)
41
+
42
+ ```ruby
43
+ # The code gutter at the left should be dim or otherwise subdued.
44
+ # Compare the gutter against this bright comment text.
45
+ puts "gutter dim test"
46
+ ```
47
+
48
+ # Carnival of Consructs
49
+
50
+ These are samples of the kinds of constructs the ANSI renderer for `fatty` are capable of.
51
+
52
+
53
+ ## Unordered Lists
54
+
55
+ - builtin commands are handled by the `fatty` demo, Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
56
+ - other commands are handled by `/bin/sh`
57
+ - keybindings are listed below
58
+
59
+
60
+ ## Ordered Lists
61
+
62
+ 1. builtin commands are handled by the `fatty` demo, Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
63
+ 2. other commands are handled by `/bin/sh`
64
+ 3. keybindings are listed below
65
+
66
+
67
+ ## Description Lists
68
+
69
+ - **bold:** **this text is bold**
70
+ - **italic:** *this text is italic*
71
+ - **code:** `this text is code`
72
+ - **verbatim:** `this text is verbatim`
73
+ - **strike:** ~~this text is strike-through~~
74
+ - **underline:** <span class="underline">this text is underlined</span>
75
+
76
+ ## A Code Block
77
+
78
+ ```ruby
79
+ def wrap(text, first_prefix: "", rest_prefix: first_prefix)
80
+ width = [@width.to_i, 20].max
81
+
82
+ words = text.to_s.split(/\s+/)
83
+ lines = []
84
+ line = +""
85
+
86
+ words.each do |word|
87
+ prefix = lines.empty? ? first_prefix : rest_prefix
88
+ available = width - Fatty::Ansi.visible_length(prefix)
89
+ available = 20 if available < 20
90
+
91
+ candidate = line.empty? ? word : "#{line} #{word}"
92
+
93
+ if Fatty::Ansi.visible_length(candidate) > available && !line.empty?
94
+ lines << "#{prefix}#{line}"
95
+ line = word.dup
96
+ else
97
+ line = candidate
98
+ end
99
+ end
100
+
101
+ unless line.empty?
102
+ prefix = lines.empty? ? first_prefix : rest_prefix
103
+ lines << "#{prefix}#{line}"
104
+ end
105
+
106
+ lines.join("\n")
107
+ end
108
+ ```
109
+
110
+
111
+ ## Nested lists
112
+
113
+ - Parent item
114
+ - Child item
115
+ - Another child
116
+ - Back to parent
117
+
118
+
119
+ ## Links
120
+
121
+ [Fatty on GitHub](<https://github.com/ddoherty03/fatty>)
122
+
123
+
124
+ ## Block quotes
125
+
126
+ > Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
127
+ >
128
+ > Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
129
+ >
130
+ > But, in a larger sense, we can not dedicate&#x2014;we can not consecrate&#x2014;we can not hallow&#x2014;this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us&#x2014;that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion&#x2014;that we here highly resolve that these dead shall not have died in vain&#x2014;that this nation, under God, shall have a new birth of freedom&#x2014;and that government of the people, by the people, for the people, shall not perish from the earth.
131
+
132
+
133
+ ## Tables with styled cells
134
+
135
+ | Feature | Example |
136
+ |------- |--------------- |
137
+ | bold | **bold cell** |
138
+ | code | \`code cell\` |
139
+ | strike | ~~strike cell~~ |
140
+
141
+
142
+ ## Forced Line Break
143
+
144
+ This line has a forced line break<br>
145
+ and this should appear on the next line.
146
+
147
+ ## Fenced code with various languages
148
+
149
+ Here is the Fibonacci number computed recursively in various languages.
150
+
151
+
152
+ ### Ruby
153
+
154
+ ```ruby
155
+ def fib(n)
156
+ return n if n < 2
157
+
158
+ fib(n - 1) + fib(n - 2)
159
+ end
160
+ puts fib(10)
161
+ ```
162
+
163
+
164
+ ### Python
165
+
166
+ ```python
167
+ def fib(n):
168
+ if n < 2:
169
+ return n
170
+
171
+ return fib(n - 1) + fib(n - 2)
172
+
173
+ print(fib(10))
174
+
175
+ ```
176
+
177
+
178
+ ### C
179
+
180
+ ```c
181
+ #include <stdio.h>
182
+
183
+ int fib(int n)
184
+ {
185
+ if (n < 2) {
186
+ return n;
187
+ }
188
+
189
+ return fib(n - 1) + fib(n - 2);
190
+ }
191
+
192
+ int main(void)
193
+ {
194
+ printf("%d\n", fib(10));
195
+ return 0;
196
+ }
197
+ ```
198
+
199
+
200
+ ### C++
201
+
202
+ ```cpp
203
+ #include <iostream>
204
+
205
+ int fib(int n)
206
+ {
207
+ if (n < 2) {
208
+ return n;
209
+ }
210
+
211
+ return fib(n - 1) + fib(n - 2);
212
+ }
213
+
214
+ int main()
215
+ {
216
+ std::cout << fib(10) << std::endl;
217
+ }
218
+ ```
219
+
220
+
221
+ ### Go
222
+
223
+ ```go
224
+ package main
225
+
226
+ import "fmt"
227
+
228
+ func fib(n int) int {
229
+ if n < 2 {
230
+ return n
231
+ }
232
+
233
+ return fib(n-1) + fib(n-2)
234
+ }
235
+
236
+ func main() {
237
+ fmt.Println(fib(10))
238
+ }
239
+ ```
240
+
241
+
242
+ ### Rust
243
+
244
+ ```rust
245
+ fn fib(n: u32) -> u32 {
246
+ if n < 2 {
247
+ n
248
+ } else {
249
+ fib(n - 1) + fib(n - 2)
250
+ }
251
+ }
252
+
253
+ fn main() {
254
+ println!("{}", fib(10));
255
+ }
256
+ ```
257
+
258
+
259
+ ### PHP
260
+
261
+ ```php
262
+ <?php
263
+
264
+ function fib($n)
265
+ {
266
+ if ($n < 2) {
267
+ return $n;
268
+ }
269
+
270
+ return fib($n - 1) + fib($n - 2);
271
+ }
272
+
273
+ echo fib(10) . PHP_EOL;
274
+ ```
275
+
276
+
277
+ ### ### JavaScript
278
+
279
+ ```javascript
280
+ function fib(n) {
281
+ if (n < 2) {
282
+ return n;
283
+ }
284
+
285
+ return fib(n - 1) + fib(n - 2);
286
+ }
287
+
288
+ console.log(fib(10));
289
+ ```
290
+
291
+
292
+ ### TypeScript
293
+
294
+ ```typescript
295
+ function fib(n: number): number {
296
+ if (n < 2) {
297
+ return n;
298
+ }
299
+
300
+ return fib(n - 1) + fib(n - 2);
301
+ }
302
+
303
+ console.log(fib(10));
304
+ ```
305
+
306
+
307
+ ### Java
308
+
309
+ ```java
310
+ public class Fib {
311
+ static int fib(int n) {
312
+ if (n < 2) {
313
+ return n;
314
+ }
315
+
316
+ return fib(n - 1) + fib(n - 2);
317
+ }
318
+
319
+ public static void main(String[] args) {
320
+ System.out.println(fib(10));
321
+ }
322
+ }
323
+ ```
324
+
325
+
326
+ ### Shell
327
+
328
+ ```bash
329
+ fib() {
330
+ if [ "$1" -lt 2 ]; then
331
+ echo "$1"
332
+ else
333
+ a=$(fib $(($1 - 1)))
334
+ b=$(fib $(($1 - 2)))
335
+ echo $((a + b))
336
+ fi
337
+ }
338
+
339
+ fib 10
340
+ ```
341
+
342
+
343
+ ### Haskell
344
+
345
+ ```haskell
346
+ fib :: Int -> Int
347
+ fib n
348
+ | n < 2 = n
349
+ | otherwise = fib (n - 1) + fib (n - 2)
350
+
351
+ main :: IO ()
352
+ main = print (fib 10)
353
+ ```
354
+
355
+
356
+ ### SQL (Recursive CTE)
357
+
358
+ ```sql
359
+ WITH RECURSIVE fib(n, a, b) AS (
360
+ SELECT 0, 0, 1
361
+ UNION ALL
362
+ SELECT n + 1, b, a + b
363
+ FROM fib
364
+ WHERE n < 10
365
+ )
366
+ SELECT a
367
+ FROM fib
368
+ ORDER BY n DESC
369
+ LIMIT 1;
370
+ ```
@@ -0,0 +1,373 @@
1
+ # H1 heading should be red on yellow and bold
2
+
3
+
4
+ ## H2 heading should be black on pink and bold
5
+
6
+
7
+ ### H3 heading should be magenta on lightyellow and underlined
8
+
9
+ This paragraph has **strong text**, *emphasized text*, `inline code`, `=highlighted text=`, and [fatty on github](<https://github.com/ddoherty03/fatty>).
10
+
11
+ Autolink: <https://github.com/ddoherty03/fat_config>
12
+
13
+ > This block quote should have a red quote gutter. The quoted text itself can stay normal output for now.
14
+
15
+ ```ruby
16
+ # This ruby block. Has comments.
17
+ # Two lines, in fact.
18
+ def hello(name)
19
+ puts "hello #{name}"
20
+ end
21
+ ```
22
+
23
+ | Feature | Expected style |
24
+ |------------ |------------------- |
25
+ | Header cells | black on lightgreen |
26
+ | Body cells | normal output |
27
+
28
+
29
+ # Carnival of Constructs
30
+
31
+ These are samples of the kinds of constructs the ANSI renderer for `fatty` are capable of.
32
+
33
+
34
+ ## Unordered Lists
35
+
36
+ - builtin commands are handled by the `fatty` demo, Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
37
+ - other commands are handled by `/bin/sh`
38
+ - keybindings are listed below
39
+
40
+
41
+ ## Ordered Lists
42
+
43
+ 1. builtin commands are handled by the `fatty` demo, Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
44
+ 2. other commands are handled by `/bin/sh`
45
+ 3. keybindings are listed below
46
+
47
+ Some regular text to break things up.
48
+
49
+ 1. Parent ordered item
50
+ 1. Child ordered item
51
+ 2. Another child ordered item
52
+ 2. Back to parent ordered item
53
+
54
+
55
+ ## Description Lists
56
+
57
+ - **bold:** **this text is bold**
58
+ - **italic:** *this text is italic*
59
+ - **code:** `this text is code`
60
+ - **verbatim:** `this text is verbatim`
61
+ - **strike:** ~~this text is strike-through~~
62
+ - **underline:** <span class="underline">this text is underlined</span>
63
+
64
+
65
+ ## A Code Block
66
+
67
+ ```ruby
68
+ def wrap(text, first_prefix: "", rest_prefix: first_prefix)
69
+ width = [@width.to_i, 20].max
70
+
71
+ words = text.to_s.split(/\s+/)
72
+ lines = []
73
+ line = +""
74
+
75
+ words.each do |word|
76
+ prefix = lines.empty? ? first_prefix : rest_prefix
77
+ available = width - Fatty::Ansi.visible_length(prefix)
78
+ available = 20 if available < 20
79
+
80
+ candidate = line.empty? ? word : "#{line} #{word}"
81
+
82
+ if Fatty::Ansi.visible_length(candidate) > available && !line.empty?
83
+ lines << "#{prefix}#{line}"
84
+ line = word.dup
85
+ else
86
+ line = candidate
87
+ end
88
+ end
89
+
90
+ unless line.empty?
91
+ prefix = lines.empty? ? first_prefix : rest_prefix
92
+ lines << "#{prefix}#{line}"
93
+ end
94
+
95
+ lines.join("\n")
96
+ end
97
+ ```
98
+
99
+
100
+ ## Nested lists
101
+
102
+ - Parent item
103
+ - Child item
104
+ - Another child
105
+ - Back to parent
106
+
107
+
108
+ ## Links
109
+
110
+ [Fatty on GitHub](<https://github.com/ddoherty03/fatty>)
111
+
112
+
113
+ ## Block quotes
114
+
115
+ > Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
116
+ >
117
+ > Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
118
+ >
119
+ > But, in a larger sense, we can not dedicate&#x2014;we can not consecrate&#x2014;we can not hallow&#x2014;this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us&#x2014;that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion&#x2014;that we here highly resolve that these dead shall not have died in vain&#x2014;that this nation, under God, shall have a new birth of freedom&#x2014;and that government of the people, by the people, for the people, shall not perish from the earth.
120
+
121
+
122
+ ## Tables with styled cells
123
+
124
+ | Feature | Example |
125
+ |------- |--------------- |
126
+ | bold | **bold cell** |
127
+ | code | `code cell` |
128
+ | strike | ~~strike cell~~ |
129
+
130
+
131
+ ## Horizontal Rule
132
+
133
+ This should be a horizontal rule, but YMMV.
134
+
135
+ ---
136
+
137
+
138
+ ## Forced Line Break
139
+
140
+ This line has a forced line break<br> and this should appear on the next line.
141
+
142
+
143
+ ## Fenced code with various languages
144
+
145
+ Here is the Fibonacci number computed recursively in various languages.
146
+
147
+
148
+ ### Ruby
149
+
150
+ ```ruby
151
+ def fib(n)
152
+ return n if n < 2
153
+
154
+ fib(n - 1) + fib(n - 2)
155
+ end
156
+ puts fib(10)
157
+ ```
158
+
159
+
160
+ ### Python
161
+
162
+ ```python
163
+ def fib(n):
164
+ if n < 2:
165
+ return n
166
+
167
+ return fib(n - 1) + fib(n - 2)
168
+
169
+ print(fib(10))
170
+
171
+ ```
172
+
173
+
174
+ ### C
175
+
176
+ ```c
177
+ #include <stdio.h>
178
+
179
+ int fib(int n)
180
+ {
181
+ if (n < 2) {
182
+ return n;
183
+ }
184
+
185
+ return fib(n - 1) + fib(n - 2);
186
+ }
187
+
188
+ int main(void)
189
+ {
190
+ printf("%d\n", fib(10));
191
+ return 0;
192
+ }
193
+ ```
194
+
195
+
196
+ ### C++
197
+
198
+ ```cpp
199
+ #include <iostream>
200
+
201
+ int fib(int n)
202
+ {
203
+ if (n < 2) {
204
+ return n;
205
+ }
206
+
207
+ return fib(n - 1) + fib(n - 2);
208
+ }
209
+
210
+ int main()
211
+ {
212
+ std::cout << fib(10) << std::endl;
213
+ }
214
+ ```
215
+
216
+
217
+ ### Go
218
+
219
+ ```go
220
+ package main
221
+
222
+ import "fmt"
223
+
224
+ func fib(n int) int {
225
+ if n < 2 {
226
+ return n
227
+ }
228
+
229
+ return fib(n-1) + fib(n-2)
230
+ }
231
+
232
+ func main() {
233
+ fmt.Println(fib(10))
234
+ }
235
+ ```
236
+
237
+
238
+ ### Rust
239
+
240
+ ```rust
241
+ fn fib(n: u32) -> u32 {
242
+ if n < 2 {
243
+ n
244
+ } else {
245
+ fib(n - 1) + fib(n - 2)
246
+ }
247
+ }
248
+
249
+ fn main() {
250
+ println!("{}", fib(10));
251
+ }
252
+ ```
253
+
254
+
255
+ ### PHP
256
+
257
+ ```php
258
+ <?php
259
+
260
+ function fib($n)
261
+ {
262
+ if ($n < 2) {
263
+ return $n;
264
+ }
265
+
266
+ return fib($n - 1) + fib($n - 2);
267
+ }
268
+
269
+ echo fib(10) . PHP_EOL;
270
+ ```
271
+
272
+
273
+ ### JavaScript
274
+
275
+ ```javascript
276
+ function fib(n) {
277
+ if (n < 2) {
278
+ return n;
279
+ }
280
+
281
+ return fib(n - 1) + fib(n - 2);
282
+ }
283
+
284
+ console.log(fib(10));
285
+ ```
286
+
287
+
288
+ ### TypeScript
289
+
290
+ ```typescript
291
+ function fib(n: number): number {
292
+ if (n < 2) {
293
+ return n;
294
+ }
295
+
296
+ return fib(n - 1) + fib(n - 2);
297
+ }
298
+
299
+ console.log(fib(10));
300
+ ```
301
+
302
+
303
+ ### Java
304
+
305
+ ```java
306
+ public class Fib {
307
+ static int fib(int n) {
308
+ if (n < 2) {
309
+ return n;
310
+ }
311
+
312
+ return fib(n - 1) + fib(n - 2);
313
+ }
314
+
315
+ public static void main(String[] args) {
316
+ System.out.println(fib(10));
317
+ }
318
+ }
319
+ ```
320
+
321
+
322
+ ### Shell
323
+
324
+ ```bash
325
+ fib() {
326
+ if [ "$1" -lt 2 ]; then
327
+ echo "$1"
328
+ else
329
+ a=$(fib $(($1 - 1)))
330
+ b=$(fib $(($1 - 2)))
331
+ echo $((a + b))
332
+ fi
333
+ }
334
+
335
+ fib 10
336
+ ```
337
+
338
+
339
+ ### Haskell
340
+
341
+ ```haskell
342
+ fib :: Int -> Int
343
+ fib n
344
+ | n < 2 = n
345
+ | otherwise = fib (n - 1) + fib (n - 2)
346
+
347
+ main :: IO ()
348
+ main = print (fib 10)
349
+ ```
350
+
351
+
352
+ ### SQL (Recursive CTE)
353
+
354
+ ```sql
355
+ WITH RECURSIVE fib(n, a, b) AS (
356
+ SELECT 0, 0, 1
357
+ UNION ALL
358
+ SELECT n + 1, b, a + b
359
+ FROM fib
360
+ WHERE n < 10
361
+ )
362
+ SELECT a
363
+ FROM fib
364
+ ORDER BY n DESC
365
+ LIMIT 1;
366
+ ```
367
+
368
+
369
+ ### Nonsense Language
370
+
371
+ ```madeuplang
372
+ this should still render as plain text
373
+ ```