lib/markdown_exec.rb in markdown_exec-2.0.5 vs lib/markdown_exec.rb in markdown_exec-2.0.6
- old
+ new
@@ -16,10 +16,11 @@
require_relative 'ansi_formatter'
require_relative 'block_label'
require_relative 'cached_nested_file_reader'
require_relative 'cli'
+require_relative 'color_scheme'
require_relative 'colorize'
require_relative 'directory_searcher'
require_relative 'env'
require_relative 'exceptions'
require_relative 'fcb'
@@ -108,18 +109,20 @@
# Prepends the age of the file in days to the file name for display in a menu.
# @param filename [String] the name of the file
# @return [String] modified file name with age prepended
def self.for_menu(filename)
file_age = (Time.now - File.mtime(filename)) / (60 * 60 * 24 * 30)
+ filename = ColorScheme.colorize_path(filename)
" #{Histogram.display(file_age, 0, 11, 12, inverse: false)}: #{filename}"
end
# Removes the age from the string to retrieve the original file name.
# @param filename_with_age [String] the modified file name with age
# @return [String] the original file name
- def self.from_menu(filename_with_age)
+ def self.from_menu(dname)
+ filename_with_age = dname.gsub(/\033\[[\d;]+m|\033\[0m/, '')
filename_with_age.split(': ', 2).last
end
end
# A class that generates a histogram bar in terminal using xterm-256 color codes.
@@ -339,11 +342,18 @@
# end
# Reports and executes block logic
def execute_block_logic(files)
@options[:filename] = select_document_if_multiple(files)
- @options.document_menu_loop
+ @options.document_inpseq
+ rescue StandardError
+ error_handler('execute_block_logic')
+ # rubocop:disable Style/RescueStandardError
+ rescue
+ pp $!, $@
+ exit 1
+ # rubocop:enable Style/RescueStandardError
end
## Executes the block specified in the options
#
def execute_block_with_error_handling
@@ -504,11 +514,11 @@
@option_parser = OptionParser.new do |opts|
executable_name = File.basename($PROGRAM_NAME)
opts.banner = [
"#{MarkdownExec::APP_NAME}" \
" - #{MarkdownExec::APP_DESC} (#{MarkdownExec::VERSION})",
- "Usage: #{executable_name} [(path | filename [block_name])] [options]"
+ "Usage: #{executable_name} [(directory | file [block_name] | search_keyword)] [options]"
].join("\n")
menu_iter do |item|
opts_menu_option_append opts, @options, item
end
@@ -551,11 +561,11 @@
->(value) {
read_configuration_file!(options, value)
}
when 'show_config'
->(_) {
- finalize_cli_argument_processing(options)
+ finalize_cli_argument_processing([])
@fout.fout options.sort_by_key.to_yaml
}
when 'val_as_bool'
->(value) {
value.instance_of?(::String) ? (value.chomp != '0') : value
@@ -708,11 +718,11 @@
@options[:saved_script_glob])
return unless filename
saved_name_split filename
@options[:save_executed_script] = false
- @options.document_menu_loop
+ @options.document_inpseq
rescue StandardError
error_handler('run_last_script')
end
def saved_name_split(name)
@@ -737,11 +747,10 @@
# Presents a TTY prompt to select an option or exit, returns selected option or nil
def select_option_or_exit(prompt_text, strings, opts = {})
result = @options.select_option_with_metadata(prompt_text, strings,
opts)
- ### 2024-04-20 what for?
# return unless result.fetch(:option, nil)
result[:selected]
end
@@ -774,10 +783,10 @@
)
return if filename.nil?
saved_name_split(filename)
- @options.document_menu_loop ### ({ save_executed_script: false })
+ @options.document_inpseq ### ({ save_executed_script: false })
end
public
def tab_completions(data = menu_for_optparse)