markdown_exec 1.5 → 1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41787e8352174177ca182e0376cabec7aee5923af43536a81fc2a9e61ee109e3
4
- data.tar.gz: 6a6c1fa34bf57aad286892772dcdbec19abb41fdb0385a69e264fee70747f742
3
+ metadata.gz: 97323ce7d6c677603ca89432c9ca64e45ff205a5b6cc03a71f4be1210bf8104a
4
+ data.tar.gz: ccce852fe96571b00c4443012371ea5ad29caec29dfdc9649cec7da2c091defe
5
5
  SHA512:
6
- metadata.gz: a4b9377c62c5054d077974b2056d7f89acd54088cd064d9c495b10eda49f64750154dc6618e6f7719dee93aaf3a0e0ca3cafa8d8fd7ca3ccbdb970e2c433b23c
7
- data.tar.gz: c9ed40b8c0df7b4b41e2db40d495a420ae1a294bbdd0c7df7702f5bfd99c6e9931a89e197e0fb5b3109fbec3403ef2b7c28126b1f0d000c6aea7c0426cde9a34
6
+ metadata.gz: bc08d47d135d9a078240c6e3001322ec8b35b8fb4f7febeabec02729240d7524a40464d9d563aeb15e5c8d09695bd0b512251d970dfede46cf07bd377af72181
7
+ data.tar.gz: ec61f969d204b0216c02e2e13d270363aef35ecf3ad6ff5a26d653e2d5c8f1608ff3e70a24ab65ab3bd48d8c546e1a6c627734c8e03e08a2440c18b1d9db7fed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6] - 2023-11-13
4
+
5
+ ### Added
6
+
7
+ - Options to remember a block's indentation in the source document and to display with same indentation in the menu.
8
+
9
+ ### Changed
10
+
11
+ - Note option matches the remaining lines in the document and they are displayed in the menu.
12
+
3
13
  ## [1.5] - 2023-11-08
4
14
 
5
15
  ### Added
data/Gemfile CHANGED
@@ -22,4 +22,7 @@ gem 'rubocop-rake', require: false
22
22
  gem 'rubocop-rspec', require: false
23
23
  gem 'shellwords'
24
24
  gem 'uri'
25
+
26
+ gem 'visual_call_graph'
27
+
25
28
  gem 'yaml', '~> 0.2.1'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (1.5)
4
+ markdown_exec (1.6)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -139,6 +139,8 @@ GEM
139
139
  rubocop (~> 1.33)
140
140
  rubocop-capybara (~> 2.17)
141
141
  rubocop-factory_bot (~> 2.22)
142
+ ruby-graphviz (1.2.5)
143
+ rexml
142
144
  ruby-progressbar (1.13.0)
143
145
  ruby2_keywords (0.0.5)
144
146
  shellwords (0.1.0)
@@ -157,6 +159,8 @@ GEM
157
159
  concurrent-ruby (~> 1.0)
158
160
  unicode-display_width (2.5.0)
159
161
  uri (0.12.2)
162
+ visual_call_graph (0.4.0)
163
+ ruby-graphviz (~> 1.2, >= 1.2.0)
160
164
  wisper (2.0.1)
161
165
  yaml (0.2.1)
162
166
  zeitwerk (2.6.12)
@@ -182,6 +186,7 @@ DEPENDENCIES
182
186
  rubocop-rspec
183
187
  shellwords
184
188
  uri
189
+ visual_call_graph
185
190
  yaml (~> 0.2.1)
186
191
 
187
192
  BUNDLED WITH
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "1.5"
16
+ echo "1.6"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -138,4 +138,4 @@ _mde() {
138
138
 
139
139
  complete -o filenames -o nospace -F _mde mde
140
140
  # _mde_echo_version
141
- # echo "Updated: 2023-11-08 15:34:04 UTC"
141
+ # echo "Updated: 2023-11-13 16:19:21 UTC"
data/examples/opts.md CHANGED
@@ -1,23 +1,20 @@
1
1
  # Demo configuring options
2
- + note1
3
- a
2
+
4
3
  ::: These Opts blocks set the color of a couple of menu options to demonstrate the live update of options.
5
- b
6
- + note2
7
- c
4
+
8
5
  ```opts :opts1
9
6
  menu_divider_color: yellow
10
7
  menu_note_match:
11
8
  menu_task_color: fg_rgb_255_63_255
12
9
  ```
13
- + note3
10
+
14
11
  ```opts :opts2
15
12
  menu_divider_color: red
16
13
  menu_note_color: yellow
17
14
  menu_note_match: "^\\+ +(?<line>.+?) *$"
18
15
  menu_task_color: fg_rgb_127_127_255
19
16
  ```
20
- + note4
17
+
21
18
  ```opts :(document_options)
22
19
  menu_divider_color: green
23
20
  menu_link_color: fg_rgbh_88_cc_66
@@ -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 = '1.5'
10
+ VERSION = '1.6'
11
11
  end
data/lib/markdown_exec.rb CHANGED
@@ -538,15 +538,24 @@ module MarkdownExec
538
538
  def create_and_add_chrome_blocks(blocks, fcb, opts, use_chrome)
539
539
  return unless use_chrome
540
540
 
541
- if opts[:menu_note_match].present? && (mbody = fcb.body[0].match opts[:menu_note_match])
542
- create_and_add_chrome_block(blocks, fcb, mbody, opts[:menu_note_format],
543
- opts[:menu_note_color].to_sym)
544
- elsif opts[:menu_divider_match].present? && (mbody = fcb.body[0].match opts[:menu_divider_match])
545
- create_and_add_chrome_block(blocks, fcb, mbody, opts[:menu_divider_format],
546
- opts[:menu_divider_color].to_sym)
547
- elsif opts[:menu_task_match].present? && (mbody = fcb.body[0].match opts[:menu_task_match])
548
- create_and_add_chrome_block(blocks, fcb, mbody, opts[:menu_task_format],
549
- opts[:menu_task_color].to_sym)
541
+ match_criteria = [
542
+ { match: :menu_task_match, format: :menu_task_format,
543
+ color: :menu_task_color },
544
+ { match: :menu_divider_match, format: :menu_divider_format,
545
+ color: :menu_divider_color },
546
+ { match: :menu_note_match, format: :menu_note_format,
547
+ color: :menu_note_color }
548
+ ]
549
+
550
+ match_criteria.each do |criteria|
551
+ unless opts[criteria[:match]].present? &&
552
+ (mbody = fcb.body[0].match opts[criteria[:match]])
553
+ next
554
+ end
555
+
556
+ create_and_add_chrome_block(blocks, fcb, mbody, opts[criteria[:format]],
557
+ opts[criteria[:color]].to_sym)
558
+ break
550
559
  end
551
560
  end
552
561
 
@@ -730,6 +739,7 @@ module MarkdownExec
730
739
  end
731
740
 
732
741
  # Formats multiline body content as a title string.
742
+ # indents all but first line with two spaces so it displays correctly in menu
733
743
  # @param body_lines [Array<String>] The lines of body content.
734
744
  # @return [String] Formatted title.
735
745
  def format_multiline_body_as_title(body_lines)
@@ -893,6 +903,16 @@ module MarkdownExec
893
903
  ENV[MDE_HISTORY_ENV_NAME] = new_history
894
904
  end
895
905
 
906
+ # Indents all lines in a given string with a specified indentation string.
907
+ # @param body [String] A multi-line string to be indented.
908
+ # @param indent [String] The string used for indentation (default is an empty string).
909
+ # @return [String] A single string with each line indented as specified.
910
+ def indent_all_lines(body, indent = nil)
911
+ return body if !indent.present?
912
+
913
+ body.lines.map { |line| indent + line.chomp }.join("\n")
914
+ end
915
+
896
916
  ## Sets up the options and returns the parsed arguments
897
917
  #
898
918
  def initialize_and_parse_cli_options
@@ -1132,31 +1152,6 @@ module MarkdownExec
1132
1152
  end.to_yaml
1133
1153
  end
1134
1154
 
1135
- def menu_for_blocks(menu_options)
1136
- options = calculated_options.merge menu_options
1137
- menu = []
1138
- iter_blocks_in_file(options) do |btype, fcb|
1139
- case btype
1140
- when :filter
1141
- %i[blocks line]
1142
- when :line
1143
- if options[:menu_divider_match] &&
1144
- (mbody = fcb.body[0].match(options[:menu_divider_match]))
1145
- menu.push FCB.new({ dname: mbody[:name], oname: mbody[:name],
1146
- disabled: '' })
1147
- end
1148
- if options[:menu_note_match] &&
1149
- (mbody = fcb.body[0].match(options[:menu_note_match]))
1150
- menu.push FCB.new({ dname: mbody[:name], oname: mbody[:name],
1151
- disabled: '' })
1152
- end
1153
- when :blocks
1154
- menu += [fcb.oname]
1155
- end
1156
- end
1157
- menu
1158
- end
1159
-
1160
1155
  ##
1161
1156
  # Generates a menu suitable for OptionParser from the menu items defined in YAML format.
1162
1157
  # @return [Array<Hash>] The array of option hashes for OptionParser.
@@ -1321,7 +1316,7 @@ module MarkdownExec
1321
1316
  next if Filter.prepared_not_in_menu?(opts, fcb)
1322
1317
 
1323
1318
  fcb.merge!(
1324
- name: fcb.dname,
1319
+ name: indent_all_lines(fcb.dname, fcb.fetch(:indent, nil)),
1325
1320
  label: BlockLabel.make(
1326
1321
  body: fcb[:body],
1327
1322
  filename: opts[:filename],
@@ -1653,6 +1648,7 @@ module MarkdownExec
1653
1648
  fcb = FCB.new
1654
1649
  fcb.headings = headings
1655
1650
  fcb.oname = fcb.dname = fcb_title_groups.fetch(:name, '')
1651
+ fcb.indent = fcb_title_groups.fetch(:indent, '')
1656
1652
  fcb.shell = fcb_title_groups.fetch(:shell, '')
1657
1653
  fcb.title = fcb_title_groups.fetch(:name, '')
1658
1654
  fcb.body = []
@@ -1749,7 +1745,13 @@ module MarkdownExec
1749
1745
  state[:in_fenced_block] = true
1750
1746
  end
1751
1747
  elsif state[:in_fenced_block] && state[:fcb].body
1752
- state[:fcb].body += [line.chomp]
1748
+ ## add line to fenced code block
1749
+ # remove fcb indent if possible
1750
+ #
1751
+ state[:fcb].body += [
1752
+ line.chomp.sub(/^#{state[:fcb].indent}/, '')
1753
+ ]
1754
+
1753
1755
  else
1754
1756
  process_line(line, opts, selected_messages, &block)
1755
1757
  end
data/lib/menu.src.yml CHANGED
@@ -118,12 +118,14 @@
118
118
  :procname: exit
119
119
  :short_name: x
120
120
 
121
- - :default: "^`{3,}"
121
+ ## match fenced code indented by spaces
122
+ #
123
+ - :default: "^(?<indent> *)`{3,}"
122
124
  :env_var: MDE_FENCED_START_AND_END_REGEX
123
125
  :opt_name: fenced_start_and_end_regex
124
126
  :procname: val_as_str
125
127
 
126
- - :default: "^`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
128
+ - :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
127
129
  :env_var: MDE_FENCED_START_EXTENDED_REGEX
128
130
  :opt_name: fenced_start_extended_regex
129
131
  :procname: val_as_str
@@ -330,7 +332,7 @@
330
332
  :opt_name: menu_link_format
331
333
  :procname: val_as_str
332
334
 
333
- - :default: fg_rgbh_44_44_44
335
+ - :default: fg_rgbh_88_88_88
334
336
  :description: Color of menu note
335
337
  :env_var: MDE_MENU_NOTE_COLOR
336
338
  :opt_name: menu_note_color
@@ -342,7 +344,9 @@
342
344
  :opt_name: menu_note_format
343
345
  :procname: val_as_str
344
346
 
345
- - :default: "^\\+ *(?<line>.*?) *$"
347
+ ## all non-blank lines are notes
348
+ #
349
+ - :default: "^(?<line>.*?) *$"
346
350
  :description: Pattern for notes in block selection menu
347
351
  :env_var: MDE_MENU_NOTE_MATCH
348
352
  :opt_name: menu_note_match
data/lib/menu.yml CHANGED
@@ -1,4 +1,4 @@
1
- # MDE - Markdown Executor (1.5)
1
+ # MDE - Markdown Executor (1.6)
2
2
  ---
3
3
  - :description: Show current configuration values
4
4
  :procname: show_config
@@ -99,11 +99,12 @@
99
99
  :long_name: exit
100
100
  :procname: exit
101
101
  :short_name: x
102
- - :default: "^`{3,}"
102
+ - :default: "^(?<indent> *)`{3,}"
103
103
  :env_var: MDE_FENCED_START_AND_END_REGEX
104
104
  :opt_name: fenced_start_and_end_regex
105
105
  :procname: val_as_str
106
- - :default: "^`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
106
+ - :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*)
107
+ *$"
107
108
  :env_var: MDE_FENCED_START_EXTENDED_REGEX
108
109
  :opt_name: fenced_start_extended_regex
109
110
  :procname: val_as_str
@@ -275,7 +276,7 @@
275
276
  :env_var: MDE_MENU_LINK_FORMAT
276
277
  :opt_name: menu_link_format
277
278
  :procname: val_as_str
278
- - :default: fg_rgbh_44_44_44
279
+ - :default: fg_rgbh_88_88_88
279
280
  :description: Color of menu note
280
281
  :env_var: MDE_MENU_NOTE_COLOR
281
282
  :opt_name: menu_note_color
@@ -285,7 +286,7 @@
285
286
  :env_var: MDE_MENU_NOTE_FORMAT
286
287
  :opt_name: menu_note_format
287
288
  :procname: val_as_str
288
- - :default: "^\\+ *(?<line>.*?) *$"
289
+ - :default: "^(?<line>.*?) *$"
289
290
  :description: Pattern for notes in block selection menu
290
291
  :env_var: MDE_MENU_NOTE_MATCH
291
292
  :opt_name: menu_note_match
data/lib/pty1.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'pty'
2
+
3
+ def launch_and_interact_with_terminal
4
+ begin
5
+ PTY.spawn("bash") do |stdout, stdin, pid|
6
+ # Send a command to the terminal
7
+ stdin.puts "echo 'Hello from Ruby!'"
8
+
9
+ # Read the output of the command
10
+ stdout.each do |line|
11
+ puts line
12
+ break if line.include?("Hello from Ruby!")
13
+ end
14
+
15
+ # You can continue to interact with the terminal here
16
+ # ...
17
+
18
+ # Ensure to exit the spawned shell
19
+ stdin.puts "exit"
20
+ end
21
+ rescue PTY::ChildExited => e
22
+ puts "The child process exited!"
23
+ end
24
+ end
25
+
26
+ launch_and_interact_with_terminal
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: '1.5'
4
+ version: '1.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fareed Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -144,6 +144,7 @@ files:
144
144
  - lib/method_sorter.rb
145
145
  - lib/object_present.rb
146
146
  - lib/option_value.rb
147
+ - lib/pty1.rb
147
148
  - lib/regexp.rb
148
149
  - lib/rspec_helpers.rb
149
150
  - lib/saved_assets.rb