markdown_exec 2.0.8.3 → 2.0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 942e4a005f42e2f3c2bd4542ba1b61e666c7379c0a2d81a5427f14ec76590a7d
4
- data.tar.gz: c38976432cd43684654663876cd6ee5fa35b40339d5217bae00e282c29cd7415
3
+ metadata.gz: 858c301950e3ca7d43bc8c8c9a87f1c340b75710c28743a02ed0811a649b46ba
4
+ data.tar.gz: 4c7445f2d0e05e974cadd163894772b865bd7f94717f6f070fda6b2db2a0ef8c
5
5
  SHA512:
6
- metadata.gz: e02a78e7a564273392203583c1b7d9502647c3379fa0894bf3b2a4b858127cfb8196a493d43e404395762449f267f8e68df48567585aa39d66d804c6c11e2edc
7
- data.tar.gz: 1bf94ff09d5248dd54853eca88dbc8ebce6ce5c17e9e5110103a2bc91250fa099120a81c7de0f060afdc0d08c607e5fbb7096735aea9ffcb4c7a4ee9bb33220f
6
+ metadata.gz: c157d1ec261a140205eabe4d2ec8a30839e8b8f1c716c2d24710d3630c587e03282b11a5f27e269e02b8e1a568fbca7bf2e37537cc04d4b9d4cfce9ef1ab4803
7
+ data.tar.gz: d991a308e029da9078adb996d8735951e3100eb117bc5a1f196db040513d4e20c715c6a4a805dcd528a93bd98d1a7b125eb2d88c4d9fea7449af1ad04add67be
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.0.8.3)
4
+ markdown_exec (2.0.8.4)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "2.0.8.3"
16
+ echo "2.0.8.4"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -178,4 +178,4 @@ _mde() {
178
178
 
179
179
  complete -o filenames -o nospace -F _mde mde
180
180
  # _mde_echo_version
181
- # echo "Updated: 2024-06-15 14:50:18 UTC"
181
+ # echo "Updated: 2024-06-24 04:53:41 UTC"
@@ -793,7 +793,7 @@ module MarkdownExec
793
793
  end
794
794
 
795
795
  def command_execute(command, args: [])
796
- @run_state.files = Hash.new([])
796
+ run_state_reset_stream_logs
797
797
  @run_state.options = @delegate_object
798
798
  @run_state.started_at = Time.now.utc
799
799
 
@@ -807,7 +807,6 @@ module MarkdownExec
807
807
  command_execute_in_own_window_format_arguments(rest: args ? args.join(' ') : '')
808
808
  )
809
809
  )
810
-
811
810
  else
812
811
  @run_state.in_own_window = false
813
812
  execute_command_with_streams(
@@ -1097,7 +1096,6 @@ module MarkdownExec
1097
1096
  block_name: @delegate_object[:block_name],
1098
1097
  document_filename: @delegate_object[:filename]
1099
1098
  )
1100
- # @dml_link_state_block_name_from_cli = @dml_link_state.block_name.present? ###
1101
1099
  @run_state.block_name_from_cli = @dml_link_state.block_name.present?
1102
1100
  @cli_block_name = @dml_link_state.block_name
1103
1101
  @dml_now_using_cli = @run_state.block_name_from_cli
@@ -1482,7 +1480,6 @@ module MarkdownExec
1482
1480
  # @param mdoc [YourMDocClass] An instance of the MDoc class.
1483
1481
  #
1484
1482
  def execute_shell_type(selected:, mdoc:, block_source:, link_state: LinkState.new)
1485
- # binding.irb
1486
1483
  if selected.fetch(:shell, '') == BlockType::LINK
1487
1484
  debounce_reset
1488
1485
  push_link_history_and_trigger_load(link_block_body: selected.fetch(:body, ''),
@@ -1621,11 +1618,6 @@ module MarkdownExec
1621
1618
  bm = extract_named_captures_from_option(titlexcall,
1622
1619
  @delegate_object[:block_name_match])
1623
1620
 
1624
- fcb.stdin = extract_named_captures_from_option(titlexcall,
1625
- @delegate_object[:block_stdin_scan])
1626
- fcb.stdout = extract_named_captures_from_option(titlexcall,
1627
- @delegate_object[:block_stdout_scan])
1628
-
1629
1621
  shell_color_option = SHELL_COLOR_OPTIONS[fcb[:shell]]
1630
1622
 
1631
1623
  if @delegate_object[:block_name_nick_match].present? && fcb.oname =~ Regexp.new(@delegate_object[:block_name_nick_match])
@@ -1760,7 +1752,7 @@ module MarkdownExec
1760
1752
  file.rewind
1761
1753
 
1762
1754
  if link_block_data.fetch(LinkKeys::EXEC, false)
1763
- @run_state.files = Hash.new([])
1755
+ run_state_reset_stream_logs
1764
1756
  execute_command_with_streams([cmd]) do |_stdin, stdout, stderr, _thread|
1765
1757
  line = stdout || stderr
1766
1758
  output_lines.push(line) if line
@@ -1831,7 +1823,6 @@ module MarkdownExec
1831
1823
  document_filename: File.basename(@delegate_object[:filename]),
1832
1824
  document_filespec: @delegate_object[:filename],
1833
1825
  home: Dir.pwd,
1834
- # rest: '',
1835
1826
  started_at: Time.now.utc.strftime(@delegate_object[:execute_command_title_time_format])
1836
1827
  }
1837
1828
  end
@@ -1885,44 +1876,6 @@ module MarkdownExec
1885
1876
  expanded_expression
1886
1877
  end
1887
1878
  end
1888
-
1889
- # private
1890
-
1891
- # def read_block_name(line)
1892
- # bm = extract_named_captures_from_option(line, @delegate_object[:block_name_match])
1893
- # name = bm[:title]
1894
-
1895
- # if @delegate_object[:block_name_nick_match].present? && line =~ Regexp.new(@delegate_object[:block_name_nick_match])
1896
- # name = $~[0]
1897
- # else
1898
- # name = bm && bm[1] ? bm[:title] : name
1899
- # end
1900
- # name
1901
- # end
1902
-
1903
- # # Loads auto link block.
1904
- # def load_auto_link_block(all_blocks, link_state, mdoc, block_source:)
1905
- # block_name = @delegate_object[:document_load_link_block_name]
1906
- # return unless block_name.present? && @most_recent_loaded_filename != @delegate_object[:filename]
1907
-
1908
- # block = HashDelegator.block_find(all_blocks, :oname, block_name)
1909
- # return unless block
1910
-
1911
- # if block.fetch(:shell, '') != BlockType::LINK
1912
- # HashDelegator.error_handler('must be Link block type', { abort: true })
1913
-
1914
- # else
1915
- # # debounce_reset
1916
- # push_link_history_and_trigger_load(
1917
- # link_block_body: block.fetch(:body, ''),
1918
- # mdoc: mdoc,
1919
- # selected: block,
1920
- # link_state: link_state,
1921
- # block_source: block_source
1922
- # )
1923
- # end
1924
- # end
1925
-
1926
1879
  # Handle expression with wildcard characters
1927
1880
  def load_filespec_wildcard_expansion(expr, auto_load_single: false)
1928
1881
  files = find_files(expr)
@@ -1958,7 +1911,6 @@ module MarkdownExec
1958
1911
  # recreate menu with new options
1959
1912
  #
1960
1913
  all_blocks, mdoc = mdoc_and_blocks_from_nested_files if load_auto_opts_block(all_blocks)
1961
- # load_auto_link_block(all_blocks, link_state, mdoc, block_source: {})
1962
1914
 
1963
1915
  menu_blocks = mdoc.fcbs_per_options(@delegate_object)
1964
1916
  add_menu_chrome_blocks!(menu_blocks: menu_blocks, link_state: link_state)
@@ -2077,7 +2029,7 @@ module MarkdownExec
2077
2029
  @fout.fout formatted_string
2078
2030
  end
2079
2031
 
2080
- def output_execution_result
2032
+ def fout_execution_report
2081
2033
  @fout.fout fetch_color(data_sym: :execution_report_preview_head,
2082
2034
  color_sym: :execution_report_preview_frame_color)
2083
2035
  [
@@ -2175,7 +2127,7 @@ module MarkdownExec
2175
2127
  def post_execution_process
2176
2128
  do_save_execution_output
2177
2129
  output_execution_summary
2178
- output_execution_result
2130
+ fout_execution_report if @delegate_object[:output_execution_report]
2179
2131
  end
2180
2132
 
2181
2133
  # Prepare the blocks menu by adding labels and other necessary details.
@@ -2541,6 +2493,13 @@ module MarkdownExec
2541
2493
  end
2542
2494
  end
2543
2495
 
2496
+ def run_state_reset_stream_logs
2497
+ @run_state.files = Hash.new()
2498
+ @run_state.files[ExecutionStreams::STD_ERR] = []
2499
+ @run_state.files[ExecutionStreams::STD_IN] = []
2500
+ @run_state.files[ExecutionStreams::STD_OUT] = []
2501
+ end
2502
+
2544
2503
  def runtime_exception(exception_sym, name, items)
2545
2504
  if @delegate_object[exception_sym] != 0
2546
2505
  data = { name: name, detail: items.join(', ') }
@@ -2712,9 +2671,13 @@ module MarkdownExec
2712
2671
  dname = oname = title = fcb_title_groups.fetch(:name, '')
2713
2672
  end
2714
2673
 
2674
+ # disable fcb for data blocks
2675
+ disabled = fcb_title_groups.fetch(:shell, '') == 'yaml' ? '' : nil
2676
+
2715
2677
  MarkdownExec::FCB.new(
2716
2678
  body: [],
2717
2679
  call: rest.match(Regexp.new(@delegate_object[:block_calls_scan]))&.to_a&.first,
2680
+ disabled: disabled,
2718
2681
  dname: dname,
2719
2682
  headings: headings,
2720
2683
  indent: fcb_title_groups.fetch(:indent, ''),
@@ -2942,21 +2905,6 @@ module MarkdownExec
2942
2905
 
2943
2906
  def self.next_link_state(*args, **kwargs, &block)
2944
2907
  super
2945
- # result = super
2946
-
2947
- # @logger ||= StdOutErrLogger.new
2948
- # @logger.unknown(
2949
- # HashDelegator.clean_hash_recursively(
2950
- # { "HashDelegator.next_link_state":
2951
- # { 'args': args,
2952
- # 'at': Time.now.strftime('%FT%TZ'),
2953
- # 'for': /[^\/]+:\d+/.match(caller.first)[0],
2954
- # 'kwargs': kwargs,
2955
- # 'return': result } }
2956
- # )
2957
- # )
2958
-
2959
- # result
2960
2908
  end
2961
2909
  end
2962
2910
  end
@@ -3469,7 +3417,7 @@ module MarkdownExec
3469
3417
  end
3470
3418
 
3471
3419
  def test_format_execution_streams_with_valid_key
3472
- result = HashDelegator.format_execution_streams(:stdout,
3420
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_OUT,
3473
3421
  { stdout: %w[output1 output2] })
3474
3422
 
3475
3423
  assert_equal 'output1output2', result
@@ -3478,7 +3426,7 @@ module MarkdownExec
3478
3426
  def test_format_execution_streams_with_empty_key
3479
3427
  @hd.instance_variable_get(:@run_state).stubs(:files).returns({})
3480
3428
 
3481
- result = HashDelegator.format_execution_streams(:stderr)
3429
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_ERR)
3482
3430
 
3483
3431
  assert_equal '', result
3484
3432
  end
@@ -3601,19 +3549,19 @@ module MarkdownExec
3601
3549
 
3602
3550
  def test_handle_stream
3603
3551
  stream = StringIO.new("line 1\nline 2\n")
3604
- file_type = :stdout
3552
+ file_type = ExecutionStreams::STD_OUT
3605
3553
 
3606
3554
  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
3607
3555
 
3608
3556
  @hd.wait_for_stream_processing
3609
3557
 
3610
3558
  assert_equal ['line 1', 'line 2'],
3611
- @hd.instance_variable_get(:@run_state).files[:stdout]
3559
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
3612
3560
  end
3613
3561
 
3614
3562
  def test_handle_stream_with_io_error
3615
3563
  stream = StringIO.new("line 1\nline 2\n")
3616
- file_type = :stdout
3564
+ file_type = ExecutionStreams::STD_OUT
3617
3565
  stream.stubs(:each_line).raises(IOError)
3618
3566
 
3619
3567
  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
@@ -3621,7 +3569,7 @@ module MarkdownExec
3621
3569
  @hd.wait_for_stream_processing
3622
3570
 
3623
3571
  assert_equal [],
3624
- @hd.instance_variable_get(:@run_state).files[:stdout]
3572
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
3625
3573
  end
3626
3574
  end
3627
3575
 
@@ -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.8.3'
10
+ VERSION = '2.0.8.4'
11
11
  end
data/lib/mdoc.rb CHANGED
@@ -53,6 +53,17 @@ module MarkdownExec
53
53
  end
54
54
  end
55
55
 
56
+ # Collects and formats the shell command output to redirect script block code to a file or a variable.
57
+ #
58
+ # @param [Hash] fcb A hash containing information about the script block's stdout and body.
59
+ # @option fcb [Hash] :stdout A hash specifying the stdout details.
60
+ # @option stdout [Boolean] :type Indicates whether to export to a variable (true) or to write to a file (false).
61
+ # @option stdout [String] :name The name of the variable or file to which the body will be output.
62
+ # @option fcb [Array<String>] :body An array of strings representing the lines of the script block's body.
63
+ #
64
+ # @return [String] A string containing the formatted shell command to output the script block's body.
65
+ # If stdout[:type] is true, the command will export the body to a shell variable.
66
+ # If stdout[:type] is false, the command will write the body to a file.
56
67
  def collect_block_code_stdout(fcb)
57
68
  stdout = fcb[:stdout]
58
69
  body = fcb[:body].join("\n")
data/lib/menu.src.yml CHANGED
@@ -64,6 +64,7 @@
64
64
  :procname: val_as_str
65
65
 
66
66
  - :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
67
+ :description: Match to place block body into a file or a variable
67
68
  :env_var: MDE_BLOCK_STDOUT_SCAN
68
69
  :opt_name: block_stdout_scan
69
70
  :procname: val_as_str
@@ -106,12 +107,6 @@
106
107
  :opt_name: display_level_xbase_prefix
107
108
  :procname: val_as_str
108
109
 
109
- # - :default: "(document_link)"
110
- # :description: Name of Link block to load with the document
111
- # :env_var: MDE_DOCUMENT_LOAD_LINK_BLOCK_NAME
112
- # :opt_name: document_load_link_block_name
113
- # :procname: val_as_str
114
-
115
110
  - :default: "(document_options)"
116
111
  :description: Name of Opts block to load with the document
117
112
  :env_var: MDE_DOCUMENT_LOAD_OPTS_BLOCK_NAME
@@ -868,6 +863,13 @@
868
863
  :opt_name: output_execution_label_value_color
869
864
  :procname: val_as_str
870
865
 
866
+ - :arg_name: BOOL
867
+ :default: true
868
+ :description: Output execution report at end of execution
869
+ :env_var: MDE_OUTPUT_EXECUTION_REPORT
870
+ :opt_name: output_execution_report
871
+ :procname: val_as_bool
872
+
871
873
  - :arg_name: BOOL
872
874
  :default: false
873
875
  :description: Output saved script filename at end of execution
data/lib/menu.yml CHANGED
@@ -53,6 +53,7 @@
53
53
  :opt_name: block_stdin_scan
54
54
  :procname: val_as_str
55
55
  - :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
56
+ :description: Match to place block body into a file or a variable
56
57
  :env_var: MDE_BLOCK_STDOUT_SCAN
57
58
  :opt_name: block_stdout_scan
58
59
  :procname: val_as_str
@@ -726,6 +727,12 @@
726
727
  :env_var: MDE_OUTPUT_EXECUTION_LABEL_VALUE_COLOR
727
728
  :opt_name: output_execution_label_value_color
728
729
  :procname: val_as_str
730
+ - :arg_name: BOOL
731
+ :default: true
732
+ :description: Output execution report at end of execution
733
+ :env_var: MDE_OUTPUT_EXECUTION_REPORT
734
+ :opt_name: output_execution_report
735
+ :procname: val_as_bool
729
736
  - :arg_name: BOOL
730
737
  :default: false
731
738
  :description: Output saved script filename at end of execution
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.0.8.3
4
+ version: 2.0.8.4
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-06-15 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard