lib/hash_delegator.rb in markdown_exec-2.7.1 vs lib/hash_delegator.rb in markdown_exec-2.7.2

- old
+ new

@@ -359,14 +359,14 @@ # Yields a line as a new block if the selected message type includes :line. # @param [String] line The line to be processed. # @param [Array<Symbol>] selected_types A list of message types to check. # @param [Proc] block The block to be called with the line data. - def yield_line_if_selected(line, selected_types, id: '', &block) + def yield_line_if_selected(line, selected_types, source_id: '', &block) return unless block && block_type_selected?(selected_types, :line) - block.call(:line, MarkdownExec::FCB.new(body: [line], id: id)) + block.call(:line, MarkdownExec::FCB.new(body: [line], id: source_id)) end end # This module provides methods for compacting and converting data structures. module CompactionHelpers @@ -598,56 +598,76 @@ else File.join(Dir.getwd, file_path) end end - def add_back_option(id: '', menu_blocks:) - append_chrome_block(id: id, menu_blocks: menu_blocks, - menu_state: MenuState::BACK) + def add_back_option(menu_blocks:, source_id: '') + append_chrome_block( + menu_blocks: menu_blocks, + menu_state: MenuState::BACK, + source_id: source_id + ) end - def add_exit_option(id: '', menu_blocks:) - append_chrome_block(id: id, menu_blocks: menu_blocks, - menu_state: MenuState::EXIT) + def add_exit_option(menu_blocks:, source_id: '') + append_chrome_block( + menu_blocks: menu_blocks, + menu_state: MenuState::EXIT, + source_id: source_id + ) end - def add_inherited_lines(menu_blocks:, link_state:) - append_inherited_lines(menu_blocks: menu_blocks, link_state: link_state) + def add_inherited_lines(link_state:, menu_blocks:) + append_inherited_lines( + link_state: link_state, + menu_blocks: menu_blocks + ) end # Modifies the provided menu blocks array by adding 'Back' and 'Exit' options, # along with initial and final dividers, based on the delegate object's configuration. # # @param menu_blocks [Array] The array of menu block elements to be modified. - def add_menu_chrome_blocks!(id: '', menu_blocks:, link_state:) + def add_menu_chrome_blocks!(link_state:, menu_blocks:, source_id: '') return unless @delegate_object[:menu_link_format].present? - if @delegate_object[:menu_with_inherited_lines] - add_inherited_lines(menu_blocks: menu_blocks, - link_state: link_state) - end + add_inherited_lines( + link_state: link_state, + menu_blocks: menu_blocks + ) if @delegate_object[:menu_with_inherited_lines] # back before exit - add_back_option(id: "#{id}.back", - menu_blocks: menu_blocks) if should_add_back_option? + add_back_option( + menu_blocks: menu_blocks, + source_id: "#{source_id}.back" + ) if should_add_back_option? # exit after other options - if @delegate_object[:menu_with_exit] - add_exit_option(id: "#{id}.exit", menu_blocks: menu_blocks) - end - append_divider(id: "#{id}.init", menu_blocks: menu_blocks, - position: :initial) - append_divider(id: "#{id}.final", menu_blocks: menu_blocks, - position: :final) + add_exit_option( + menu_blocks: menu_blocks, + source_id: "#{source_id}.exit" + ) if @delegate_object[:menu_with_exit] + + append_divider( + menu_blocks: menu_blocks, + position: :initial, + source_id: "#{source_id}.init" + ) + + append_divider( + menu_blocks: menu_blocks, + position: :final, + source_id: "#{source_id}.final" + ) end # Appends a chrome block, which is a menu option for Back or Exit # # @param all_blocks [Array] The current blocks in the menu # @param type [Symbol] The type of chrome block to add (:back or :exit) - def append_chrome_block(menu_blocks:, menu_state:, id: '') + def append_chrome_block(menu_blocks:, menu_state:, source_id: '') case menu_state when MenuState::BACK history_state_partition option_name = @delegate_object[:menu_option_back_name] insert_at_top = @delegate_object[:menu_back_at_top] @@ -681,11 +701,11 @@ chrome_block = FCB.new( chrome: true, dname: HashDelegator.new(@delegate_object).string_send_color( formatted_name, :menu_chrome_color ), - id: id, + id: source_id.to_s, type: BlockType::CHROME, nickname: formatted_name, oname: formatted_name ) @@ -701,23 +721,23 @@ # Appends a formatted divider to the specified position in a menu block array. # The method checks for the presence of formatting options before appending. # # @param menu_blocks [Array] The array of menu block elements. # @param position [Symbol] The position to insert the divider (:initial or :final). - def append_divider(id: '', menu_blocks:, position:) + def append_divider(menu_blocks:, position:, source_id: '') return unless divider_formatting_present?(position) - divider = create_divider(position, id: id) + divider = create_divider(position, source_id: source_id) position == :initial ? menu_blocks.unshift(divider) : menu_blocks.push(divider) end # Appends a formatted divider to the specified position in a menu block array. # The method checks for the presence of formatting options before appending. # # @param menu_blocks [Array] The array of menu block elements. # @param position [Symbol] The position to insert the divider (:initial or :final). - def append_inherited_lines(menu_blocks:, link_state:, position: top) + def append_inherited_lines(link_state:, menu_blocks:, position: top) return unless link_state.inherited_lines_present? insert_at_top = @delegate_object[:menu_inherited_lines_at_top] chrome_blocks = link_state.inherited_lines_map do |line| formatted = format(@delegate_object[:menu_inherited_lines_format], @@ -781,63 +801,70 @@ end end # private + def expand_references!(fcb, link_state) + expand_variable_references!( + blocks: [fcb], + initial_code_required: false, + link_state: link_state + ) + expand_variable_references!( + blocks: [fcb], + echo_format: '%s', + group_name: :command, + initial_code_required: false, + key_format: '$(%s)', + link_state: link_state, + pattern: options_command_substitution_regexp + ) + end + # Iterates through nested files to collect various types # of blocks, including dividers, tasks, and others. # The method categorizes blocks based on their type and processes them accordingly. # # @return [Array<FCB>] An array of FCB objects representing the blocks. def blocks_from_nested_files( - link_state: @dml_link_state || LinkState.new + link_state: @dml_link_state || LinkState.new, + source_id: nil ) register_console_attributes(@delegate_object) @decor_patterns_from_delegate_object_for_block_create = collect_line_decor_patterns(@delegate_object) count = 0 blocks = [] iter_blocks_from_nested_files do |btype, fcb| count += 1 - # text substitution in menu - # - expand_references = lambda do |fcb| - expand_variable_references!(blocks: [fcb], link_state: link_state, - initial_code_required: false) - expand_variable_references!( - blocks: [fcb], - echo_format: '%s', - initial_code_required: false, - key_format: '$(%s)', - link_state: link_state, - group_name: :command, - pattern: options_command_substitution_regexp - ) - end - case btype when :blocks if @delegate_object[:bash] fcb.for_menu!( block_calls_scan: @delegate_object[:block_calls_scan], block_name_match: @delegate_object[:block_name_match], block_name_nick_match: @delegate_object[:block_name_nick_match], - id: "*#{count}" + id: "#{source_id}_bfnf_b_#{count}" ) do |oname, color| apply_block_type_color_option(oname, color) end + else + expand_references!(fcb, link_state) end - expand_references.call(fcb) blocks << fcb when :filter # types accepted %i[blocks line] when :line unless @delegate_object[:no_chrome] - expand_references.call(fcb) - create_and_add_chrome_blocks(blocks, fcb, id: "*#{count}", - init_ids: init_ids) + # expand references only if block is recognized (not a comment) + create_and_add_chrome_blocks( + blocks, fcb, id: "#{source_id}_bfnf_l_#{count}", init_ids: init_ids + ) do + # expand references only if block is recognized (not a comment) + expand_references!(fcb, link_state) + end end end end # !!t blocks.count blocks @@ -1132,12 +1159,14 @@ link_state.block_name = nil end # Check if the expression contains wildcard characters - def contains_wildcards?(expr) - expr.match(%r{\*|\?|\[}) + def contains_glob?(str) + return false if str.nil? + + str.match?(/[\*\?\[\{\}]/) end def copy_to_clipboard(required_lines) text = required_lines.flatten.join($INPUT_RECORD_SEPARATOR) Clipboard.copy(text) @@ -1198,11 +1227,12 @@ def create_and_add_chrome_block( blocks:, case_conversion: nil, center: nil, collapse: nil, color_method:, decor_patterns: [], disabled: true, format_option:, id: '', level: 0, match_data:, type: '', - wrap: nil + wrap: nil, + fcb: nil ) line_cap = NamedCaptureExtractor.extract_named_group2(match_data) # replace tabs in indent line_cap[:indent] ||= '' line_cap[:indent] = line_cap[:indent].dup if line_cap[:indent].frozen? @@ -1254,27 +1284,48 @@ decorated = apply_tree_decorations( oname, color_method, decor_patterns ) line_obj[:line] = line_obj[:indent] + line_obj[:text] - blocks.push FCB.new( - center: center, - chrome: true, - collapse: collapse.nil? ? (line_obj[:collapse] == COLLAPSIBLE_TOKEN_COLLAPSE) : collapse, - token: line_obj[:collapse], - disabled: disabled ? TtyMenu::DISABLE : nil, - id: "#{id}.#{index}", - level: level, - s0indent: indent, - s0printable: line_obj[:text], - s1decorated: decorated, - dname: line_obj[:indent] + decorated, - indent: line_obj[:indent], - oname: line_obj[:text], - text: line_obj[:text], - type: type - ) + + if fcb.nil? + fcb = FCB.new( + center: center, + chrome: true, + collapse: collapse.nil? ? (line_obj[:collapse] == COLLAPSIBLE_TOKEN_COLLAPSE) : collapse, + token: line_obj[:collapse], + disabled: disabled ? TtyMenu::DISABLE : nil, + id: "#{id}.#{index}", + level: level, + s0indent: indent, + s0printable: line_obj[:text], + s1decorated: decorated, + dname: line_obj[:indent] + decorated, + indent: line_obj[:indent], + oname: line_obj[:text], + text: line_obj[:text], + type: type + ) + else + fcb.center = center + fcb.chrome = true + fcb.collapse = collapse.nil? ? (line_obj[:collapse] == COLLAPSIBLE_TOKEN_COLLAPSE) : collapse + fcb.token = line_obj[:collapse] + fcb.disabled = disabled ? TtyMenu::DISABLE : nil + fcb.id = "#{id}.#{index}" + fcb.level = level + fcb.s0indent = indent + fcb.s0printable = line_obj[:text] + fcb.s1decorated = decorated + fcb.dname = line_obj[:indent] + decorated + fcb.indent = line_obj[:indent] + fcb.oname = line_obj[:text] + fcb.text = line_obj[:text] + fcb.type = type + end + + blocks.push fcb end line_caps.count end ## @@ -1290,10 +1341,16 @@ unless @delegate_object[criteria[:match]].present? && (mbody = fcb.body[0].match @delegate_object[criteria[:match]]) next end + if block_given? + # expand references only if block is recognized (not a comment) + yield if block_given? + mbody = fcb.body[0].match @delegate_object[criteria[:match]] + end + create_and_add_chrome_block( blocks: blocks, case_conversion: criteria[:case_conversion], center: criteria[:center] && @delegate_object[criteria[:center]], @@ -1310,10 +1367,11 @@ color_method: criteria[:color] && @delegate_object[criteria[:color]].to_sym, decor_patterns: @decor_patterns_from_delegate_object_for_block_create, disabled: !(criteria[:collapsible] && @delegate_object[criteria[:collapsible]]), + fcb: fcb, id: "#{id}.#{index}", format_option: criteria[:format] && @delegate_object[criteria[:format]], level: criteria[:level], match_data: mbody, @@ -1322,11 +1380,11 @@ ) break end end - def create_divider(position, id: '') + def create_divider(position, source_id: '') divider_key = if position == :initial :menu_initial_divider else :menu_final_divider end @@ -1335,11 +1393,11 @@ FCB.new( chrome: true, disabled: TtyMenu::DISABLE, dname: string_send_color(oname, :menu_divider_color), - id: id, + id: source_id, oname: oname ) end # Prompts user if named block is the same as the prior execution. @@ -1418,23 +1476,24 @@ @delegate_object[divider_key].present? end def dml_menu_append_chrome_item( name, count, type, - id: '', + always_create: true, + always_enable: true, menu_state: MenuState::LOAD, - always_create: true, always_enable: true + source_id: '' ) raise unless name.present? raise if @dml_menu_blocks.nil? item = @dml_menu_blocks.find { |block| block.oname == name } # create menu item when it is needed (count > 0) # if item.nil? && (always_create || count.positive?) - item = append_chrome_block(id: id, + item = append_chrome_block(source_id: source_id, menu_blocks: @dml_menu_blocks, menu_state: menu_state) end # update item if it exists @@ -1686,15 +1745,11 @@ next_state_append_code(selected, link_state, code_from_vars_block_to_set_environment_variables(selected)) elsif COLLAPSIBLE_TYPES.include?(selected.type) debounce_reset - if @compressed_ids.keys.include?(selected.id) - @compressed_ids.delete(selected.id) - else - @compressed_ids.merge!(selected.id => selected.level) - end + menu_toggle_collapsible_block(selected) LoadFileLinkState.new(LoadFile::REUSE, link_state) elsif debounce_allows compile_execute_and_trigger_reuse(mdoc: mdoc, selected: selected, @@ -1878,19 +1933,29 @@ glob: @delegate_object[:document_configurations_glob], menu_options: HashDelegator.options_for_tty_menu(@delegate_object), view: @delegate_object[:vars_block_filename_view] ) block_data = HashDelegator.parse_yaml_data_from_body(selected.body) - if selected_option = select_option_with_metadata( + + dirs = Dir.glob( + File.join( + Dir.pwd, + block_data['directory'] || directory, + block_data['glob'] || glob + ) + ) + + if !contains_glob?(block_data['directory']) && + !contains_glob?(block_data['glob']) + if dirs[0] + File.readlines(dirs[0], chomp: true) + else + warn 'No matching file found.' + end + elsif selected_option = select_option_with_metadata( prompt_title, - [exit_prompt] + Dir.glob( - File.join( - Dir.pwd, - block_data['directory'] || directory, - block_data['glob'] || glob - ) - ).sort.map do |file| + [exit_prompt] + dirs.sort.map do |file| { name: format( block_data['view'] || view, NamedCaptureExtractor.extract_named_group2( file.match( Regexp.new(block_data['filename_pattern'] || @@ -1906,11 +1971,11 @@ ) if selected_option.dname != exit_prompt File.readlines(selected_option.oname, chomp: true) end else - warn 'No matching files found' + warn 'No matching files found.' end end # Collects required code lines based on the selected block and # the delegate object's configuration. @@ -2173,10 +2238,11 @@ group_name: :variable, initial_code_required: false, key_format: '${%s}', pattern: nil ) + # defined($x) ? '' : ($x = 1; pp [__LINE__, caller.deref]) pattern ||= options_variable_expression_regexp return if pattern.nil? variable_counts = count_named_group_occurrences(blocks, pattern, group_name: group_name) @@ -2395,11 +2461,11 @@ )), fenced_start_extended_regex: Regexp.new(@delegate_object.fetch( :fenced_start_and_end_regex, '^(?<indent> *)`{3,}' )), - fcb: MarkdownExec::FCB.new, + fcb: MarkdownExec::FCB.new(id: 'INIT'), in_fenced_block: false, headings: [] } end @@ -2417,20 +2483,20 @@ ).each_with_index do |nested_line, index| next unless nested_line update_line_and_block_state( nested_line, state, selected_types, - id: "#{@delegate_object[:filename]}:#{index}", + source_id: "#{@delegate_object[:filename]}_ibfnf_#{index}", &block ) end end - def iter_source_blocks(source, &block) + def iter_source_blocks(source, source_id: nil, &block) case source when 1 - blocks_from_nested_files.each(&block) + blocks_from_nested_files(source_id: source_id).each(&block) when 2 @dml_blocks_in_file.each(&block) when 3 @dml_menu_blocks.each(&block) else @@ -2546,16 +2612,18 @@ @delegate_object[:execute_command_title_time_format] ) } end - def list_blocks + def list_blocks(source_id: nil) message = @delegate_object[:list_blocks_message] block_eval = @delegate_object[:list_blocks_eval] list = [] - iter_source_blocks(@delegate_object[:list_blocks_type]) do |block| + iter_source_blocks( + @delegate_object[:list_blocks_type], source_id: source_id + ) do |block| list << (block_eval.present? ? eval(block_eval) : block.send(message)) end list.compact! @fout.fout_list(list) @@ -2564,11 +2632,11 @@ # Loads auto blocks based on delegate object settings and updates # if new filename is detected. # Executes a specified block once per filename. # @param all_blocks [Array] Array of all block elements. # @return [Boolean, nil] True if values were modified, nil otherwise. - def load_auto_opts_block(all_blocks, id: '', mdoc:) + def load_auto_opts_block(all_blocks, mdoc:) block_name = @delegate_object[:document_load_opts_block_name] unless block_name.present? && @opts_most_recent_filename != @delegate_object[:filename] return end @@ -2584,10 +2652,34 @@ @opts_most_recent_filename = @delegate_object[:filename] true end + def load_document_shell_block(all_blocks, mdoc: nil) + block_name = @delegate_object[:document_load_shell_block_name] + unless block_name.present? && + @shell_most_recent_filename != @delegate_object[:filename] + return + end + + fcb = HashDelegator.block_find(all_blocks, :oname, block_name) + return unless fcb + + @shell_most_recent_filename = @delegate_object[:filename] + + if mdoc + mdoc.collect_recursively_required_code( + anyname: fcb.pub_name, + label_format_above: @delegate_object[:shell_code_label_format_above], + label_format_below: @delegate_object[:shell_code_label_format_below], + block_source: block_source + )[:code] + else + fcb.body + end + end + def load_auto_vars_block(all_blocks, block_name: @delegate_object[:document_load_vars_block_name]) unless block_name.present? && @vars_most_recent_filename != @delegate_object[:filename] return @@ -2626,11 +2718,11 @@ def load_filespec_from_expression(expression) # Process expression with embedded formatting expanded_expression = formatted_expression(expression) # Handle wildcards or direct file specification - if contains_wildcards?(expanded_expression) + if contains_glob?(expanded_expression) load_filespec_wildcard_expansion(expanded_expression) else expanded_expression end end @@ -2674,52 +2766,67 @@ @delegate_object = @menu_base_options.dup @menu_user_clicked_back_link = false [block_name_from_cli, now_using_cli] end - def mdoc_and_blocks_from_nested_files - menu_blocks = blocks_from_nested_files + def mdoc_and_blocks_from_nested_files(source_id: nil) + menu_blocks = blocks_from_nested_files(source_id: source_id) mdoc = MDoc.new(menu_blocks) do |nopts| @delegate_object.merge!(nopts) end [menu_blocks, mdoc] end ## Handles the file loading and returns the blocks # in the file and MDoc instance # - def mdoc_menu_and_blocks_from_nested_files(link_state, id: '') + def mdoc_menu_and_blocks_from_nested_files(link_state, source_id: '') # read blocks, load document opts block, and re-process blocks # - all_blocks, mdoc = mdoc_and_blocks_from_nested_files - if load_auto_opts_block(all_blocks, id: id, mdoc: mdoc) - all_blocks, mdoc = mdoc_and_blocks_from_nested_files + all_blocks, mdoc = mdoc_and_blocks_from_nested_files(source_id: source_id) + if load_auto_opts_block(all_blocks, mdoc: mdoc) + all_blocks, mdoc = mdoc_and_blocks_from_nested_files(source_id: source_id) end + # load document shell block + # + if code_lines = load_document_shell_block(all_blocks, mdoc: mdoc) + next_state_set_code(nil, link_state, code_lines) + link_state.inherited_lines = code_lines + end + # load document vars block # if code_lines = load_auto_vars_block(all_blocks) new_code = HashDelegator.code_merge(link_state.inherited_lines, code_lines) - next_state_set_code( - nil, - link_state, - new_code - ) + next_state_set_code(nil, link_state, new_code) link_state.inherited_lines = new_code end # filter by name, collapsed # menu_blocks, @compressed_ids = mdoc.fcbs_per_options( @delegate_object.merge!(compressed_ids: @compressed_ids) ) + # re-expand blocks + menu_blocks.each do |fcb| + fcb.body = fcb.raw_body || fcb.body || [] + fcb.dname = fcb.raw_dname || fcb.dname + fcb.s0printable = fcb.raw_s0printable || fcb.s0printable + fcb.s1decorated = fcb.raw_s1decorated || fcb.s1decorated + expand_references!(fcb, link_state) + end + # chrome for menu # - add_menu_chrome_blocks!(id: id, menu_blocks: menu_blocks, - link_state: link_state) + add_menu_chrome_blocks!( + link_state: link_state, + menu_blocks: menu_blocks, + source_id: source_id + ) ### compress empty lines HashDelegator.delete_consecutive_blank_lines!(menu_blocks) HashDelegator.tables_into_columns!(menu_blocks, @delegate_object, screen_width_for_table) @@ -2741,10 +2848,11 @@ chrome: true, disabled: TtyMenu::DISABLE, dname: HashDelegator.new(@delegate_object).string_send_color( document_glob, :menu_inherited_lines_color ), + # 2025-01-03 menu item is disabled ∴ does not need a recall id oname: formatted_name ) if insert_at_top @dml_menu_blocks.unshift(chrome_block) @@ -2781,10 +2889,26 @@ else option_value end end + def menu_compress_collapsible_block(selected) + @compressed_ids.merge!(selected.id => selected.level) + end + + def menu_expand_collapsible_block(selected) + @compressed_ids.delete(selected.id) + end + + def menu_toggle_collapsible_block(selected) + if @compressed_ids.keys.include?(selected.id) + menu_expand_collapsible_block(selected) + else + menu_compress_collapsible_block(selected) + end + end + # If a method is missing, treat it as a key for the @delegate_object. def method_missing(method_name, *args, &block) if @delegate_object.respond_to?(method_name) @delegate_object.send(method_name, *args, &block) elsif method_name.to_s.end_with?('=') && args.size == 1 @@ -3433,11 +3557,11 @@ def save_filespec_from_expression(expression) # Process expression with embedded formatting formatted = formatted_expression(expression) # Handle wildcards or direct file specification - if contains_wildcards?(formatted) + if contains_glob?(formatted) save_filespec_wildcard_expansion(formatted) else formatted end end @@ -3577,15 +3701,18 @@ item.dname == selection || item.id == selection else item == selection end end + + # new FCB if selected is not an object if selected.instance_of?(String) selected = FCB.new(dname: selected) elsif selected.instance_of?(Hash) selected = FCB.new(selected) end + unless selected HashDelegator.error_handler('select_option_with_metadata', error: 'menu item not found') exit 1 end @@ -3649,11 +3776,13 @@ # @param line [String] The line initiating the fenced block. # @param headings [Array<String>] Current headings hierarchy. # @param fenced_start_extended_regex [Regexp] # Regular expression to identify fenced block start. # @return [MarkdownExec::FCB] A new FCB instance with the parsed attributes. - def start_fenced_block(line, headings, fenced_start_extended_regex) + def start_fenced_block( + line, headings, fenced_start_extended_regex, source_id: nil + ) fcb_title_groups = NamedCaptureExtractor.extract_named_groups( line, fenced_start_extended_regex ) rest = fcb_title_groups.fetch(:rest, '') @@ -3700,10 +3829,11 @@ Regexp.new(@delegate_object[:block_calls_scan]) )&.to_a&.first, disabled: disabled, dname: dname, headings: headings, + id: source_id.to_s, indent: fcb_title_groups.fetch(:indent, ''), nickname: nickname, oname: oname, reqs: reqs, shell: fcb_title_groups.fetch(:shell, ''), @@ -3762,11 +3892,11 @@ # @return [Void] The function modifies the `state` # and `selected_types` arguments in place. ## def update_line_and_block_state( nested_line, state, selected_types, - id:, + source_id:, &block ) line = nested_line.to_s if line.match(@delegate_object[:fenced_start_and_end_regex]) if state[:in_fenced_block] @@ -3782,11 +3912,12 @@ else ## start of code block # state[:fcb] = start_fenced_block( line, state[:headings], - @delegate_object[:fenced_start_extended_regex] + @delegate_object[:fenced_start_extended_regex], + source_id: source_id ) state[:fcb][:depth] = nested_line[:depth] state[:fcb][:indention] = nested_line[:indention] state[:in_fenced_block] = true end @@ -3799,12 +3930,13 @@ ] elsif nested_line[:depth].zero? || @delegate_object[:menu_include_imported_notes] # add line if it is depth 0 or option allows it # - HashDelegator.yield_line_if_selected(line, selected_types, id: id, - &block) + HashDelegator.yield_line_if_selected( + line, selected_types, source_id: source_id, &block + ) end end ## apply options to current state # @@ -4076,30 +4208,35 @@ else raise end end + count = 0 InputSequencer.new( @delegate_object[:filename], block_list ).run do |msg, data| + count += 1 case msg when :parse_document # once for each menu - vux_parse_document(id: 'vux_parse_document') - vux_menu_append_history_files(formatted_choice_ostructs, - id: 'vux_menu_append_history_files') + count = 0 + vux_parse_document(source_id: "#{@delegate_object[:filename]}_vmlpd") + vux_menu_append_history_files( + formatted_choice_ostructs, + source_id: "#{@delegate_object[:filename]}_vmlhf" + ) vux_publish_document_file_name_for_external_automation when :display_menu # does not display vux_clear_menu_state when :end_of_cli # yield :end_of_cli, @delegate_object if @delegate_object[:list_blocks] - list_blocks + list_blocks(source_id: "#{@delegate_object[:filename]}_vmleoc") :exit end when :user_choice vux_user_selected_block_name @@ -4130,12 +4267,13 @@ end end end - def vux_menu_append_history_files(formatted_choice_ostructs, - id: '') + def vux_menu_append_history_files( + formatted_choice_ostructs, source_id: '' + ) if @delegate_object[:menu_for_history] history_files( @dml_link_state, filename: saved_asset_filename(@delegate_object[:filename], @dml_link_state), @@ -4143,12 +4281,12 @@ ).tap do |files| if files.count.positive? dml_menu_append_chrome_item( formatted_choice_ostructs[:history].oname, files.count, 'files', - id: id, - menu_state: MenuState::HISTORY + menu_state: MenuState::HISTORY, + source_id: source_id ) end end end @@ -4166,42 +4304,42 @@ menu_add_disabled_option(document_glob) end if files.count.positive? dml_menu_append_chrome_item( formatted_choice_ostructs[:load].dname, files.count, 'files', - id: "#{id}.load", - menu_state: MenuState::LOAD + menu_state: MenuState::LOAD, + source_id: "#{source_id}_vmahf_load" ) end if @delegate_object[:menu_inherited_lines_edit_always] || lines_count.positive? dml_menu_append_chrome_item( formatted_choice_ostructs[:edit].dname, lines_count, 'lines', - id: "#{id}.edit", - menu_state: MenuState::EDIT + menu_state: MenuState::EDIT, + source_id: "#{source_id}_vmahf_edit" ) end if lines_count.positive? dml_menu_append_chrome_item( formatted_choice_ostructs[:save].dname, 1, '', - id: "#{id}.save", - menu_state: MenuState::SAVE + menu_state: MenuState::SAVE, + source_id: "#{source_id}_vmahf_save" ) end if lines_count.positive? dml_menu_append_chrome_item( formatted_choice_ostructs[:view].dname, 1, '', - id: "#{id}.view", - menu_state: MenuState::VIEW + menu_state: MenuState::VIEW, + source_id: "#{source_id}_vmahf_view" ) end # rubocop:disable Style/GuardClause if @delegate_object[:menu_with_shell] dml_menu_append_chrome_item( formatted_choice_ostructs[:shell].dname, 1, '', - id: "#{id}.shell", - menu_state: MenuState::SHELL + menu_state: MenuState::SHELL, + source_id: "#{source_id}_vmahf_shell" ) end # rubocop:enable Style/GuardClause # # reflect new menu items @@ -4215,11 +4353,11 @@ **execute_navigate_back.merge(prior_block_was_link: true) ) ) end - def vux_parse_document(id: '') + def vux_parse_document(source_id: '') @run_state.batch_index += 1 @run_state.in_own_window = false @run_state.source.block_name_from_cli, @dml_now_using_cli = manage_cli_selection_state( @@ -4237,10 +4375,12 @@ end # update @delegate_object and @menu_base_options in auto_load # @dml_blocks_in_file, @dml_menu_blocks, @dml_mdoc = - mdoc_menu_and_blocks_from_nested_files(@dml_link_state, id: id) + mdoc_menu_and_blocks_from_nested_files( + @dml_link_state, source_id: source_id + ) dump_delobj(@dml_blocks_in_file, @dml_menu_blocks, @dml_link_state) end def vux_publish_block_name_for_external_automation(block_name) publish_for_external_automation(