fatty 0.99.10.0 → 0.99.12.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.org +30 -0
  3. data/README.md +263 -230
  4. data/README.org +49 -5
  5. data/examples/markdown/native-markdown.md +370 -0
  6. data/examples/markdown/ox-gfm-markdown.md +373 -0
  7. data/exe/fatty +43 -41
  8. data/exe/themer +10 -10
  9. data/help/help.md +1 -0
  10. data/lib/fatty/alert.rb +1 -1
  11. data/lib/fatty/ansi/renderer.rb +8 -4
  12. data/lib/fatty/ansi/windows_console.rb +40 -0
  13. data/lib/fatty/ansi.rb +0 -5
  14. data/lib/fatty/api/choose.rb +2 -2
  15. data/lib/fatty/api/menu.rb +3 -0
  16. data/lib/fatty/api/output.rb +13 -5
  17. data/lib/fatty/api/progress.rb +6 -6
  18. data/lib/fatty/api/prompt.rb +3 -1
  19. data/lib/fatty/api/status.rb +1 -1
  20. data/lib/fatty/api.rb +12 -10
  21. data/lib/fatty/callback_environment.rb +1 -0
  22. data/lib/fatty/colors/color.rb +7 -30
  23. data/lib/fatty/config.rb +11 -11
  24. data/lib/fatty/curses/context.rb +41 -11
  25. data/lib/fatty/curses/event_source.rb +85 -26
  26. data/lib/fatty/curses/key_decoder.rb +54 -22
  27. data/lib/fatty/curses/patch.rb +2 -0
  28. data/lib/fatty/curses/pdcurses_keys.rb +154 -0
  29. data/lib/fatty/curses/windows_keyboard.rb +35 -0
  30. data/lib/fatty/env.rb +14 -12
  31. data/lib/fatty/help.rb +26 -18
  32. data/lib/fatty/input_field.rb +55 -17
  33. data/lib/fatty/key_event.rb +1 -4
  34. data/lib/fatty/keymaps/emacs.rb +12 -2
  35. data/lib/fatty/markdown/ansi_renderer.rb +1 -1
  36. data/lib/fatty/markdown/render.rb +10 -3
  37. data/lib/fatty/mouse_event.rb +3 -3
  38. data/lib/fatty/output_buffer.rb +1 -2
  39. data/lib/fatty/pager.rb +7 -7
  40. data/lib/fatty/progress.rb +2 -2
  41. data/lib/fatty/renderer/curses.rb +28 -27
  42. data/lib/fatty/renderer/truecolor.rb +8 -1
  43. data/lib/fatty/renderer.rb +6 -6
  44. data/lib/fatty/session/keytest_session.rb +2 -1
  45. data/lib/fatty/session/output_session.rb +3 -5
  46. data/lib/fatty/session/popup_session.rb +24 -24
  47. data/lib/fatty/session/prompt_session.rb +1 -1
  48. data/lib/fatty/session/shell_session.rb +11 -5
  49. data/lib/fatty/session/status_session.rb +2 -2
  50. data/lib/fatty/shell.rb +60 -0
  51. data/lib/fatty/terminal.rb +24 -19
  52. data/lib/fatty/version.rb +1 -1
  53. data/lib/fatty.rb +9 -10
  54. metadata +24 -18
data/README.org CHANGED
@@ -1,11 +1,23 @@
1
- #+OPTIONS: toc:4 H:4
1
+ #+OPTIONS: toc:nil H:4
2
+ #+PROPERTY: header-args :eval never
2
3
  #+PROPERTY: header-args:ruby :results value :colnames no :hlines yes :exports both :dir "./"
3
- #+PROPERTY: header-args:ruby+ :wrap example :session fatty_session :eval yes
4
+ #+PROPERTY: header-args:ruby+ :wrap example :session fatty_session
4
5
  #+PROPERTY: header-args:ruby+ :prologue "$:.unshift('./lib') unless $:.first == './lib'; require 'fatty'"
5
6
  #+PROPERTY: header-args:ruby+ :ruby "bundle exec irb"
6
7
  #+PROPERTY: header-args:sh :exports code :eval no
7
8
  #+PROPERTY: header-args:bash :exports code :eval no
8
9
 
10
+ #+BEGIN_EXPORT markdown
11
+ [![CI](https://github.com/ddoherty03/fatty/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/ddoherty03/fatty/actions/workflows/main.yml)
12
+ #+END_EXPORT
13
+
14
+
15
+ # gem_docs:version begin
16
+ Version: 0.99.12.0
17
+ # gem_docs:version end
18
+
19
+ #+TOC: headlines 4
20
+
9
21
  * Introduction
10
22
  ~Fatty~ aims to provide a full-featured command-line environment that provides:
11
23
 
@@ -245,7 +257,7 @@ The =on_accept= callback can send text to the output pane in three ways:
245
257
 
246
258
  1. by returning a value from the callback;
247
259
  2. by calling =append= or =markdown= on the callback environment; or
248
- 3. by calling =append_now= on the callback environment.
260
+ 3. by calling =append_now= or =markdown_now= on the callback environment.
249
261
 
250
262
  A returned =String= is the simplest output mechanism. It is displayed after
251
263
  the callback finishes:
@@ -260,13 +272,13 @@ Calls to =append= and =markdown= also queue output until the callback finishes.
260
272
  If a callback both calls =append= or =markdown= and returns a =String=, the
261
273
  queued output is displayed first and the returned string is displayed after it.
262
274
 
263
- Calls to =append_now= are different. They append text and immediately render a
275
+ Calls to =append_now= and =markdown_now= are different. They append text and immediately render a
264
276
  frame, so the user can see output while the callback is still running. Use
265
277
  =append_now= for long-running callbacks that should stream progress to the
266
278
  output pane.
267
279
 
268
280
  At the end of the callback, =Fatty= finishes the command and updates the pager
269
- state. Output produced with =append_now= may therefore appear during the
281
+ state. Output produced with =append_now= or =markdown_now= may therefore appear during the
270
282
  callback, while output from =append=, =markdown=, and the callback's return
271
283
  value appears after the callback returns.
272
284
 
@@ -421,6 +433,12 @@ This line has a forced line break
421
433
  and this should appear on the next line.
422
434
  #+end_example
423
435
 
436
+ *** =markdown_now(text)=
437
+ Render Markdown using the current theme, then call =append_now= to display it
438
+ immediately. Like =markdown=, this returns =nil=. Previously queued output
439
+ remains queued. Use this when Markdown should be visible before a prompt or
440
+ while a callback is still running.
441
+
424
442
  *** =status(text, role: :info)=
425
443
  Display the text in the "status" area, the lines immediately above the input
426
444
  field, using one of the following "roles":
@@ -2277,3 +2295,29 @@ warn:
2277
2295
  error:
2278
2296
  fg: "#e78d8d"
2279
2297
  #+end_example
2298
+
2299
+ * Windows differences
2300
+ All demo commands have been tested on Windows 11 with RubyInstaller 3.4.
2301
+ Compared with Linux, the following differences apply:
2302
+
2303
+ - Windows currently requires a patched curses build for temporarily
2304
+ handing the terminal to external commands and interactive programs.
2305
+ The patch is available at:
2306
+ https://github.com/ddoherty03/curses/tree/preserve-screen-suspension
2307
+
2308
+ - Mouse input is unavailable with the Windows curses build tested.
2309
+
2310
+ - Alt is displayed as Meta (=M-=). Windows may intercept some shortcuts
2311
+ before Fatty receives them. Alt+numpad retains Windows character-entry
2312
+ behavior; for example, Alt+keypad-7 produces Ctrl-G, which closes
2313
+ =keytest=. Some hardware-specific keys may be unavailable.
2314
+
2315
+ - Windows intercepts some key chords, including M-TAB, so F2 has been
2316
+ provided as an alternative for popup completions.
2317
+
2318
+ - External commands use Windows command syntax, including =cmd.exe=
2319
+ built-ins such as =dir=, rather than PowerShell aliases. Path completion
2320
+ uses Windows backslash separators.
2321
+
2322
+ - Exiting Fatty does not restore a saved copy of the screen that was
2323
+ visible before startup.
@@ -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
+ ```