fatty 0.99.0 → 0.99.3

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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.org +11 -29
  3. data/README.md +2207 -18
  4. data/README.org +2066 -104
  5. data/exe/fatty +236 -93
  6. data/help/help.md +233 -0
  7. data/lib/fatty/action.rb +3 -7
  8. data/lib/fatty/actionable.rb +2 -0
  9. data/lib/fatty/alert.rb +65 -39
  10. data/lib/fatty/ansi/renderer.rb +26 -6
  11. data/lib/fatty/ansi.rb +1 -0
  12. data/lib/fatty/api/alert.rb +15 -0
  13. data/lib/fatty/api/choose.rb +145 -0
  14. data/lib/fatty/api/environment.rb +12 -0
  15. data/lib/fatty/api/keytest.rb +11 -0
  16. data/lib/fatty/api/menu.rb +104 -0
  17. data/lib/fatty/api/output.rb +55 -0
  18. data/lib/fatty/api/progress.rb +24 -0
  19. data/lib/fatty/api/prompt.rb +77 -0
  20. data/lib/fatty/api/status.rb +55 -0
  21. data/lib/fatty/api.rb +38 -0
  22. data/lib/fatty/callback_environment.rb +74 -0
  23. data/lib/fatty/colors/color.rb +366 -232
  24. data/lib/fatty/colors/pairs.rb +2 -0
  25. data/lib/fatty/command.rb +78 -0
  26. data/lib/fatty/config.rb +227 -39
  27. data/lib/fatty/config_files/config.yml +4 -12
  28. data/lib/fatty/config_files/keydefs.yml +13 -23
  29. data/lib/fatty/config_files/themes/capuchin_monk.yml +140 -0
  30. data/lib/fatty/config_files/themes/catppuccin_latte.yml +140 -0
  31. data/lib/fatty/config_files/themes/catppuccin_mocha.yml +140 -0
  32. data/lib/fatty/config_files/themes/cyberpunk.yml +141 -0
  33. data/lib/fatty/config_files/themes/dracula.yml +140 -0
  34. data/lib/fatty/config_files/themes/everforest_dark.yml +140 -0
  35. data/lib/fatty/config_files/themes/gruvbox_dark.yml +140 -0
  36. data/lib/fatty/config_files/themes/gruvbox_light.yml +140 -0
  37. data/lib/fatty/config_files/themes/mono.yml +119 -47
  38. data/lib/fatty/config_files/themes/monokai.yml +140 -0
  39. data/lib/fatty/config_files/themes/nordic.yml +1 -0
  40. data/lib/fatty/config_files/themes/onedark.yml +140 -0
  41. data/lib/fatty/config_files/themes/solarized_dark.yml +1 -0
  42. data/lib/fatty/config_files/themes/solarized_light.yml +140 -0
  43. data/lib/fatty/config_files/themes/terminal.yml +67 -0
  44. data/lib/fatty/config_files/themes/tokyo_night.yml +140 -0
  45. data/lib/fatty/config_files/themes/wordperfect.yml +80 -9
  46. data/lib/fatty/core_ext/hash.rb +19 -0
  47. data/lib/fatty/core_ext/string.rb +19 -12
  48. data/lib/fatty/core_ext.rb +1 -0
  49. data/lib/fatty/curses/context.rb +86 -84
  50. data/lib/fatty/curses/event_source.rb +128 -40
  51. data/lib/fatty/curses/key_decoder.rb +77 -11
  52. data/lib/fatty/env.rb +21 -20
  53. data/lib/fatty/help.rb +1 -29
  54. data/lib/fatty/history/entry.rb +2 -0
  55. data/lib/fatty/history.rb +17 -14
  56. data/lib/fatty/input_buffer.rb +71 -47
  57. data/lib/fatty/input_field.rb +216 -149
  58. data/lib/fatty/key_event.rb +67 -66
  59. data/lib/fatty/key_map.rb +54 -16
  60. data/lib/fatty/keymaps/emacs.rb +40 -6
  61. data/lib/fatty/log_formats/json.rb +2 -0
  62. data/lib/fatty/log_formats/text.rb +2 -0
  63. data/lib/fatty/logger.rb +7 -2
  64. data/lib/fatty/markdown/ansi_renderer.rb +75 -6
  65. data/lib/fatty/markdown/render.rb +2 -3
  66. data/lib/fatty/mouse_event.rb +142 -2
  67. data/lib/fatty/output_buffer.rb +2 -0
  68. data/lib/fatty/pager.rb +158 -47
  69. data/lib/fatty/progress.rb +417 -0
  70. data/lib/fatty/renderer/curses.rb +340 -184
  71. data/lib/fatty/renderer/truecolor.rb +266 -163
  72. data/lib/fatty/renderer.rb +115 -97
  73. data/lib/fatty/screen.rb +2 -0
  74. data/lib/fatty/session/alert_session.rb +39 -21
  75. data/lib/fatty/session/isearch_session.rb +92 -38
  76. data/lib/fatty/session/keytest_session.rb +105 -85
  77. data/lib/fatty/session/modal_session.rb +38 -1
  78. data/lib/fatty/session/output_session.rb +472 -21
  79. data/lib/fatty/session/popup_session.rb +251 -134
  80. data/lib/fatty/session/prompt_session.rb +68 -26
  81. data/lib/fatty/session/search_session.rb +79 -31
  82. data/lib/fatty/session/shell_session.rb +383 -368
  83. data/lib/fatty/session/status_session.rb +167 -0
  84. data/lib/fatty/session.rb +95 -95
  85. data/lib/fatty/terminal/popup_owner.rb +14 -11
  86. data/lib/fatty/terminal.rb +515 -813
  87. data/lib/fatty/themes/loader.rb +4 -2
  88. data/lib/fatty/themes/manager.rb +4 -0
  89. data/lib/fatty/themes/registry.rb +2 -0
  90. data/lib/fatty/themes/resolver.rb +175 -162
  91. data/lib/fatty/version.rb +1 -1
  92. data/lib/fatty/viewport.rb +8 -1
  93. data/lib/fatty.rb +35 -7
  94. metadata +42 -40
  95. data/.envrc +0 -2
  96. data/.simplecov +0 -23
  97. data/.yardopts +0 -4
  98. data/CHANGELOG.md +0 -34
  99. data/Rakefile +0 -15
  100. data/TODO.org +0 -163
  101. data/examples/markdown/native-markdown.md +0 -370
  102. data/examples/markdown/ox-gfm-markdown.md +0 -373
  103. data/examples/markdown/ox-gfm-markdown.org +0 -376
  104. data/fatty.gemspec +0 -42
  105. data/lib/fatty/accept_env.rb +0 -32
  106. data/lib/fatty/config_files/help.md +0 -120
  107. data/lib/fatty/config_files/help.org +0 -124
  108. data/lib/fatty/config_files/themes/wordperfect_light.yml +0 -77
  109. data/lib/fatty/menu_env.rb +0 -22
  110. data/lib/fatty/session/input_session.rb +0 -99
  111. data/lib/fatty/sessions.rb +0 -14
  112. data/lib/fatty/terminal/progress.rb +0 -374
  113. data/lib/fatty/view/alert_view.rb +0 -14
  114. data/lib/fatty/view/cursor_view.rb +0 -18
  115. data/lib/fatty/view/input_view.rb +0 -9
  116. data/lib/fatty/view/output_view.rb +0 -9
  117. data/lib/fatty/view/status_view.rb +0 -14
  118. data/lib/fatty/view.rb +0 -33
  119. data/lib/fatty/views.rb +0 -9
  120. data/sig/fatty.rbs +0 -4
data/lib/fatty/help.rb CHANGED
@@ -1,37 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require "redcarpet"
4
- # require_relative "ansi_renderer"
5
-
6
- # module Fatty
7
- # module Help
8
- # def self.path
9
- # File.expand_path("config_files/help.md", __dir__)
10
- # end
11
-
12
- # def self.render(width: 80)
13
- # renderer = Fatty::AnsiRenderer.new(width: width)
14
- # markdown = Redcarpet::Markdown.new(
15
- # renderer,
16
- # tables: true,
17
- # fenced_code_blocks: true,
18
- # autolink: true,
19
- # )
20
- # markdown.render(text)
21
- # end
22
-
23
- # def self.text
24
- # File.read(path)
25
- # end
26
- # end
27
- # end
28
-
29
- # frozen_string_literal: true
30
-
31
3
  module Fatty
32
4
  module Help
33
5
  def self.path
34
- File.expand_path("config_files/help.md", __dir__)
6
+ File.expand_path("../../help/help.md", __dir__)
35
7
  end
36
8
 
37
9
  def self.text
@@ -55,6 +55,8 @@ module Fatty
55
55
  nil
56
56
  end
57
57
 
58
+ # simplecov:disable
59
+
58
60
  private_class_method :parse_stamp
59
61
 
60
62
  private
data/lib/fatty/history.rb CHANGED
@@ -25,10 +25,10 @@ module Fatty
25
25
  @cursors = {}
26
26
 
27
27
  if @path
28
- Fatty.info("History loaded from #{@path}")
28
+ Fatty.info("History loaded from #{@path}", tag: :config)
29
29
  load
30
30
  else
31
- Fatty.info("In-memory History only: no path")
31
+ Fatty.info("In-memory History only: no path", tag: :config)
32
32
  end
33
33
  end
34
34
 
@@ -47,10 +47,6 @@ module Fatty
47
47
  @instances = {}
48
48
  end
49
49
 
50
- def self.default
51
- for_path(:default)
52
- end
53
-
54
50
  ###################################################################################
55
51
  # Accessing History items from a consuming application
56
52
  ###################################################################################
@@ -164,19 +160,24 @@ module Fatty
164
160
  cursor[:scratch] = nil
165
161
  end
166
162
 
167
- def suggest_for(*kinds, prefix:, ctx: nil)
163
+ def suggestions_for(*kinds, prefix:, ctx: nil, limit: nil)
168
164
  text = prefix.to_s
169
- return if text.empty?
165
+ return [] if text.empty?
170
166
 
171
167
  wanted_ctx = normalize_ctx(ctx)
172
168
 
173
- unless wanted_ctx.empty?
174
- local = entries_for(*kinds, ctx: wanted_ctx, prefix: text)
175
- return local.last.text unless local.empty?
176
- end
169
+ rows =
170
+ if wanted_ctx.empty?
171
+ entries_for(*kinds, prefix: text)
172
+ else
173
+ local = entries_for(*kinds, ctx: wanted_ctx, prefix: text)
174
+ global = entries_for(*kinds, prefix: text)
175
+ local + global
176
+ end
177
177
 
178
- global = entries_for(*kinds, prefix: text)
179
- global.last&.text
178
+ rows = rows.reverse.map(&:text).uniq
179
+ rows = rows.first(limit) if limit
180
+ rows
180
181
  end
181
182
 
182
183
  def self.normalize_ctx(ctx)
@@ -189,6 +190,8 @@ module Fatty
189
190
 
190
191
  private
191
192
 
193
+ # simplecov:disable
194
+
192
195
  def normalize_kinds(*kinds)
193
196
  kinds.flatten.map(&:to_sym).uniq.sort
194
197
  end
@@ -35,22 +35,19 @@ module Fatty
35
35
  include Actionable
36
36
 
37
37
  attr_reader :mark, :kill_ring, :undo_stack
38
- attr_accessor :text, :cursor, :word_re, :virtual_suffix
38
+ attr_accessor :text, :cursor, :word_char_re, :virtual_suffix
39
39
 
40
- DEFAULT_WORD_CHARS = "[[:alnum:]_]"
40
+ DEFAULT_WORD_CHAR_RE = "[[:alnum:]_]"
41
41
 
42
- def initialize(word_chars: DEFAULT_WORD_CHARS, word_re: nil, undo_limit: 1_000, kill_ring_max: 60)
42
+ def initialize(word_char_re: DEFAULT_WORD_CHAR_RE, undo_limit: 1_000, kill_ring_max: 60)
43
43
  @text = +""
44
44
  @virtual_suffix = +""
45
45
  @cursor = 0
46
46
  @mark = nil
47
- @word_re =
48
- if word_re
49
- word_re
50
- else
51
- # word_chars is a fragment like "[[:alnum:]_]" or "[[:alnum:]_-]"
52
- Regexp.new(word_chars)
53
- end
47
+ # word_char_re is a fragment like "[[:alnum:]_]" or "[[:alnum:]_-]"
48
+ # meant to match a single charachter that should be considered a part of
49
+ # a word for purposes of cursor movement.
50
+ @word_char_re = normalize_word_char_re(word_char_re)
54
51
  @undo_limit = undo_limit
55
52
  @undo_stack = []
56
53
  @redo_stack = []
@@ -289,7 +286,7 @@ module Fatty
289
286
  desc "Delete the character before the cursor"
290
287
  action :delete_char_backward do |count: 1|
291
288
  if region_active?
292
- delete_region
289
+ kill_region
293
290
  else
294
291
  n = normalize_count(count)
295
292
  return if @cursor.zero?
@@ -309,7 +306,7 @@ module Fatty
309
306
  desc "Delete count characters after the cursor"
310
307
  action :delete_char_forward do |count: 1|
311
308
  if region_active?
312
- delete_region
309
+ kill_region
313
310
  else
314
311
  n = normalize_count(count)
315
312
  return if @cursor == text.length
@@ -352,56 +349,66 @@ module Fatty
352
349
  killed
353
350
  end
354
351
 
355
- desc "Kill count words after the cursor and return the deleted string"
352
+ desc "Kill count words after the cursor, or kill the active region"
356
353
  action :kill_word_forward do |count: 1|
357
- n = normalize_count(count)
358
- return "" if eol?
354
+ if region_active?
355
+ kill_region
356
+ else
357
+ n = normalize_count(count)
358
+ return "" if eol?
359
359
 
360
- deleted = ""
361
- with_undo do
362
- start = cursor
363
- finish = start
364
- repeat(n) do
365
- break if finish >= text.length
360
+ deleted = ""
361
+ with_undo do
362
+ start = cursor
363
+ finish = start
364
+
365
+ repeat(n) do
366
+ break if finish >= text.length
366
367
 
367
- span = word_span_forward(finish)
368
- break if span.begin == span.end
368
+ span = word_span_forward(finish)
369
+ break if span.begin == span.end
370
+
371
+ finish = span.end
372
+ end
369
373
 
370
- finish = span.end
374
+ deleted = delete_range(start...finish)
375
+ @cursor = start
376
+ push_kill(deleted)
377
+ @last_action = :kill
371
378
  end
372
379
 
373
- deleted = delete_range(start...finish)
374
- @cursor = start
375
- push_kill(deleted)
376
- @last_action = :kill
380
+ deleted
377
381
  end
378
- deleted
379
382
  end
380
383
 
381
384
  desc "Kill count words before the cursor and return the deleted string"
382
385
  action :kill_word_backward do |count: 1|
383
- n = normalize_count(count)
384
- return "" if bol?
386
+ if region_active?
387
+ kill_region
388
+ else
389
+ n = normalize_count(count)
390
+ return "" if bol?
385
391
 
386
- deleted = ""
387
- with_undo do
388
- finish = cursor
389
- start = finish
390
- repeat(n) do
391
- break if start <= 0
392
+ deleted = ""
393
+ with_undo do
394
+ finish = cursor
395
+ start = finish
396
+ repeat(n) do
397
+ break if start <= 0
392
398
 
393
- span = word_span_backward(start)
394
- break if span.begin == span.end
399
+ span = word_span_backward(start)
400
+ break if span.begin == span.end
395
401
 
396
- start = span.begin
397
- end
402
+ start = span.begin
403
+ end
398
404
 
399
- deleted = delete_range(start...finish)
400
- @cursor = start
401
- push_kill(deleted)
402
- @last_action = :kill
405
+ deleted = delete_range(start...finish)
406
+ @cursor = start
407
+ push_kill(deleted)
408
+ @last_action = :kill
409
+ end
410
+ deleted
403
411
  end
404
- deleted
405
412
  end
406
413
 
407
414
  desc "Transpose the two characters around point."
@@ -707,6 +714,23 @@ module Fatty
707
714
 
708
715
  private
709
716
 
717
+ # simplecov:disable
718
+
719
+ def normalize_word_char_re(value)
720
+ case value
721
+ when Regexp
722
+ value
723
+ when String
724
+ value = value.strip
725
+ if value.start_with?("/") && value.end_with?("/") && value.length >= 2
726
+ value[1...-1]
727
+ else
728
+ value
729
+ end
730
+ Regexp.new(value)
731
+ end
732
+ end
733
+
710
734
  def move_word_right_once
711
735
  break_undo_chain!
712
736
  chars = virtual_text.chars
@@ -992,7 +1016,7 @@ module Fatty
992
1016
  end
993
1017
 
994
1018
  def word_char?(ch)
995
- @word_re.match?(ch)
1019
+ @word_char_re.match?(ch)
996
1020
  end
997
1021
  end
998
1022
  end