lib/hash_delegator.rb in markdown_exec-2.0.8.3 vs lib/hash_delegator.rb in markdown_exec-2.0.8.4
- old
+ new
@@ -791,11 +791,11 @@
HashDelegator.code_merge(link_state&.inherited_lines, required[:code] + code_lines)
end
def command_execute(command, args: [])
- @run_state.files = Hash.new([])
+ run_state_reset_stream_logs
@run_state.options = @delegate_object
@run_state.started_at = Time.now.utc
if @delegate_object[:execute_in_own_window] &&
@delegate_object[:execute_command_format].present? &&
@@ -805,11 +805,10 @@
format(
@delegate_object[:execute_command_format],
command_execute_in_own_window_format_arguments(rest: args ? args.join(' ') : '')
)
)
-
else
@run_state.in_own_window = false
execute_command_with_streams(
[@delegate_object[:shell], '-c', command, @delegate_object[:filename], *args]
)
@@ -1095,11 +1094,10 @@
@menu_base_options = @delegate_object
@dml_link_state = LinkState.new(
block_name: @delegate_object[:block_name],
document_filename: @delegate_object[:filename]
)
- # @dml_link_state_block_name_from_cli = @dml_link_state.block_name.present? ###
@run_state.block_name_from_cli = @dml_link_state.block_name.present?
@cli_block_name = @dml_link_state.block_name
@dml_now_using_cli = @run_state.block_name_from_cli
@dml_menu_default_dname = nil
@dml_block_state = SelectedBlockMenuState.new
@@ -1480,11 +1478,10 @@
#
# @param opts [Hash] Options hash containing configuration settings.
# @param mdoc [YourMDocClass] An instance of the MDoc class.
#
def execute_shell_type(selected:, mdoc:, block_source:, link_state: LinkState.new)
-# binding.irb
if selected.fetch(:shell, '') == BlockType::LINK
debounce_reset
push_link_history_and_trigger_load(link_block_body: selected.fetch(:body, ''),
mdoc: mdoc,
selected: selected,
@@ -1619,15 +1616,10 @@
fcb.call = fcb.title.match(Regexp.new(@delegate_object[:block_calls_scan]))&.fetch(1, nil)
titlexcall = fcb.call ? fcb.title.sub("%#{fcb.call}", '') : fcb.title
bm = extract_named_captures_from_option(titlexcall,
@delegate_object[:block_name_match])
- fcb.stdin = extract_named_captures_from_option(titlexcall,
- @delegate_object[:block_stdin_scan])
- fcb.stdout = extract_named_captures_from_option(titlexcall,
- @delegate_object[:block_stdout_scan])
-
shell_color_option = SHELL_COLOR_OPTIONS[fcb[:shell]]
if @delegate_object[:block_name_nick_match].present? && fcb.oname =~ Regexp.new(@delegate_object[:block_name_nick_match])
fcb.nickname = $~[0]
fcb.title = fcb.oname = format_multiline_body_as_title(fcb.body)
@@ -1758,11 +1750,11 @@
cmd = "#{@delegate_object[:shell]} #{file.path}"
file.write(all_code.join("\n"))
file.rewind
if link_block_data.fetch(LinkKeys::EXEC, false)
- @run_state.files = Hash.new([])
+ run_state_reset_stream_logs
execute_command_with_streams([cmd]) do |_stdin, stdout, stderr, _thread|
line = stdout || stderr
output_lines.push(line) if line
end
@@ -1829,11 +1821,10 @@
batch_random: @run_state.batch_random,
block_name: @delegate_object[:block_name],
document_filename: File.basename(@delegate_object[:filename]),
document_filespec: @delegate_object[:filename],
home: Dir.pwd,
- # rest: '',
started_at: Time.now.utc.strftime(@delegate_object[:execute_command_title_time_format])
}
end
# Loads auto blocks based on delegate object settings and updates if new filename is detected.
@@ -1883,48 +1874,10 @@
load_filespec_wildcard_expansion(expanded_expression)
else
expanded_expression
end
end
-
- # private
-
- # def read_block_name(line)
- # bm = extract_named_captures_from_option(line, @delegate_object[:block_name_match])
- # name = bm[:title]
-
- # if @delegate_object[:block_name_nick_match].present? && line =~ Regexp.new(@delegate_object[:block_name_nick_match])
- # name = $~[0]
- # else
- # name = bm && bm[1] ? bm[:title] : name
- # end
- # name
- # end
-
- # # Loads auto link block.
- # def load_auto_link_block(all_blocks, link_state, mdoc, block_source:)
- # block_name = @delegate_object[:document_load_link_block_name]
- # return unless block_name.present? && @most_recent_loaded_filename != @delegate_object[:filename]
-
- # block = HashDelegator.block_find(all_blocks, :oname, block_name)
- # return unless block
-
- # if block.fetch(:shell, '') != BlockType::LINK
- # HashDelegator.error_handler('must be Link block type', { abort: true })
-
- # else
- # # debounce_reset
- # push_link_history_and_trigger_load(
- # link_block_body: block.fetch(:body, ''),
- # mdoc: mdoc,
- # selected: block,
- # link_state: link_state,
- # block_source: block_source
- # )
- # end
- # end
-
# Handle expression with wildcard characters
def load_filespec_wildcard_expansion(expr, auto_load_single: false)
files = find_files(expr)
if files.count.zero?
HashDelegator.error_handler("no files found with '#{expr}' ", { abort: true })
@@ -1956,11 +1909,10 @@
all_blocks, mdoc = mdoc_and_blocks_from_nested_files
# recreate menu with new options
#
all_blocks, mdoc = mdoc_and_blocks_from_nested_files if load_auto_opts_block(all_blocks)
- # load_auto_link_block(all_blocks, link_state, mdoc, block_source: {})
menu_blocks = mdoc.fcbs_per_options(@delegate_object)
add_menu_chrome_blocks!(menu_blocks: menu_blocks, link_state: link_state)
### compress empty lines
HashDelegator.delete_consecutive_blank_lines!(menu_blocks)
@@ -2075,11 +2027,11 @@
formatted_string = string_send_color(@delegate_object[data_sym],
color_sym)
@fout.fout formatted_string
end
- def output_execution_result
+ def fout_execution_report
@fout.fout fetch_color(data_sym: :execution_report_preview_head,
color_sym: :execution_report_preview_frame_color)
[
['Block', @run_state.script_block_name],
['Command', ([MarkdownExec::BIN_NAME, @delegate_object[:filename]] +
@@ -2173,11 +2125,11 @@
end
def post_execution_process
do_save_execution_output
output_execution_summary
- output_execution_result
+ fout_execution_report if @delegate_object[:output_execution_report]
end
# Prepare the blocks menu by adding labels and other necessary details.
#
# @param all_blocks [Array<Hash>] The list of blocks from the file.
@@ -2539,10 +2491,17 @@
else
@delegate_object.respond_to?(method_name, include_private)
end
end
+ def run_state_reset_stream_logs
+ @run_state.files = Hash.new()
+ @run_state.files[ExecutionStreams::STD_ERR] = []
+ @run_state.files[ExecutionStreams::STD_IN] = []
+ @run_state.files[ExecutionStreams::STD_OUT] = []
+ end
+
def runtime_exception(exception_sym, name, items)
if @delegate_object[exception_sym] != 0
data = { name: name, detail: items.join(', ') }
warn(
format(
@@ -2710,13 +2669,17 @@
nickname = $~[0]
else
dname = oname = title = fcb_title_groups.fetch(:name, '')
end
+ # disable fcb for data blocks
+ disabled = fcb_title_groups.fetch(:shell, '') == 'yaml' ? '' : nil
+
MarkdownExec::FCB.new(
body: [],
call: rest.match(Regexp.new(@delegate_object[:block_calls_scan]))&.to_a&.first,
+ disabled: disabled,
dname: dname,
headings: headings,
indent: fcb_title_groups.fetch(:indent, ''),
nickname: nickname,
oname: oname,
@@ -2940,25 +2903,10 @@
obj
end
def self.next_link_state(*args, **kwargs, &block)
super
- # result = super
-
- # @logger ||= StdOutErrLogger.new
- # @logger.unknown(
- # HashDelegator.clean_hash_recursively(
- # { "HashDelegator.next_link_state":
- # { 'args': args,
- # 'at': Time.now.strftime('%FT%TZ'),
- # 'for': /[^\/]+:\d+/.match(caller.first)[0],
- # 'kwargs': kwargs,
- # 'return': result } }
- # )
- # )
-
- # result
end
end
end
return if $PROGRAM_NAME != __FILE__
@@ -3467,20 +3415,20 @@
@hd = HashDelegator.new
@hd.instance_variable_set(:@run_state, mock('run_state'))
end
def test_format_execution_streams_with_valid_key
- result = HashDelegator.format_execution_streams(:stdout,
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_OUT,
{ stdout: %w[output1 output2] })
assert_equal 'output1output2', result
end
def test_format_execution_streams_with_empty_key
@hd.instance_variable_get(:@run_state).stubs(:files).returns({})
- result = HashDelegator.format_execution_streams(:stderr)
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_ERR)
assert_equal '', result
end
def test_format_execution_streams_with_nil_files
@@ -3599,30 +3547,30 @@
{ output_stdout: true })
end
def test_handle_stream
stream = StringIO.new("line 1\nline 2\n")
- file_type = :stdout
+ file_type = ExecutionStreams::STD_OUT
Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
@hd.wait_for_stream_processing
assert_equal ['line 1', 'line 2'],
- @hd.instance_variable_get(:@run_state).files[:stdout]
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
end
def test_handle_stream_with_io_error
stream = StringIO.new("line 1\nline 2\n")
- file_type = :stdout
+ file_type = ExecutionStreams::STD_OUT
stream.stubs(:each_line).raises(IOError)
Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
@hd.wait_for_stream_processing
assert_equal [],
- @hd.instance_variable_get(:@run_state).files[:stdout]
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
end
end
class TestHashDelegatorIterBlocksFromNestedFiles < Minitest::Test
def setup