markdown_exec 2.8.0 → 2.8.2

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: c36bb5c2d9e91eeeae59067f91fc88a3ad8e6b1a27ebfb474ff900903d030042
4
- data.tar.gz: b002fc24e78006e830fdc66bb0be4df05fe9df62e6c036965eefbb7047f37ec7
3
+ metadata.gz: 066c72f2f85462a89163b7834669dee6526e516ee3ebfe4be2e8b269cb4ece36
4
+ data.tar.gz: 48c2bce9ac82cda2cbecca5bea4564b28013cdbab7005e249e8a856d0280afa0
5
5
  SHA512:
6
- metadata.gz: 8eedac9012c2c0103afe99a8ea0cd235b26b3ab62618b35d79af6f685a56195818d28ba70588f93d754c76e5c4b3bb524de0ed09fd97864bdc79a424015911a9
7
- data.tar.gz: d24b8c56e50416032de644f00d11f6bb81689617e47da57ec1e4b39a693c867dedff268ddd00e023bc134fc40ee9ae9b452a808131d129b378508464ac0793f5
6
+ metadata.gz: fe1270b8cf11efc8ad9e81cb43052bc75cfc217e362c7d6e30acb6981a6d0be749f290b9b15ce1a2655d6a7e157177c4cd975aa61de22a6f6bafe2a835285228
7
+ data.tar.gz: 9445285db86af55fe5ba0b784a24d30dd418ac3d1dc551183a5a1b3b865df27a6b314ddc08b4a013de5e926e023439753fe08cd4ea8d6c6da0c0d9547e4a9546
data/.rubocop.yml CHANGED
@@ -76,6 +76,9 @@ Security/YAMLLoad:
76
76
  Style/ClassVars:
77
77
  Enabled: false
78
78
 
79
+ Style/CombinableLoops:
80
+ Enabled: false
81
+
79
82
  Style/CommentedKeyword:
80
83
  Enabled: false
81
84
 
@@ -97,6 +100,9 @@ Style/GlobalVars:
97
100
  Style/IfUnlessModifier: # 2024-08 suggests lines that are too long
98
101
  Enabled: false
99
102
 
103
+ Style/KeywordParametersOrder:
104
+ Enabled: false
105
+
100
106
  Style/Lambda:
101
107
  Enabled: false
102
108
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.8.2] - 2025-02-19
4
+
5
+ ### Added
6
+
7
+ - UX blocks can add preconditions. Preconditions are variable names that must be set before the UX block is executed. If any preconditions are not set, a warning is displayed, and the sequence is aborted.
8
+ - UX blocks can require shell an other UX blocks.
9
+ - UX blocks are evaluated in order and calculation can depend on prior variables in the same sequence.
10
+
11
+ ### Changed
12
+
13
+ - Hide all blocks per their initial title instead of `oname`.
14
+ - Make menu blocks for list of files found to fix crash.
15
+ - Use a block ID to recall the selected block.
16
+ - UX blocks are hidden similar to the rest.
17
+
18
+ ## [2.8.1] - 2025-02-13
19
+
20
+ ### Added
21
+
22
+ - BATS tests for UX block type.
23
+
24
+ ### Changed
25
+
26
+ - Improve persistence of position in menu on reload
27
+ - Update block-type-ux-exec BATS test.
28
+ - Refactor menu for selecting items with facets.
29
+
3
30
  ## [2.8.0] - 2025-02-10
4
31
 
5
32
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.8.0)
4
+ markdown_exec (2.8.2)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'hide blocks' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-hide.md \
7
+ 'visible'
8
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Initial values' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-auto.md \
7
+ 'v1 = _v2 = _v3 = 12_v4 = 21_v5 = markdown_exec_v6 = 31'
8
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Output of executed commands as initial value' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-exec.md \
7
+ "ux0=_ux1=Unknown_ux2=markdown_exec_ux3=markdown_exec_ux4=Xform: 'markdown'"
8
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Output of executed commands as initial value' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-require.md \
7
+ 'SPECIES=Pongo tapanuliensis_GENUS=Pongo_NAME=Pongo tapanuliensis - Pongo_NAME2=Pongo tapanuliensis - Pongo'
8
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Row format merges with prior table' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-row-format.md \
7
+ ' | Variable | Value | Prompt |_ | --------- | ---------------- | ------------------- |_ | Species | Pongo tapanulien | New species? |_ | Name: Gen | Value: Pongo | Prompt: New genus? |_ | Family | Hominidae | Enter a value: |'
8
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Transformed output of executed commands' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-transform.md \
7
+ '_Execution output has a trailing newline._Var0=markdown_exec_00000000 6d 61 72 6b 64 6f 77 6e 5f 65 78 65 63 0a |markdown_exec.|__With validate and transform, output has no newline._Var1=markdown_exec_00000000 6d 61 72 6b 64 6f 77 6e 5f 65 78 65 63 |markdown_exec|__With transform :chomp, output has no newline._Var2=markdown_exec_00000000 6d 61 72 6b 64 6f 77 6e 5f 65 78 65 63 |markdown_exec|__With transform :upcase, output is in upper case w/ newline._Var3=MARKDOWN_EXEC_00000000 4d 41 52 4b 44 4f 57 4e 5f 45 58 45 43 0a |MARKDOWN_EXEC.|'
8
+ }
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "2.8.0"
16
+ echo "2.8.2"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -0,0 +1,18 @@
1
+ ``` :(hidden)
2
+ ```
3
+ ``` :visible
4
+ ```
5
+ / ux block is displayed differently than other types
6
+ ```ux :()
7
+ name: name
8
+ ```
9
+ @import bats-document-configuration.md
10
+ ```opts :(document_opts)
11
+ # Pattern for blocks to hide from user-selection
12
+ block_name_include_match:
13
+ ^\(.*\)$
14
+
15
+ # Pattern for the block name in the line defining the block
16
+ block_name_match: |
17
+ :(?<title>\S+)( |$)
18
+ ```
@@ -0,0 +1,43 @@
1
+ / v2025-02-08
2
+ / name only
3
+ ```ux
4
+ name: v1
5
+ ```
6
+ / name and default
7
+ / transform and validate options not applied to default
8
+ ```ux
9
+ default: 11
10
+ name: v2
11
+ ```
12
+ / name and default; auto-load
13
+ / prompt option is ignored during auto-load
14
+ ```ux :[document_ux_v3]
15
+ default: 12
16
+ name: v3
17
+ ```
18
+ / name, default, exec; auto-load static
19
+ ```ux :[document_ux_v4]
20
+ default: 21
21
+ exec: basename $(pwd)
22
+ name: v4
23
+ ```
24
+ / name, default, exec; auto-load executed `basename $(pwd)`
25
+ / allowed is ignored by exec
26
+ ```ux :[document_ux_v5]
27
+ default: :exec
28
+ exec: basename $(pwd)
29
+ name: v5
30
+ ```
31
+ / name, default, allowed; auto-load static default
32
+ ```ux :[document_ux_v6]
33
+ allowed:
34
+ - 32
35
+ - 33
36
+ default: 31
37
+ name: v6
38
+ ```
39
+ @import bats-document-configuration.md
40
+ ```opts :(document_opts)
41
+ menu_ux_row_format: '%{name} = ${%{name}}'
42
+ ux_auto_load_force_default: true
43
+ ```
@@ -0,0 +1,42 @@
1
+ / auto-load block, does not execute command to calculate
2
+ / click block to calculate
3
+ ```ux :[document_ux0]
4
+ exec: basename $(pwd)
5
+ name: ux0
6
+ ```
7
+ / auto-load block and execute command to calculate
8
+ / click block to recalculate
9
+ ```ux :[document_ux1]
10
+ default: Unknown
11
+ exec: basename $(pwd)
12
+ name: ux1
13
+ ```
14
+ / auto-load block and execute command to calculate
15
+ / click block to recalculate
16
+ ```ux :[document_ux2]
17
+ default: :exec
18
+ exec: basename $(pwd)
19
+ name: ux2
20
+ ```
21
+ / required block defining a function used in exec
22
+ ```bash :(bash3)
23
+ # function from bash3
24
+ val () { basename $(pwd) ; }
25
+ ```
26
+ ```ux :[document_ux3] +(bash3)
27
+ default: :exec
28
+ exec: val
29
+ name: ux3
30
+ ```
31
+ / default is computed
32
+ / output of execution is validated/parsed
33
+ / parsing is transformed
34
+ ```ux :[document_ux4]
35
+ default: :exec
36
+ exec: basename $(pwd)
37
+ name: ux4
38
+ transform: "Xform: '%{name}'"
39
+ validate: |
40
+ ^(?<name>.*)(_.*)$
41
+ ```
42
+ @import bats-document-configuration.md
@@ -0,0 +1,28 @@
1
+ / an automatic UX block requires a shell block and another UX block
2
+ ``` :(shell)
3
+ ENTITY='Pongo tapanuliensis,Pongo'
4
+ ```
5
+ ```ux :[document_ux_SPECIES] +(shell) +[ux_GENUS]
6
+ default: :exec
7
+ exec: printf "${ENTITY%%,*}"
8
+ name: SPECIES
9
+ ```
10
+ / required ux block requires another
11
+ ```ux :[ux_GENUS] +[ux_NAME]
12
+ default: :exec
13
+ exec: printf "${ENTITY##*,}"
14
+ name: GENUS
15
+ ```
16
+ / executed in context of prior ux blocks, uses their initial values
17
+ ```ux :[ux_NAME]
18
+ default: :exec
19
+ exec: printf "$SPECIES - $GENUS"
20
+ name: NAME
21
+ ```
22
+ / executed after other ux blocks, uses their initial values
23
+ ```ux :[document_ux_NAME2]
24
+ default: :exec
25
+ exec: printf "$NAME"
26
+ name: NAME2
27
+ ```
28
+ @import bats-document-configuration.md
@@ -0,0 +1,47 @@
1
+ / v2025-02-08
2
+ | Variable| Value| Prompt
3
+ | -| -| -
4
+ / auto-load default value
5
+ / custom prompt
6
+ / select list
7
+ / default value
8
+ ```ux :[document_ux_Species]
9
+ allowed:
10
+ - Pongo tapanuliensis
11
+ - Histiophryne psychedelica
12
+ - Phyllopteryx dewysea
13
+ default: Pongo tapanuliensis
14
+ name: Species
15
+ prompt: New species?
16
+ ```
17
+ / auto-load default value
18
+ / cell text is prefixed Name/Value/Prompt
19
+ / select list contains additional text
20
+ / selected value is validated with named groups
21
+ / selected value is transformed; named capture is prefixed Xform
22
+ ```ux :[document_ux_Genus]
23
+ allowed:
24
+ - 1. Pongo
25
+ - 2. Histiophryne
26
+ - 3. Phyllopteryx
27
+ default: Pongo
28
+ menu_format: "| Name: %{name}| Value: ${%{name}}| Prompt: %{prompt}"
29
+ name: Genus
30
+ prompt: New genus?
31
+ transform: "Xform: '%{name}'"
32
+ validate: |
33
+ ^\d+\. *(?<name>[^ ].*)$
34
+ ```
35
+ / default
36
+ / auto-load default value
37
+ ```ux :[document_ux_Family]
38
+ default: Hominidae
39
+ name: Family
40
+ ```
41
+ @import bats-document-configuration.md
42
+ ```opts :(document_opts)
43
+ menu_ux_row_format: '| %{name}| ${%{name}}| %{prompt}'
44
+ screen_width: 64
45
+ table_center: true
46
+ ux_auto_load_force_default: true
47
+ ```
@@ -0,0 +1,41 @@
1
+ :::
2
+ **Execution output has a trailing newline.**
3
+ ```ux :[document_ux_transform_0]
4
+ default: :exec
5
+ exec: basename $(pwd)
6
+ name: Var0
7
+ ```
8
+ $(echo -n "$Var0" | hexdump -C)
9
+ :::
10
+ **With validate and transform, output has no newline.**
11
+ ```ux :[document_ux_transform_1]
12
+ default: :exec
13
+ exec: basename $(pwd)
14
+ name: Var1
15
+ transform: '%{name}'
16
+ validate: (?<name>.+)
17
+ ```
18
+ $(echo -n "$Var1" | hexdump -C)
19
+ :::
20
+ **With transform `:chomp`, output has no newline.**
21
+ ```ux :[document_ux_transform_2]
22
+ default: :exec
23
+ exec: basename $(pwd)
24
+ name: Var2
25
+ transform: :chomp
26
+ ```
27
+ $(echo -n "$Var2" | hexdump -C)
28
+ :::
29
+ **With transform `:upcase`, output is in upper case w/ newline.**
30
+ ```ux :[document_ux_transform_3]
31
+ default: :exec
32
+ exec: basename $(pwd)
33
+ name: Var3
34
+ transform: :upcase
35
+ ```
36
+ $(echo -n "$Var3" | hexdump -C)
37
+ @import bats-document-configuration.md
38
+ ```opts :(document_opts)
39
+ divider4_collapsible: false
40
+ table_center: false
41
+ ```
data/lib/constants.rb CHANGED
@@ -100,8 +100,10 @@ end
100
100
 
101
101
  # selected block and subsequent menu state
102
102
  #
103
+ BlockSelection = Struct.new(:id)
103
104
  SelectedBlockMenuState = Struct.new(:block, :source, :state)
104
105
 
105
106
  class TtyMenu
107
+ ENABLE = nil
106
108
  DISABLE = ''
107
109
  end
data/lib/fcb.rb CHANGED
@@ -14,7 +14,8 @@ def parse_yaml_of_ux_block(
14
14
  export = data['export']
15
15
  export = data if export.nil?
16
16
  name = export['name']
17
- raise "Invalid data: #{data.inspect}" unless name.present?
17
+
18
+ raise "Name is missing in UX block: #{data.inspect}" unless name.present?
18
19
 
19
20
  OpenStruct.new(
20
21
  allowed: export['allowed'],
@@ -22,6 +23,7 @@ def parse_yaml_of_ux_block(
22
23
  exec: export['exec'],
23
24
  menu_format: export['menu_format'] || menu_format,
24
25
  name: name,
26
+ preconditions: export['preconditions'],
25
27
  prompt: export['prompt'] || prompt,
26
28
  transform: export['transform'],
27
29
  validate: export['validate'] || validate
@@ -56,10 +58,6 @@ module MarkdownExec
56
58
  title: '',
57
59
  type: ''
58
60
  }.merge(options)
59
- # @attrs[:raw_body] ||= @attrs[:body]
60
- # @attrs[:raw_dname] ||= @attrs[:dname]
61
- # @attrs[:raw_s0printable] ||= @attrs[:s0printable]
62
- # @attrs[:raw_s1decorated] ||= @attrs[:s1decorated]
63
61
  end
64
62
 
65
63
  def code_name_included?(*names)
@@ -92,34 +90,6 @@ module MarkdownExec
92
90
  end
93
91
  end
94
92
 
95
- # def body=(value)
96
- # ww0 'body=', value
97
- # # binding.irb
98
- # @attrs[:raw_body] ||= value
99
- # @attrs[:body] = value
100
- # end
101
-
102
- # def dname=(value)
103
- # ww0 'dname=', value
104
- # binding.irb if value == ' | Species| Not specified'
105
- # @attrs[:raw_dname] ||= value
106
- # @attrs[:dname] = value
107
- # end
108
-
109
- # def s0printable=(value)
110
- # ww0 's0printable=', value
111
- # # binding.irb
112
- # @attrs[:raw_s0printable] ||= value
113
- # @attrs[:s0printable] = value
114
- # end
115
-
116
- # def s1decorated=(value)
117
- # ww0 's1decorated=', value
118
- # # binding.irb
119
- # @attrs[:raw_s1decorated] ||= value
120
- # @attrs[:s1decorated] = value
121
- # end
122
-
123
93
  # Processes a block to generate its summary, modifying its attributes
124
94
  # based on various matching criteria.
125
95
  # It handles special formatting for bash blocks, extracting and setting
@@ -168,6 +138,7 @@ module MarkdownExec
168
138
  @attrs[:center] = table_center
169
139
  oname = @attrs[:oname] = format(export.menu_format, export.to_h)
170
140
  else
141
+ # triggered by an empty block
171
142
  raise "Invalid data type: #{data.inspect}"
172
143
  end
173
144
  end