markdown_exec 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Gemfile.lock +2 -2
  4. data/Rakefile +3 -3
  5. data/bats/block-types.bats +13 -7
  6. data/bats/import.bats +6 -0
  7. data/bats/markup.bats +6 -15
  8. data/bats/options-collapse.bats +26 -0
  9. data/bats/options.bats +1 -1
  10. data/bats/table.bats +8 -0
  11. data/bats/test_helper.bash +74 -49
  12. data/bats/variable-expansion.bats +46 -0
  13. data/bin/tab_completion.sh +1 -1
  14. data/docs/dev/bats-document-configuration.md +8 -1
  15. data/docs/dev/block-type-bash.md +1 -1
  16. data/docs/dev/block-type-opts.md +1 -5
  17. data/docs/dev/block-type-vars.md +4 -0
  18. data/docs/dev/import-missing.md +2 -0
  19. data/docs/dev/menu-cli.md +1 -1
  20. data/docs/dev/options-collapse.md +47 -0
  21. data/docs/dev/requiring-blocks.md +3 -0
  22. data/docs/dev/specs.md +2 -1
  23. data/docs/dev/table-crash.md +39 -0
  24. data/docs/dev/table-indent.md +26 -0
  25. data/docs/dev/text-decoration.md +2 -5
  26. data/docs/dev/variable-expansion.md +2 -4
  27. data/examples/bash-blocks.md +1 -1
  28. data/examples/block-names.md +1 -1
  29. data/examples/block-types.md +1 -1
  30. data/examples/data-files.md +1 -1
  31. data/examples/document_options.md +2 -2
  32. data/examples/indent.md +1 -1
  33. data/examples/interrupt.md +1 -1
  34. data/examples/link-blocks-vars.md +1 -1
  35. data/examples/linked.md +1 -1
  36. data/examples/linked1.md +1 -1
  37. data/examples/nickname.md +1 -1
  38. data/examples/opts-blocks-require.md +1 -1
  39. data/examples/opts-blocks.md +1 -1
  40. data/examples/opts_output_execution.md +1 -1
  41. data/examples/pass-through-arguments.md +1 -1
  42. data/examples/pause-after-execution.md +1 -1
  43. data/examples/port-blocks.md +1 -1
  44. data/examples/save.md +1 -1
  45. data/examples/text-markup.md +1 -1
  46. data/examples/variable-expansion.md +6 -2
  47. data/examples/vars-blocks.md +1 -1
  48. data/examples/wrap.md +1 -1
  49. data/lib/block_types.rb +4 -0
  50. data/lib/cached_nested_file_reader.rb +7 -4
  51. data/lib/collapser.rb +302 -0
  52. data/lib/constants.rb +10 -0
  53. data/lib/evaluate_shell_expressions.rb +0 -3
  54. data/lib/fcb.rb +13 -17
  55. data/lib/format_table.rb +11 -7
  56. data/lib/hash_delegator.rb +461 -272
  57. data/lib/hierarchy_string.rb +5 -1
  58. data/lib/markdown_exec/version.rb +1 -1
  59. data/lib/markdown_exec.rb +16 -32
  60. data/lib/mdoc.rb +100 -35
  61. data/lib/menu.src.yml +124 -17
  62. data/lib/menu.yml +102 -16
  63. data/lib/ww.rb +75 -22
  64. metadata +12 -9
  65. data/lib/append_to_bash_history.rb +0 -303
  66. data/lib/ce_get_cost_and_usage.rb +0 -23
  67. data/lib/doh.rb +0 -190
  68. data/lib/layered_hash.rb +0 -143
  69. data/lib/poly.rb +0 -171
data/lib/menu.yml CHANGED
@@ -8,6 +8,10 @@
8
8
  :arg_name: BOOL
9
9
  :default: false
10
10
  :procname: val_as_bool
11
+ - :opt_name: block_batch_match
12
+ :env_var: MDE_BLOCK_BATCH_MATCH
13
+ :default: "@batch"
14
+ :procname: val_as_str
11
15
  - :opt_name: block_calls_scan
12
16
  :env_var: MDE_BLOCK_CALLS_SCAN
13
17
  :default: "%\\([^\\)]+\\)"
@@ -16,6 +20,10 @@
16
20
  :env_var: MDE_BLOCK_DISABLE_MATCH
17
21
  :default: "@disable"
18
22
  :procname: val_as_str
23
+ - :opt_name: block_interactive_match
24
+ :env_var: MDE_BLOCK_INTERACTIVE_MATCH
25
+ :default: "@interactive"
26
+ :procname: val_as_str
19
27
  - :opt_name: block_name
20
28
  :long_name: block-name
21
29
  :short_name: b
@@ -112,6 +120,24 @@
112
120
  :env_var: MDE_DISPLAY_LEVEL_XBASE_PREFIX
113
121
  :default: "> "
114
122
  :procname: val_as_str
123
+ - :opt_name: divider_match
124
+ :env_var: MDE_DIVIDER_MATCH
125
+ :description: Pattern for topics/dividers in block selection menu
126
+ :default: "^(?<indent>[ \t]*):::(?<collapse>[+-~]?)(?<leading>[ \t]*)(?<line>(?<text>.*?)(?<trailing>[
127
+ \t]*))?$"
128
+ :procname: val_as_str
129
+ - :opt_name: divider4_center
130
+ :env_var: MDE_DIVIDER4_CENTER
131
+ :default: true
132
+ :procname: val_as_bool
133
+ - :opt_name: divider4_collapse
134
+ :env_var: MDE_DIVIDER_COLLAPSE
135
+ :default: false
136
+ :procname: val_as_bool
137
+ - :opt_name: divider4_collapsible
138
+ :env_var: MDE_DIVIDER_COLLAPSIBLE
139
+ :default: true
140
+ :procname: val_as_bool
115
141
  - :opt_name: document_configurations_directory
116
142
  :env_var: MDE_DOCUMENT_CONFIGURATIONS_DIRECTORY
117
143
  :description: Directory with files
@@ -133,7 +159,16 @@
133
159
  - :opt_name: document_load_opts_block_name
134
160
  :env_var: MDE_DOCUMENT_LOAD_OPTS_BLOCK_NAME
135
161
  :description: Name of Opts block to load with the document
136
- :default: "(document_options)"
162
+ :default: "(document_opts)"
163
+ :procname: val_as_str
164
+ - :opt_name: document_load_vars_block_name
165
+ :env_var: MDE_DOCUMENT_LOAD_VARS_BLOCK_NAME
166
+ :description: Name of Vars block to load with the document
167
+ :default: "(document_vars)"
168
+ :procname: val_as_str
169
+ - :opt_name: document_play_bin
170
+ :env_var: MDE_DOCUMENT_PLAY_BIN
171
+ :default: play
137
172
  :procname: val_as_str
138
173
  - :opt_name: document_saved_lines_glob
139
174
  :env_var: MDE_DOCUMENT_SAVED_LINES_GLOB
@@ -341,25 +376,52 @@
341
376
  :env_var: MDE_HEADING1_CENTER
342
377
  :default: true
343
378
  :procname: val_as_bool
344
- - :opt_name: heading2_center
345
- :env_var: MDE_HEADING1_CENTER
346
- :default: true
379
+ - :opt_name: heading1_collapse
380
+ :env_var: MDE_HEADING1_COLLAPSE
381
+ :default: false
347
382
  :procname: val_as_bool
348
- - :opt_name: heading3_center
349
- :env_var: MDE_HEADING1_CENTER
350
- :default: true
383
+ - :opt_name: heading1_collapsible
384
+ :env_var: MDE_HEADING1_COLLAPSIBLE
385
+ :default: false
351
386
  :procname: val_as_bool
352
387
  - :opt_name: heading1_match
353
388
  :env_var: MDE_HEADING1_MATCH
354
- :default: "^#(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
389
+ :default: "^#(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
390
+ \t]*))?$"
355
391
  :procname: val_as_str
392
+ - :opt_name: heading2_center
393
+ :env_var: MDE_HEADING2_CENTER
394
+ :default: true
395
+ :procname: val_as_bool
396
+ - :opt_name: heading2_collapse
397
+ :env_var: MDE_HEADING2_COLLAPSE
398
+ :default: false
399
+ :procname: val_as_bool
400
+ - :opt_name: heading2_collapsible
401
+ :env_var: MDE_HEADING2_COLLAPSIBLE
402
+ :default: true
403
+ :procname: val_as_bool
356
404
  - :opt_name: heading2_match
357
405
  :env_var: MDE_HEADING2_MATCH
358
- :default: "^##(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
406
+ :default: "^##(?<line>(?!#)(?<collapse>[+-~]?)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
407
+ \t]*))?$"
359
408
  :procname: val_as_str
409
+ - :opt_name: heading3_center
410
+ :env_var: MDE_HEADING3_CENTER
411
+ :default: true
412
+ :procname: val_as_bool
413
+ - :opt_name: heading3_collapse
414
+ :env_var: MDE_HEADING3_COLLAPSE
415
+ :default: false
416
+ :procname: val_as_bool
417
+ - :opt_name: heading3_collapsible
418
+ :env_var: MDE_HEADING3_COLLAPSIBLE
419
+ :default: true
420
+ :procname: val_as_bool
360
421
  - :opt_name: heading3_match
361
422
  :env_var: MDE_HEADING3_MATCH
362
- :default: "^###(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
423
+ :default: "^###(?<collapse>[+-~]?)(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[
424
+ \t]*))?$"
363
425
  :procname: val_as_str
364
426
  - :long_name: help
365
427
  :short_name: h
@@ -501,6 +563,12 @@
501
563
  :env_var: MDE_MD_FILENAME_MATCH
502
564
  :default: ".+\\.md"
503
565
  :procname: val_as_str
566
+ - :opt_name: menu_active_color_pastel_messages
567
+ :env_var: MDE_MENU_ACTIVE_COLOR_PASTEL_MESSAGES
568
+ :description: menu_active_color_pastel_messages
569
+ :default:
570
+ - bright_magenta
571
+ - on_black
504
572
  - :opt_name: menu_back_at_top
505
573
  :env_var: MDE_MENU_BACK_AT_TOP
506
574
  :description: Display Back option at top of menu (vs bottom)
@@ -535,6 +603,16 @@
535
603
  :description: format for menu chromes
536
604
  :default: "%{line}"
537
605
  :procname: val_as_str
606
+ - :opt_name: menu_collapsible_symbol_collapsed
607
+ :env_var: MDE_MENU_COLLAPSIBLE_SYMBOL_COLLAPSED
608
+ :description: menu_collapsible_symbol_collapsed
609
+ :default: "⬢"
610
+ :procname: val_as_str
611
+ - :opt_name: menu_collapsible_symbol_expanded
612
+ :env_var: MDE_MENU_COLLAPSIBLE_SYMBOL_expandED
613
+ :description: menu_collapsible_symbol_expanded
614
+ :default: "⬡"
615
+ :procname: val_as_str
538
616
  - :opt_name: menu_divider_color
539
617
  :env_var: MDE_MENU_DIVIDER_COLOR
540
618
  :description: Color of menu divider
@@ -545,11 +623,6 @@
545
623
  :description: format for menu dividers and demarcations
546
624
  :default: "-:= %{line} =:-"
547
625
  :procname: val_as_str
548
- - :opt_name: menu_divider_match
549
- :env_var: MDE_MENU_DIVIDER_MATCH
550
- :description: Pattern for topics/dividers in block selection menu
551
- :default: "^(?<indent>[ \t]*):::(?<line>(?<text>.*?)(?<trailing>[ \t]*))?$"
552
- :procname: val_as_str
553
626
  - :opt_name: menu_divider_symbol
554
627
  :env_var: MDE_MENU_DIVIDER_SYMBOL
555
628
  :description: Symbol before each divider
@@ -760,7 +833,7 @@
760
833
  - :opt_name: menu_table_rows_match
761
834
  :env_var: MDE_MENU_TABLE_ROWS_MATCH
762
835
  :description: Pattern for table rows
763
- :default: "^(?<line>[ \\t]*(?<text>\\|.*?)(?<trailing>[ \\t]*))$"
836
+ :default: "^(?<line>(?<indent>[ \\t]*)(?<text>\\|.*?)(?<trailing>[ \\t]*))$"
764
837
  :procname: val_as_str
765
838
  - :opt_name: menu_task_color
766
839
  :env_var: MDE_MENU_TASK_COLOR
@@ -922,6 +995,14 @@
922
995
  :arg_name: BOOL
923
996
  :default: false
924
997
  :procname: val_as_bool
998
+ - :opt_name: play_bin_batch
999
+ :env_var: MDE_PLAY_BIN_BATCH
1000
+ :default: play
1001
+ :procname: val_as_str
1002
+ - :opt_name: play_bin_interactive
1003
+ :env_var: MDE_PLAY_BIN_INTERACTIVE
1004
+ :default: play_interactive
1005
+ :procname: val_as_str
925
1006
  - :opt_name: probe
926
1007
  :long_name: probe
927
1008
  :env_var: MDE_PROBE
@@ -1255,6 +1336,11 @@
1255
1336
  :env_var: MDE_TABLE_BORDER_COLOR
1256
1337
  :description: Color for table border
1257
1338
  :default: fg_bg_rgbh_00_00_df_14_18_1c
1339
+ - :opt_name: table_center
1340
+ :env_var: MDE_TABLE_CENTER
1341
+ :arg_name: BOOL
1342
+ :default: true
1343
+ :procname: val_as_bool
1258
1344
  - :opt_name: table_header_row_color
1259
1345
  :env_var: MDE_TABLE_HEADER_ROW_COLOR
1260
1346
  :description: Color for table header row
data/lib/ww.rb CHANGED
@@ -2,42 +2,95 @@
2
2
 
3
3
  # encoding=utf-8
4
4
  require 'pp'
5
+ require 'stringio'
6
+
7
+ LOG_LEVELS = %i[debug info warn error fatal]
5
8
 
6
9
  $debug = $DEBUG || !ENV['WW'].nil?
7
10
 
8
11
  # attribution in output unless disabled
9
12
  if $debug && ENV['WW_MINIMUM'].nil?
10
- $stderr.puts "WW Debugging per $DEBUG ('ruby --debug')" if $DEBUG
11
- $stderr.puts "WW Debugging per environment variable WW" if !ENV['WW'].nil?
13
+ warn "WW Debugging per $DEBUG ('ruby --debug')" if $DEBUG
14
+ warn 'WW Debugging per environment variable WW' unless ENV['WW'].nil?
12
15
  end
13
16
 
14
- # def wtr(*objs, full_backtrace: false, single_line: false)
15
- # ww(['->'] + objs,
16
- # locations: caller_locations[2..-1],
17
- # full_backtrace: full_backtrace,
18
- # single_line: single_line)
19
- # end
20
-
21
- def ww(*objs, full_backtrace: false, single_line: false,
22
- locations: caller_locations)
17
+ def ww(*objs, **kwargs)
23
18
  return unless $debug
24
19
 
25
- def cil(caller_info)
26
- "#{caller_info.lineno} : #{File.basename(caller_info.path)} : " \
27
- "#{caller_info.label}"
20
+ ww0(*objs, **kwargs)
21
+ end
22
+
23
+ def ww0(*objs,
24
+ category: nil,
25
+ full_backtrace: false,
26
+ level: :debug,
27
+ locations: caller_locations,
28
+ log_file: nil,
29
+ output: $stderr,
30
+ single_line: false,
31
+ timestamp: false)
32
+ # Format caller information line
33
+ def caller_info_line(caller_info)
34
+ "#{caller_info.lineno} : #{caller_info.path.sub(%r{^#{Dir.pwd}},
35
+ '')} : #{caller_info.label}"
28
36
  end
37
+ # Validate log level
38
+ raise ArgumentError,
39
+ "Invalid log level: #{level}" unless LOG_LEVELS.include?(level)
29
40
 
41
+ # Generate backtrace
30
42
  backtrace = if full_backtrace
31
- locations.map do |caller_info|
32
- cil(caller_info)
33
- end
43
+ locations.map { |caller_info| caller_info_line(caller_info) }
34
44
  else
35
- [cil(locations[0, 1].first)]
45
+ [caller_info_line(locations.first)]
36
46
  end
47
+
48
+ # Add optional timestamp
49
+ time_prefix = timestamp ? "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] " : ''
50
+
51
+ # Add log level and category prefix
52
+ level_prefix = "[#{level.to_s.upcase}]"
53
+ category_prefix = category ? "[#{category}] " : ''
54
+
55
+ # Combine all parts into the final message
56
+ header = "#{time_prefix}#{level_prefix} #{category_prefix}"
37
57
  trace = backtrace + objs
38
- if single_line
39
- PP.singleline_pp(trace, $stderr)
40
- else
41
- PP.pp(trace, $stderr)
58
+ formatted_message = if single_line
59
+ io = StringIO.new
60
+ PP.singleline_pp(trace, io)
61
+ "#{header} #{io.string}"
62
+ else
63
+ io = StringIO.new
64
+ PP.pp(trace, io)
65
+ "#{header}\n#{io.string}"
66
+ end
67
+
68
+ # Output to $stderr or specified IO object
69
+ output.puts formatted_message
70
+ output.flush
71
+
72
+ # Optionally log to a file
73
+ return unless log_file
74
+
75
+ File.open(log_file, 'a') do |file|
76
+ file.puts(formatted_message)
77
+ end
78
+ end
79
+
80
+ class Array
81
+ unless defined?(deref)
82
+ def deref
83
+ map(&:deref).select do |line|
84
+ !%r{^/vendor/}.match(line)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ class String
91
+ unless defined?(deref)
92
+ def deref
93
+ sub(%r{^#{Dir.pwd}}, '')
94
+ end
42
95
  end
43
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fareed Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-02 00:00:00.000000000 Z
11
+ date: 2024-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: yaml
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.2.0
83
83
  description: Interactively select and execute fenced code blocks in markdown files.
@@ -114,9 +114,12 @@ files:
114
114
  - bats/import.bats
115
115
  - bats/markup.bats
116
116
  - bats/mde.bats
117
+ - bats/options-collapse.bats
117
118
  - bats/options.bats
118
119
  - bats/publish.bats
120
+ - bats/table.bats
119
121
  - bats/test_helper.bash
122
+ - bats/variable-expansion.bats
120
123
  - bin/bmde
121
124
  - bin/colorize_env_vars.sh
122
125
  - bin/console
@@ -131,14 +134,18 @@ files:
131
134
  - docs/dev/block-type-vars.md
132
135
  - docs/dev/data-blocks.md
133
136
  - docs/dev/disable.md
137
+ - docs/dev/import-missing.md
134
138
  - docs/dev/import.md
135
139
  - docs/dev/linked-file.md
136
140
  - docs/dev/manage-saved-documents.md
137
141
  - docs/dev/menu-cli.md
142
+ - docs/dev/options-collapse.md
138
143
  - docs/dev/pass-through-arguments.md
139
144
  - docs/dev/requiring-blocks.md
140
145
  - docs/dev/specs-import.md
141
146
  - docs/dev/specs.md
147
+ - docs/dev/table-crash.md
148
+ - docs/dev/table-indent.md
142
149
  - docs/dev/text-decoration.md
143
150
  - docs/dev/variable-expansion.md
144
151
  - examples/bash-blocks.md
@@ -186,20 +193,18 @@ files:
186
193
  - examples/wrap.md
187
194
  - lib/ansi_formatter.rb
188
195
  - lib/ansi_string.rb
189
- - lib/append_to_bash_history.rb
190
196
  - lib/argument_processor.rb
191
197
  - lib/array.rb
192
198
  - lib/array_util.rb
193
199
  - lib/block_label.rb
194
200
  - lib/block_types.rb
195
201
  - lib/cached_nested_file_reader.rb
196
- - lib/ce_get_cost_and_usage.rb
197
202
  - lib/cli.rb
203
+ - lib/collapser.rb
198
204
  - lib/color_scheme.rb
199
205
  - lib/colorize.rb
200
206
  - lib/constants.rb
201
207
  - lib/directory_searcher.rb
202
- - lib/doh.rb
203
208
  - lib/env.rb
204
209
  - lib/evaluate_shell_expressions.rb
205
210
  - lib/exceptions.rb
@@ -213,7 +218,6 @@ files:
213
218
  - lib/hierarchy_string.rb
214
219
  - lib/input_sequencer.rb
215
220
  - lib/instance_method_wrapper.rb
216
- - lib/layered_hash.rb
217
221
  - lib/link_history.rb
218
222
  - lib/markdown_exec.rb
219
223
  - lib/markdown_exec/version.rb
@@ -223,7 +227,6 @@ files:
223
227
  - lib/namer.rb
224
228
  - lib/object_present.rb
225
229
  - lib/option_value.rb
226
- - lib/poly.rb
227
230
  - lib/regexp.rb
228
231
  - lib/resize_terminal.rb
229
232
  - lib/rspec_helpers.rb