markdown_exec 2.0.5 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,11 @@ class InputSequencer
20
20
  @current_block = nil
21
21
  @block_queue = initial_blocks
22
22
  @debug = Env.env_bool('INPUT_SEQUENCER_DEBUG', default: false)
23
+ # rubocop:disable Style/RescueStandardError
24
+ rescue
25
+ pp $!, $@
26
+ exit 1
27
+ # rubocop:enable Style/RescueStandardError
23
28
  end
24
29
 
25
30
  # Merges the current menu state with the next, prioritizing the next state's values.
@@ -54,6 +59,11 @@ class InputSequencer
54
59
  # Orchestrates the flow of menu states and user interactions.
55
60
  def run_yield(sym, *args, &block)
56
61
  block.call sym, *args
62
+ # rubocop:disable Style/RescueStandardError
63
+ rescue
64
+ pp $!, $@
65
+ exit 1
66
+ # rubocop:enable Style/RescueStandardError
57
67
  end
58
68
 
59
69
  def bq_is_empty?
@@ -81,10 +91,7 @@ class InputSequencer
81
91
 
82
92
  choice = run_yield :user_choice, &block
83
93
 
84
- if choice.nil?
85
- raise 'Block not recognized.'
86
- break
87
- end
94
+ raise 'Block not recognized.' if choice.nil?
88
95
  break if run_yield(:exit?, choice&.downcase, &block) # Exit loop and method to terminate the app
89
96
 
90
97
  next_state = run_yield :execute_block, choice, &block
@@ -7,5 +7,5 @@ module MarkdownExec
7
7
  BIN_NAME = 'mde'
8
8
  GEM_NAME = 'markdown_exec'
9
9
  TAP_DEBUG = 'MDE_DEBUG'
10
- VERSION = '2.0.5'
10
+ VERSION = '2.0.7'
11
11
  end
data/lib/markdown_exec.rb CHANGED
@@ -18,6 +18,7 @@ require_relative 'ansi_formatter'
18
18
  require_relative 'block_label'
19
19
  require_relative 'cached_nested_file_reader'
20
20
  require_relative 'cli'
21
+ require_relative 'color_scheme'
21
22
  require_relative 'colorize'
22
23
  require_relative 'directory_searcher'
23
24
  require_relative 'env'
@@ -110,6 +111,7 @@ module MarkdownExec
110
111
  # @return [String] modified file name with age prepended
111
112
  def self.for_menu(filename)
112
113
  file_age = (Time.now - File.mtime(filename)) / (60 * 60 * 24 * 30)
114
+ filename = ColorScheme.colorize_path(filename)
113
115
 
114
116
  " #{Histogram.display(file_age, 0, 11, 12, inverse: false)}: #{filename}"
115
117
  end
@@ -117,7 +119,8 @@ module MarkdownExec
117
119
  # Removes the age from the string to retrieve the original file name.
118
120
  # @param filename_with_age [String] the modified file name with age
119
121
  # @return [String] the original file name
120
- def self.from_menu(filename_with_age)
122
+ def self.from_menu(dname)
123
+ filename_with_age = dname.gsub(/\033\[[\d;]+m|\033\[0m/, '')
121
124
  filename_with_age.split(': ', 2).last
122
125
  end
123
126
  end
@@ -341,7 +344,14 @@ module MarkdownExec
341
344
  # Reports and executes block logic
342
345
  def execute_block_logic(files)
343
346
  @options[:filename] = select_document_if_multiple(files)
344
- @options.document_menu_loop
347
+ @options.document_inpseq
348
+ rescue StandardError
349
+ error_handler('execute_block_logic')
350
+ # rubocop:disable Style/RescueStandardError
351
+ rescue
352
+ pp $!, $@
353
+ exit 1
354
+ # rubocop:enable Style/RescueStandardError
345
355
  end
346
356
 
347
357
  ## Executes the block specified in the options
@@ -506,7 +516,7 @@ module MarkdownExec
506
516
  opts.banner = [
507
517
  "#{MarkdownExec::APP_NAME}" \
508
518
  " - #{MarkdownExec::APP_DESC} (#{MarkdownExec::VERSION})",
509
- "Usage: #{executable_name} [(path | filename [block_name])] [options]"
519
+ "Usage: #{executable_name} [(directory | file [block_name] | search_keyword)] [options]"
510
520
  ].join("\n")
511
521
 
512
522
  menu_iter do |item|
@@ -553,7 +563,7 @@ module MarkdownExec
553
563
  }
554
564
  when 'show_config'
555
565
  ->(_) {
556
- finalize_cli_argument_processing(options)
566
+ finalize_cli_argument_processing([])
557
567
  @fout.fout options.sort_by_key.to_yaml
558
568
  }
559
569
  when 'val_as_bool'
@@ -710,7 +720,7 @@ module MarkdownExec
710
720
 
711
721
  saved_name_split filename
712
722
  @options[:save_executed_script] = false
713
- @options.document_menu_loop
723
+ @options.document_inpseq
714
724
  rescue StandardError
715
725
  error_handler('run_last_script')
716
726
  end
@@ -776,7 +786,7 @@ module MarkdownExec
776
786
 
777
787
  saved_name_split(filename)
778
788
 
779
- @options.document_menu_loop ### ({ save_executed_script: false })
789
+ @options.document_inpseq ### ({ save_executed_script: false })
780
790
  end
781
791
 
782
792
  public
data/lib/mdoc.rb CHANGED
@@ -72,11 +72,10 @@ module MarkdownExec
72
72
  #
73
73
  def collect_block_dependencies(anyname:)
74
74
  name_block = get_block_by_anyname(anyname)
75
- if name_block.nil? || name_block.keys.empty?
76
- raise "Named code block `#{anyname}` not found. (@#{__LINE__})"
77
- end
75
+ raise "Named code block `#{anyname}` not found. (@#{__LINE__})" if name_block.nil? || name_block.keys.empty?
76
+
77
+ nickname = name_block.pub_name
78
78
 
79
- nickname = name_block[:nickname] || name_block[:oname]
80
79
  dependencies = collect_dependencies(nickname)
81
80
  # &bc 'dependencies.count:',dependencies.count
82
81
  all_dependency_names = collect_unique_names(dependencies).push(nickname).uniq
@@ -85,9 +84,7 @@ module MarkdownExec
85
84
  # select non-chrome blocks in order of appearance in source documents
86
85
  #
87
86
  blocks = @table.select do |fcb|
88
- !fcb.fetch(:chrome,
89
- false) && all_dependency_names.include?(fcb.fetch(:nickname,
90
- nil) || fcb.fetch(:oname))
87
+ !fcb.fetch(:chrome, false) && all_dependency_names.include?(fcb.pub_name)
91
88
  end
92
89
  # &bc 'blocks.count:',blocks.count
93
90
 
@@ -95,7 +92,7 @@ module MarkdownExec
95
92
  #
96
93
  unmet_dependencies = all_dependency_names.dup
97
94
  blocks = blocks.map do |fcb|
98
- unmet_dependencies.delete(fcb[:nickname] || fcb[:oname]) # may not exist if block name is duplicated
95
+ unmet_dependencies.delete(fcb.pub_name) # may not exist if block name is duplicated
99
96
  if (call = fcb[:call])
100
97
  [get_block_by_anyname("[#{call.match(/^%\((\S+) |\)/)[1]}]")
101
98
  .merge({ cann: call })]
@@ -124,7 +121,7 @@ module MarkdownExec
124
121
  # &bc 'blocks.count:',blocks.count
125
122
 
126
123
  block_search.merge(
127
- { block_names: blocks.map { |block| block[:nickname] || block[:oname] },
124
+ { block_names: blocks.map(&:pub_name),
128
125
  code: blocks.map do |fcb|
129
126
  if fcb[:cann]
130
127
  collect_block_code_cann(fcb)
@@ -136,7 +133,7 @@ module MarkdownExec
136
133
  elsif fcb[:shell] == BlockType::PORT
137
134
  collect_block_code_shell(fcb)
138
135
  elsif label_body
139
- block_name_for_bash_comment = (fcb[:nickname] || fcb[:oname]).gsub(/\s+/, '_')
136
+ block_name_for_bash_comment = fcb.pub_name.gsub(/\s+/, '_')
140
137
  [label_format_above && format(label_format_above,
141
138
  block_source.merge({ block_name: block_name_for_bash_comment }))] +
142
139
  fcb[:body] +
@@ -198,7 +195,7 @@ module MarkdownExec
198
195
 
199
196
  ### hide rows correctly
200
197
 
201
- if !options[:menu_include_imported_blocks]
198
+ unless options[:menu_include_imported_blocks]
202
199
  selrows = selrows.reject do |block|
203
200
  block.fetch(:depth, 0).positive?
204
201
  end
@@ -287,9 +284,7 @@ module MarkdownExec
287
284
  return memo if memo.keys.include? source
288
285
 
289
286
  block = get_block_by_anyname(source)
290
- if block.nil? || block.keys.empty?
291
- raise "Named code block `#{source}` not found. (@#{__LINE__})"
292
- end
287
+ raise "Named code block `#{source}` not found. (@#{__LINE__})" if block.nil? || block.keys.empty?
293
288
 
294
289
  memo[source] = block[:reqs]
295
290
  return memo unless memo[source]&.count&.positive?
data/lib/menu.src.yml CHANGED
@@ -118,16 +118,32 @@
118
118
  :opt_name: document_load_opts_block_name
119
119
  :procname: val_as_str
120
120
 
121
+ - :arg_name: GLOB
122
+ :default: "document_configurations/%{document_filename}_*.sh"
123
+ :description: Glob for saved lines for a document
124
+ :env_var: MDE_DOCUMENT_SAVED_LINES_GLOB
125
+ :opt_name: document_saved_lines_glob
126
+ :procname: val_as_str
127
+
128
+ - :arg_name: BOOL
129
+ :default: true
130
+ :description: Add menu options for saved lines
131
+ :env_var: MDE_MENU_FOR_SAVED_LINES
132
+ :opt_name: menu_for_saved_lines
133
+ :procname: val_as_bool
134
+
121
135
  - :arg_name: BOOL
122
136
  :default: false
123
137
  :description: Dump @delegate_object
124
- :long_name: dump-dump-delegate-object
138
+ :env_var: MDE_DUMP_DELEGATE_OBJECT
139
+ :long_name: dump-delegate-object
125
140
  :opt_name: dump_delegate_object
126
141
  :procname: val_as_bool
127
142
 
128
143
  - :arg_name: BOOL
129
144
  :default: false
130
145
  :description: Dump BlocksInFile (stage 1)
146
+ :env_var: MDE_DUMP_BLOCKS_IN_FILE
131
147
  :long_name: dump-blocks-in-file
132
148
  :opt_name: dump_blocks_in_file
133
149
  :procname: val_as_bool
@@ -135,27 +151,31 @@
135
151
  - :arg_name: BOOL
136
152
  :default: false
137
153
  :description: Dump inherited block_names
138
- :long_name: dump-dump-inherited-block_names
154
+ :env_var: MDE_DUMP_INHERITED_BLOCK_NAMES
155
+ :long_name: dump-inherited-block_names
139
156
  :opt_name: dump_inherited_block_names
140
157
  :procname: val_as_bool
141
158
 
142
159
  - :arg_name: BOOL
143
160
  :default: false
144
161
  :description: Dump inherited dependencies
145
- :long_name: dump-dump-inherited-dependencies
162
+ :env_var: MDE_DUMP_INHERITED_DEPENDENCIES
163
+ :long_name: dump-inherited-dependencies
146
164
  :opt_name: dump_inherited_dependencies
147
165
  :procname: val_as_bool
148
166
 
149
167
  - :arg_name: BOOL
150
168
  :default: false
151
169
  :description: Dump inherited lines
152
- :long_name: dump-dump-inherited-lines
170
+ :env_var: MDE_DUMP_INHERITED_LINES
171
+ :long_name: dump-inherited-lines
153
172
  :opt_name: dump_inherited_lines
154
173
  :procname: val_as_bool
155
174
 
156
175
  - :arg_name: BOOL
157
176
  :default: false
158
177
  :description: Dump MenuBlocks (stage 2)
178
+ :env_var: MDE_DUMP_MENU_BLOCKS
159
179
  :long_name: dump-menu-blocks
160
180
  :opt_name: dump_menu_blocks
161
181
  :procname: val_as_bool
@@ -163,6 +183,7 @@
163
183
  - :arg_name: BOOL
164
184
  :default: false
165
185
  :description: Dump selected block
186
+ :env_var: MDE_DUMP_SELECTED_BLOCK
166
187
  :long_name: dump-selected-block
167
188
  :opt_name: dump_selected_block
168
189
  :procname: val_as_bool
@@ -285,7 +306,7 @@
285
306
  :opt_name: fenced_start_and_end_regex
286
307
  :procname: val_as_str
287
308
 
288
- - :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
309
+ - :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *(:(?<name>[^\\s]*))? *(?<rest>.*) *$"
289
310
  :description: Match the start of a fenced block
290
311
  :env_var: MDE_FENCED_START_EXTENDED_REGEX
291
312
  :opt_name: fenced_start_extended_regex
@@ -315,17 +336,17 @@
315
336
  :opt_name: find_path
316
337
  :procname: val_as_str
317
338
 
318
- - :default: "^# *(?<line>[^#]*?) *$"
339
+ - :default: "^#(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
319
340
  :env_var: MDE_HEADING1_MATCH
320
341
  :opt_name: heading1_match
321
342
  :procname: val_as_str
322
343
 
323
- - :default: "^## *(?<line>[^#]*?) *$"
344
+ - :default: "^##(?<line>(?!#)(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
324
345
  :env_var: MDE_HEADING2_MATCH
325
346
  :opt_name: heading2_match
326
347
  :procname: val_as_str
327
348
 
328
- - :default: "^### *(?<line>.+?) *$"
349
+ - :default: "^###(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
329
350
  :env_var: MDE_HEADING3_MATCH
330
351
  :opt_name: heading3_match
331
352
  :procname: val_as_str
@@ -407,6 +428,14 @@
407
428
  :opt_name: list_recent_scripts
408
429
  :procname: val_as_bool
409
430
 
431
+ - :arg_name: PATH
432
+ :default: ''
433
+ :description: Load code
434
+ :env_var: MDE_LOAD_CODE
435
+ :long_name: load-code
436
+ :opt_name: load_code
437
+ :procname: val_as_str
438
+
410
439
  - :arg_name: PREFIX
411
440
  :default: mde
412
441
  :description: Name prefix for stdout files
@@ -475,7 +504,7 @@
475
504
  :opt_name: menu_divider_format
476
505
  :procname: val_as_str
477
506
 
478
- - :default: "^::: +(?<line>.+?)$"
507
+ - :default: "^:::(?<line>(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
479
508
  :description: Pattern for topics/dividers in block selection menu
480
509
  :env_var: MDE_MENU_DIVIDER_MATCH
481
510
  :opt_name: menu_divider_match
@@ -494,6 +523,13 @@
494
523
  :opt_name: menu_exit_at_top
495
524
  :procname: val_as_bool
496
525
 
526
+ - :arg_name: BOOL
527
+ :default: false
528
+ :description: Display Load option at top of menu (vs bottom)
529
+ :env_var: MDE_MENU_LOAD_AT_TOP
530
+ :opt_name: menu_load_at_top
531
+ :procname: val_as_bool
532
+
497
533
  - :default:
498
534
  :line: "~~~"
499
535
  :description: closing demarcations for menu
@@ -501,37 +537,40 @@
501
537
  :opt_name: menu_final_divider
502
538
  :procname: val_as_str
503
539
 
504
- - :default: fg_rgbh_80_80_c0
540
+ - :default: fg_bg_rgbh_80_80_c0_10_10_20
505
541
  :description: Color for heading 1 in menu
506
542
  :env_var: MDE_MENU_HEADING1_COLOR
507
543
  :opt_name: menu_heading1_color
508
544
  :procname: val_as_str
509
545
 
510
- - :default: "# %{line}"
546
+ # strip heading tag
547
+ - :default: "%{line}"
511
548
  :description: format for menu heading1 in menu
512
549
  :env_var: MDE_MENU_HEADING1_FORMAT
513
550
  :opt_name: menu_heading1_format
514
551
  :procname: val_as_str
515
552
 
516
- - :default: fg_rgbh_60_60_c0
553
+ - :default: fg_bg_rgbh_60_60_c0_10_10_20
517
554
  :description: Color for heading 2 in menu
518
555
  :env_var: MDE_MENU_HEADING2_COLOR
519
556
  :opt_name: menu_heading2_color
520
557
  :procname: val_as_str
521
558
 
522
- - :default: "## %{line}"
559
+ # strip heading tag
560
+ - :default: "%{line}"
523
561
  :description: format for menu heading2 in menu
524
562
  :env_var: MDE_MENU_HEADING2_FORMAT
525
563
  :opt_name: menu_heading2_format
526
564
  :procname: val_as_str
527
565
 
528
- - :default: fg_rgbh_40_40_c0
566
+ - :default: fg_bg_rgbh_40_40_c0_10_10_20
529
567
  :description: Color for heading 3 in menu
530
568
  :env_var: MDE_MENU_HEADING3_COLOR
531
569
  :opt_name: menu_heading3_color
532
570
  :procname: val_as_str
533
571
 
534
- - :default: "### %{line}"
572
+ # strip heading tag
573
+ - :default: "%{line}"
535
574
  :description: format for menu heading3 in menu
536
575
  :env_var: MDE_MENU_HEADING3_FORMAT
537
576
  :opt_name: menu_heading3_format
@@ -596,7 +635,7 @@
596
635
  :opt_name: menu_link_format
597
636
  :procname: val_as_str
598
637
 
599
- - :default: fg_rgbh_b0_b0_b0
638
+ - :default: fg_rgbh_c0_c0_c0
600
639
  :description: Color of menu note
601
640
  :env_var: MDE_MENU_NOTE_COLOR
602
641
  :opt_name: menu_note_color
@@ -609,7 +648,7 @@
609
648
  :procname: val_as_str
610
649
 
611
650
  ## all lines that do not start with "/ " are notes
612
- - :default: "^(?<line>(?!/ ).*)?$"
651
+ - :default: "^(?<line>(?!/ )(?<indent>[ \t]*)(?<text>.*?)(?<trailing>[ \t]*))?$"
613
652
  :description: Pattern for notes in block selection menu
614
653
  :env_var: MDE_MENU_NOTE_MATCH
615
654
  :opt_name: menu_note_match
@@ -622,6 +661,13 @@
622
661
  :opt_name: menu_option_back_name
623
662
  :procname: val_as_str
624
663
 
664
+ - :default:
665
+ :line: "* Edit"
666
+ :description: Text for Edit option
667
+ :env_var: MDE_MENU_OPTION_EDIT_NAME
668
+ :opt_name: menu_option_edit_name
669
+ :procname: val_as_str
670
+
625
671
  - :default:
626
672
  :line: "* Exit"
627
673
  :description: Text for Exit option
@@ -629,6 +675,34 @@
629
675
  :opt_name: menu_option_exit_name
630
676
  :procname: val_as_str
631
677
 
678
+ - :default:
679
+ :line: "* Load"
680
+ :description: Text for Load option
681
+ :env_var: MDE_MENU_OPTION_LOAD_NAME
682
+ :opt_name: menu_option_load_name
683
+ :procname: val_as_str
684
+
685
+ - :default:
686
+ :line: "* Save"
687
+ :description: Text for Save option
688
+ :env_var: MDE_MENU_OPTION_SAVE_NAME
689
+ :opt_name: menu_option_save_name
690
+ :procname: val_as_str
691
+
692
+ - :default:
693
+ :line: "! Shell"
694
+ :description: Text for Shell option
695
+ :env_var: MDE_MENU_OPTION_SHELL_NAME
696
+ :opt_name: menu_option_shell_name
697
+ :procname: val_as_str
698
+
699
+ - :default:
700
+ :line: "* View"
701
+ :description: Text for View option
702
+ :env_var: MDE_MENU_OPTION_VIEW_NAME
703
+ :opt_name: menu_option_view_name
704
+ :procname: val_as_str
705
+
632
706
  - :default: fg_rgbh_ff_00_ff
633
707
  :description: Color of menu opts
634
708
  :env_var: MDE_MENU_OPTS_COLOR
@@ -710,12 +784,19 @@
710
784
  :procname: val_as_bool
711
785
 
712
786
  - :arg_name: BOOL
713
- :default: true
787
+ :default: false
714
788
  :description: Display inherited lines in menu
715
789
  :env_var: MDE_MENU_WITH_INHERITED_LINES
716
790
  :opt_name: menu_with_inherited_lines
717
791
  :procname: val_as_bool
718
792
 
793
+ - :arg_name: BOOL
794
+ :default: true
795
+ :description: Display Shell option in menu
796
+ :env_var: MDE_MENU_WITH_SHELL
797
+ :opt_name: menu_with_shell
798
+ :procname: val_as_bool
799
+
719
800
  - :arg_name: BOOL
720
801
  :default: false
721
802
  :description: Hide decorative menu entries
@@ -758,7 +839,6 @@
758
839
  :default: false
759
840
  :description: Display summary for execution
760
841
  :env_var: MDE_OUTPUT_EXECUTION_SUMMARY
761
- :long_name: output-execution-summary
762
842
  :opt_name: output_execution_summary
763
843
  :procname: val_as_bool
764
844
 
@@ -819,7 +899,7 @@
819
899
 
820
900
  - :arg_name: BOOL
821
901
  :default: false
822
- :description: Wheter to pause after manually executing a block and the next menu
902
+ :description: Whether to pause after manually executing a block and the next menu
823
903
  :env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
824
904
  :opt_name: pause_after_script_execution
825
905
  :procname: val_as_bool
@@ -860,6 +940,12 @@
860
940
  :opt_name: prompt_exit
861
941
  :procname: val_as_str
862
942
 
943
+ - :default: Back
944
+ :description: Quit prompt
945
+ :env_var: MDE_PROMPT_FILESPEC_OTHER
946
+ :opt_name: prompt_filespec_back
947
+ :procname: val_as_str
948
+
863
949
  - :default: Other
864
950
  :description: Prompt for a custom file name
865
951
  :env_var: MDE_PROMPT_FILESPEC_OTHER
@@ -946,7 +1032,6 @@
946
1032
  :default: false
947
1033
  :description: Wheter to save an executed script`
948
1034
  :env_var: MDE_SAVE_EXECUTED_SCRIPT
949
- :long_name: save-executed-script
950
1035
  :opt_name: save_executed_script
951
1036
  :procname: val_as_bool
952
1037
 
@@ -954,7 +1039,6 @@
954
1039
  :default: false
955
1040
  :description: Save standard output of the executed script
956
1041
  :env_var: MDE_SAVE_EXECUTION_OUTPUT
957
- :long_name: save-execution-output
958
1042
  :opt_name: save_execution_output
959
1043
  :procname: val_as_bool
960
1044
 
@@ -988,7 +1072,6 @@
988
1072
  :default: logs
989
1073
  :description: Folder where saved scripts are stored
990
1074
  :env_var: MDE_SAVED_SCRIPT_FOLDER
991
- :long_name: saved-script-folder
992
1075
  :opt_name: saved_script_folder
993
1076
  :procname: val_as_str
994
1077
 
@@ -1003,7 +1086,6 @@
1003
1086
  :default: logs
1004
1087
  :description: Saved stdout folder
1005
1088
  :env_var: MDE_SAVED_STDOUT_FOLDER
1006
- :long_name: saved-stdout-folder
1007
1089
  :opt_name: saved_stdout_folder
1008
1090
  :procname: val_as_str
1009
1091