markdown_exec 2.8.4 → 3.0.0

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -1
  3. data/Gemfile.lock +1 -1
  4. data/Rakefile +0 -33
  5. data/bats/bats.bats +2 -0
  6. data/bats/block-type-link.bats +1 -1
  7. data/bats/block-type-ux-allowed.bats +2 -2
  8. data/bats/block-type-ux-default.bats +8 -0
  9. data/bats/block-type-ux-invalid.bats +1 -1
  10. data/bats/{block-type-ux-preconditions.bats → block-type-ux-required-variables.bats} +1 -1
  11. data/bats/block-type-ux-row-format.bats +1 -1
  12. data/bats/block-type-ux-sources.bats +36 -0
  13. data/bats/border.bats +1 -1
  14. data/bats/cli.bats +2 -2
  15. data/bats/command-substitution-options.bats +14 -0
  16. data/bats/command-substitution.bats +1 -1
  17. data/bats/fail.bats +5 -2
  18. data/bats/indented-block-type-vars.bats +1 -1
  19. data/bats/markup.bats +1 -1
  20. data/bats/option-expansion.bats +8 -0
  21. data/bats/table-column-truncate.bats +1 -1
  22. data/bats/test_helper.bash +50 -5
  23. data/docs/dev/bats-document-configuration.md +1 -1
  24. data/docs/dev/block-type-ux-allowed.md +5 -5
  25. data/docs/dev/block-type-ux-auto.md +9 -5
  26. data/docs/dev/block-type-ux-chained.md +4 -2
  27. data/docs/dev/block-type-ux-default.md +42 -0
  28. data/docs/dev/block-type-ux-echo-hash.md +6 -1
  29. data/docs/dev/block-type-ux-echo.md +3 -1
  30. data/docs/dev/block-type-ux-exec.md +3 -4
  31. data/docs/dev/block-type-ux-hidden.md +3 -0
  32. data/docs/dev/block-type-ux-require.md +9 -18
  33. data/docs/dev/{block-type-ux-preconditions.md → block-type-ux-required-variables.md} +1 -2
  34. data/docs/dev/block-type-ux-row-format.md +3 -4
  35. data/docs/dev/block-type-ux-sources.md +57 -0
  36. data/docs/dev/block-type-ux-transform.md +0 -4
  37. data/docs/dev/command-substitution-options.md +61 -0
  38. data/docs/dev/indented-block-type-vars.md +1 -0
  39. data/docs/dev/menu-pagination-indent.md +123 -0
  40. data/docs/dev/menu-pagination.md +111 -0
  41. data/docs/dev/option-expansion.md +10 -0
  42. data/lib/ansi_formatter.rb +2 -0
  43. data/lib/block_cache.rb +197 -0
  44. data/lib/command_result.rb +57 -0
  45. data/lib/constants.rb +18 -0
  46. data/lib/error_reporting.rb +38 -0
  47. data/lib/evaluate_shell_expressions.rb +43 -18
  48. data/lib/fcb.rb +114 -11
  49. data/lib/hash_delegator.rb +595 -359
  50. data/lib/markdown_exec/version.rb +1 -1
  51. data/lib/markdown_exec.rb +136 -45
  52. data/lib/mdoc.rb +74 -23
  53. data/lib/menu.src.yml +27 -9
  54. data/lib/menu.yml +23 -8
  55. data/lib/namer.rb +1 -3
  56. data/lib/value_or_exception.rb +76 -0
  57. metadata +18 -4
@@ -1,6 +1,5 @@
1
1
  / This automatic block sets VAR and displays the current value in the menu.
2
2
  ```ux :[document_ux_VAR]
3
- default: :echo
4
3
  echo: $(basename `pwd`)
5
4
  name: VAR
6
5
  ```
@@ -10,11 +9,14 @@ menu_with_inherited_lines: true
10
9
  ```
11
10
  / This block is not visible. Execute to set a new value, displayed by the block above.
12
11
  ```ux :(VAR_has_count)
12
+ init: false
13
13
  echo: $(basename `pwd` | wc -c)
14
+ force: false
14
15
  name: VAR
15
16
  ```
16
17
  / This block is visible. Execute to set a new value, displayed by the block above.
17
18
  ```ux :[IAB_has_count]
19
+ init: false
18
20
  echo: $VAR$VAR
19
21
  name: IAB
20
22
  ```
@@ -1,20 +1,21 @@
1
1
  / auto-load block, does not execute command to calculate
2
2
  / click block to calculate
3
3
  ```ux :[document_ux0]
4
+ init: ''
4
5
  exec: basename $(pwd)
5
6
  name: ux0
6
7
  ```
7
8
  / auto-load block and execute command to calculate
8
9
  / click block to recalculate
9
10
  ```ux :[document_ux1]
10
- default: Unknown
11
+ init: Unknown
11
12
  exec: basename $(pwd)
12
13
  name: ux1
13
14
  ```
14
15
  / auto-load block and execute command to calculate
15
16
  / click block to recalculate
16
17
  ```ux :[document_ux2]
17
- default: :exec
18
+ act: :exec
18
19
  exec: basename $(pwd)
19
20
  name: ux2
20
21
  ```
@@ -24,7 +25,6 @@ name: ux2
24
25
  val () { basename $(pwd) ; }
25
26
  ```
26
27
  ```ux :[document_ux3] +(bash3)
27
- default: :exec
28
28
  exec: val
29
29
  name: ux3
30
30
  ```
@@ -32,7 +32,6 @@ name: ux3
32
32
  / output of execution is validated/parsed
33
33
  / parsing is transformed
34
34
  ```ux :[document_ux4]
35
- default: :exec
36
35
  exec: basename $(pwd)
37
36
  name: ux4
38
37
  transform: "Xform: '%{name}'"
@@ -4,17 +4,20 @@ ENTITY='Pongo tapanuliensis,Pongo'
4
4
  ```
5
5
  ```ux :[SPECIES] +(shell) +(GENUS)
6
6
  echo: "${ENTITY%%,*}"
7
+ init: false
7
8
  name: SPECIES
8
9
  ```
9
10
  / required ux block requires another
10
11
  ```ux :(GENUS) +[NAME]
11
12
  echo: "${ENTITY##*,}"
13
+ init: false
12
14
  name: GENUS
13
15
  readonly: true
14
16
  ```
15
17
  / executed in context of prior ux blocks, uses their values
16
18
  ```ux :[NAME]
17
19
  echo: "$SPECIES - $GENUS"
20
+ init: false
18
21
  name: NAME
19
22
  readonly: true
20
23
  ```
@@ -1,32 +1,23 @@
1
- / an automatic UX block requires a shell block and another UX block
1
+ / This is an hidden shell block that is required by UX blocks.
2
2
  ``` :(shell)
3
3
  ENTITY='Pongo tapanuliensis,Pongo'
4
4
  ```
5
- ```ux :[document_ux_SPECIES] +(shell) +[ux_GENUS]
6
- default: :exec
7
- exec: echo "${ENTITY%%,*}"
5
+ ```ux +(shell)
6
+ echo: "${ENTITY%%,*}"
8
7
  name: SPECIES
9
- transform: :chomp
10
8
  ```
11
- / required ux block requires another
12
- ```ux :[ux_GENUS] +[ux_NAME]
13
- default: :exec
14
- exec: echo "${ENTITY##*,}"
9
+ ```ux +(shell)
10
+ echo: "${ENTITY##*,}"
15
11
  name: GENUS
16
- transform: :chomp
17
12
  ```
18
13
  / executed in context of prior ux blocks, uses their initial values
19
- ```ux :[ux_NAME]
20
- default: :exec
21
- exec: echo "$SPECIES - $GENUS"
14
+ ```ux
15
+ echo: "$SPECIES - $GENUS"
22
16
  name: NAME
23
- transform: :chomp
24
17
  ```
25
18
  / executed after other ux blocks, uses their initial values
26
- ```ux :[document_ux_NAME2]
27
- default: :exec
28
- exec: echo "$NAME"
19
+ ```ux
20
+ echo: "$NAME"
29
21
  name: NAME2
30
- transform: :chomp
31
22
  ```
32
23
  @import bats-document-configuration.md
@@ -1,9 +1,8 @@
1
1
  / an automatic UX block that has a precondition that must be met before it is executed
2
2
  ```ux :[document_ux_SPECIES]
3
- default: :exec
4
3
  exec: printf "$MISSING_VARIABLE"
5
4
  name: SPECIES
6
- preconditions:
5
+ required:
7
6
  - MISSING_VARIABLE
8
7
  ```
9
8
  @import bats-document-configuration.md
@@ -10,7 +10,7 @@ allowed:
10
10
  - Pongo tapanuliensis
11
11
  - Histiophryne psychedelica
12
12
  - Phyllopteryx dewysea
13
- default: Pongo tapanuliensis
13
+ init: Pongo tapanuliensis
14
14
  name: Species
15
15
  prompt: New species?
16
16
  ```
@@ -24,7 +24,6 @@ allowed:
24
24
  - 1. Pongo
25
25
  - 2. Histiophryne
26
26
  - 3. Phyllopteryx
27
- default: Pongo
28
27
  menu_format: "| Name: %{name}| Value: ${%{name}}| Prompt: %{prompt}"
29
28
  name: Genus
30
29
  prompt: New genus?
@@ -35,13 +34,13 @@ validate: |
35
34
  / default
36
35
  / auto-load default value
37
36
  ```ux :[document_ux_Family]
38
- default: Hominidae
37
+ init: Hominidae
39
38
  name: Family
40
39
  ```
41
40
  @import bats-document-configuration.md
42
41
  ```opts :(document_opts)
43
42
  menu_ux_row_format: '| %{name}| ${%{name}}| %{prompt}'
44
- screen_width: 64
43
+ screen_width: 72
45
44
  table_center: true
46
45
  ux_auto_load_force_default: true
47
46
  ```
@@ -0,0 +1,57 @@
1
+ / 1. Simple variable display and edit:
2
+ ```ux
3
+ name: USER_NAME
4
+ prompt: Enter your name
5
+ default: Guest
6
+ ```
7
+ /Behavior: Displays the USER_NAME variable. When clicked, prompts for input with "Enter your name" and defaults to "Guest" if no input is provided.
8
+ /
9
+ /2. Command output initialization:
10
+ ```ux
11
+ name: CURRENT_DIR
12
+ init: :exec
13
+ exec: basename $(pwd)
14
+ transform: :chomp
15
+ ```
16
+ /Behavior: Initializes CURRENT_DIR with the output of the `pwd` command when the document loads.
17
+ /
18
+ /3. Echo-based initialization:
19
+ ```ux
20
+ name: SHELL_VERSION
21
+ init: :echo
22
+ echo: $SHELL
23
+ ```
24
+ /Behavior: Sets SHELL_VERSION to the value of the $SHELL environment variable when the document loads.
25
+ /
26
+ /4. Selection from allowed values:
27
+ ```ux
28
+ name: ENVIRONMENT
29
+ allow:
30
+ - development
31
+ - staging
32
+ - production
33
+ prompt: Select environment
34
+ ```
35
+ /Behavior: When activated, presents a menu to select from development, staging, or production environments.
36
+ /
37
+ /## Validation Examples
38
+ /
39
+ /5. Email validation:
40
+ ```ux
41
+ name: USER_EMAIL
42
+ prompt: Enter email address
43
+ validate: '(?<local>[^@]+)@(?<domain>[^@]+)'
44
+ transform: '%{local}@%{domain}'
45
+ ```
46
+ /Behavior: Validates input as an email address, capturing local and domain parts. The transform ensures proper formatting.
47
+ /
48
+ /6. Version number validation:
49
+ ```ux
50
+ name: VERSION
51
+ prompt: Enter version number
52
+ validate: '(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)'
53
+ transform: '%{major}.%{minor}.%{patch}'
54
+ ```
55
+ /Behavior: Ensures input follows semantic versioning format (e.g., 1.2.3).
56
+ /
57
+ @import bats-document-configuration.md
@@ -1,7 +1,6 @@
1
1
  :::
2
2
  **Execution output has a trailing newline.**
3
3
  ```ux :[document_ux_transform_0]
4
- default: :exec
5
4
  exec: basename $(pwd)
6
5
  name: Var0
7
6
  ```
@@ -9,7 +8,6 @@ $(echo -n "$Var0" | hexdump -C)
9
8
  :::
10
9
  **With validate and transform, output has no newline.**
11
10
  ```ux :[document_ux_transform_1]
12
- default: :exec
13
11
  exec: basename $(pwd)
14
12
  name: Var1
15
13
  transform: '%{name}'
@@ -19,7 +17,6 @@ $(echo -n "$Var1" | hexdump -C)
19
17
  :::
20
18
  **With transform `:chomp`, output has no newline.**
21
19
  ```ux :[document_ux_transform_2]
22
- default: :exec
23
20
  exec: basename $(pwd)
24
21
  name: Var2
25
22
  transform: :chomp
@@ -28,7 +25,6 @@ $(echo -n "$Var2" | hexdump -C)
28
25
  :::
29
26
  **With transform `:upcase`, output is in upper case w/ newline.**
30
27
  ```ux :[document_ux_transform_3]
31
- default: :exec
32
28
  exec: basename $(pwd)
33
29
  name: Var3
34
30
  transform: :upcase
@@ -0,0 +1,61 @@
1
+ / command substitution options to use different patterns
2
+ /
3
+ @import bats-document-configuration.md
4
+ /
5
+ ```vars :(document_vars)
6
+ Common_Name: Tapanuli Orangutan
7
+ Species: Pongo tapanuliensis
8
+ ```
9
+ /
10
+ ::: Command substitution
11
+
12
+ The current value of environment variable `Common_Name` is displayed using two different operators.
13
+ The command `echo $SHLVL` is executed via command substitution, using two different operators.
14
+
15
+ | Operator| Variable Expansion| Command Substitution
16
+ | -| -| -
17
+ | $| ${Common_Name}| $(echo $Species)
18
+ | @| @{Common_Name}| @(echo $Species)
19
+
20
+ ::: Toggle between operators.
21
+
22
+ /| MDE Option| Value
23
+ /| -| -
24
+ /| command_substitution_regexp| &{command_substitution_regexp}
25
+ /| menu_ux_row_format| &{menu_ux_row_format}
26
+ /| variable_expansion_regexp| &{variable_expansion_regexp}
27
+
28
+ / This block requires a hidden block.
29
+ ```opts :operator_$ +(operator_$2)
30
+ command_substitution_regexp: '(?<expression>\$\((?<command>([^()]*(\([^()]*\))*[^()]*)*)\))'
31
+ ```
32
+ ```opts :(operator_$2)
33
+ menu_ux_row_format: '%{name}=${%{name}}'
34
+ variable_expansion_regexp: '(?<expression>\${(?<variable>[A-Z0-9a-z_]+)})'
35
+ ```
36
+
37
+ ```opts :operator_@
38
+ command_substitution_regexp: '(?<expression>@\((?<command>([^()]*(\([^()]*\))*[^()]*)*)\))'
39
+ menu_ux_row_format: '%{name}=@{%{name}}'
40
+ variable_expansion_regexp: '(?<expression>@{(?<variable>[A-Z0-9a-z_]+)})'
41
+ ```
42
+
43
+ ```opts :(both)
44
+ command_substitution_regexp: '(?<expression>[\$\@]\((?<command>([^()]*(\([^()]*\))*[^()]*)*)\))'
45
+ menu_ux_row_format: '%{name}=${%{name}}'
46
+ variable_expansion_regexp: '(?<expression>[\$\@]{(?<variable>[A-Z0-9a-z_]+)})'
47
+ ```
48
+ /
49
+ / Require the block that sets @ as the operator.
50
+ ```opts :(document_opts) +operator_@
51
+ divider4_collapsible: false
52
+ heading1_center: false
53
+ heading2_center: false
54
+ heading3_center: false
55
+ menu_final_divider:
56
+ menu_for_saved_lines: false
57
+ menu_initial_divider:
58
+ menu_vars_set_format:
59
+ screen_width: 64
60
+ table_center: false
61
+ ```
@@ -1,4 +1,5 @@
1
1
  / All lines of an indented block must have equal indents.
2
+ / The block is indented with 2 spaces.
2
3
  ```vars
3
4
  Species: Pongo tapanuliensis
4
5
  Genus: Pongo
@@ -0,0 +1,123 @@
1
+ # Menu pagination indent
2
+
3
+ | Option| Value
4
+ | -| -
5
+ | select_page_height| &{select_page_height}
6
+ | screen_width| &{screen_width}
7
+
8
+ / An Opts block
9
+ ::: Indented with 2 spaces
10
+ ```opts
11
+ option1: 1
12
+ option2: 2
13
+ option3: 3
14
+ option4: 4
15
+ ```
16
+ ::: Indented with 4 spaces
17
+ ```opts
18
+ option1: 1
19
+ option2: 2
20
+ option3: 3
21
+ option4: 4
22
+ ```
23
+ ::: Indented with 1 tab
24
+ ```opts
25
+ option1: 1
26
+ option2: 2
27
+ option3: 3
28
+ option4: 4
29
+ ```
30
+
31
+ / A shell block
32
+ ::: Indented with 2 spaces
33
+ ```
34
+ : 1
35
+ : 2
36
+ : 3
37
+ : 4
38
+ ```
39
+ ::: Indented with 4 spaces
40
+ ```
41
+ : 1
42
+ : 2
43
+ : 3
44
+ : 4
45
+ ```
46
+ ::: Indented with 1 tab
47
+ ```
48
+ : 1
49
+ : 2
50
+ : 3
51
+ : 4
52
+ ```
53
+
54
+ | Variable| Value
55
+ | -| -
56
+ | VARIABLE| ${VARIABLE}
57
+
58
+ / An UX block
59
+ ::: Indented with 2 spaces
60
+ ```ux
61
+ init: false
62
+ echo:
63
+ VARIABLE1: 1
64
+ VARIABLE2: 2
65
+ VARIABLE3: 3
66
+ VARIABLE4: 4
67
+ name: VARIABLE1
68
+ ```
69
+ ::: Indented with 4 spaces
70
+ ```ux
71
+ init: false
72
+ echo:
73
+ VARIABLE1: 1
74
+ VARIABLE2: 2
75
+ VARIABLE3: 3
76
+ VARIABLE4: 4
77
+ name: VARIABLE1
78
+ ```
79
+ ::: Indented with 1 tab
80
+ ```ux
81
+ init: false
82
+ echo:
83
+ VARIABLE1: 1
84
+ VARIABLE2: 2
85
+ VARIABLE3: 3
86
+ VARIABLE4: 4
87
+ name: VARIABLE1
88
+ ```
89
+
90
+
91
+ | Variable| Value
92
+ | -| -
93
+ | VARIABLE1| ${VARIABLE1}
94
+ | VARIABLE2| ${VARIABLE2}
95
+
96
+ / A VARS block
97
+ ::: Indented with 2 spaces
98
+ ```vars
99
+ VARIABLE1: 1
100
+ VARIABLE2: 2
101
+ VARIABLE3: 3
102
+ VARIABLE4: 4
103
+ ```
104
+ ::: Indented with 4 spaces
105
+ ```vars
106
+ VARIABLE1: 1
107
+ VARIABLE2: 2
108
+ VARIABLE3: 3
109
+ VARIABLE4: 4
110
+ ```
111
+ ::: Indented with 1 tab
112
+ ```vars
113
+ VARIABLE1: 1
114
+ VARIABLE2: 2
115
+ VARIABLE3: 3
116
+ VARIABLE4: 4
117
+ ```
118
+
119
+ @import bats-document-configuration.md
120
+ ```opts :(document_opts)
121
+ screen_width: 48
122
+ select_page_height: 12
123
+ ```
@@ -0,0 +1,111 @@
1
+ # Menu pagination
2
+
3
+ ::: ˆ
4
+ MDE detects the screen's dimensions: height (lines) and width (characters)
5
+
6
+ | Option| Value
7
+ | -| -
8
+ | select_page_height| &{select_page_height}
9
+ | screen_width| &{screen_width}
10
+
11
+ Normal document text is displayed as disabled menu lines. The width of these lines is limited according to the screen's width.
12
+
13
+ ::: ˆ
14
+ / A sequence of text blocks
15
+ : 1
16
+ : 2
17
+ : 3
18
+ : 4
19
+ : 5
20
+ : 6
21
+ : 7
22
+ : 8
23
+ : 9
24
+ : 10
25
+ : 11
26
+ : 12
27
+
28
+ ::: ˆ
29
+ / A shell block
30
+ ```
31
+ : 1
32
+ : 2
33
+ : 3
34
+ : 4
35
+ : 5
36
+ : 6
37
+ : 7
38
+ : 8
39
+ : 9
40
+ : 10
41
+ : 11
42
+ : 12
43
+ ```
44
+ ::: ˆ
45
+ / An Opts block
46
+ ```opts
47
+ option1: 1
48
+ option2: 2
49
+ option3: 3
50
+ option4: 4
51
+ option5: 5
52
+ option6: 6
53
+ option7: 7
54
+ option8: 8
55
+ option9: 9
56
+ option10: 10
57
+ option11: 11
58
+ option12: 12
59
+ ```
60
+ ::: ˆ
61
+
62
+ | Variable| Value
63
+ | -| -
64
+ | VARIABLE1| ${VARIABLE1}
65
+ | VARIABLE2| ${VARIABLE2}
66
+
67
+ / A Vars block
68
+ ```vars
69
+ VARIABLE1: 1
70
+ VARIABLE2: 2
71
+ VARIABLE3: 3
72
+ VARIABLE4: 4
73
+ VARIABLE5: 5
74
+ VARIABLE6: 6
75
+ VARIABLE7: 7
76
+ VARIABLE8: 8
77
+ VARIABLE9: 9
78
+ VARIABLE10: 10
79
+ VARIABLE11: 11
80
+ VARIABLE12: 12
81
+ ```
82
+ ::: ˆ
83
+
84
+ | Variable| Value
85
+ | -| -
86
+ | VARIABLE| ${VARIABLE}
87
+
88
+ / An UX block
89
+ ```ux
90
+ init: false
91
+ echo:
92
+ VARIABLE1: 1
93
+ VARIABLE2: 2
94
+ VARIABLE3: 3
95
+ VARIABLE4: 4
96
+ VARIABLE5: 5
97
+ VARIABLE6: 6
98
+ VARIABLE7: 7
99
+ VARIABLE8: 8
100
+ VARIABLE9: 9
101
+ VARIABLE10: 10
102
+ VARIABLE11: 11
103
+ VARIABLE12: 12
104
+ name: VARIABLE1
105
+ ```
106
+ ::: ˆ
107
+ @import bats-document-configuration.md
108
+ ```opts :(document_opts)
109
+ screen_width: 48
110
+ select_page_height: 12
111
+ ```
@@ -0,0 +1,10 @@
1
+
2
+ | Option| Description| Value Length| Value| Default
3
+ | -| -| -| -| -
4
+ | screen_width| &{screen_width.description}| &{screen_width.length}| &{screen_width}| &{screen_width.default}
5
+ | table_center| &{table_center.description}| &{table_center.length}| &{table_center}| &{table_center.default}
6
+ @import bats-document-configuration.md
7
+ ```opts :(document_opts)
8
+ screen_width: 64
9
+ table_center: false
10
+ ```
@@ -116,6 +116,8 @@ class AnsiFormatter
116
116
  # @param default [String] Default color method to use if color_sym is not found in @options.
117
117
  # @return [String] The string with the applied color method.
118
118
  def string_send_color(string, color_sym, default: 'plain')
119
+ return string.to_s unless @options.fetch(:ansi_formatter_color, true)
120
+
119
121
  color_method = @options.fetch(color_sym, default).to_sym
120
122
  AnsiString.new(string.to_s).send(color_method)
121
123
  end