markdown_exec 2.0.5 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb96e0d1b92398066dedcaf7017ee6d7deea37ef9ba19fa089de6c4e5aebf27d
4
- data.tar.gz: f8b8ffcb0f30fbec9321a4a9f14ae7568b16b31e40833046fb1ab16ddcf28c1b
3
+ metadata.gz: af8a53f03e48c890798b520b84bd0357ccef4f31d93b97cc7cc8b4b72ca1a035
4
+ data.tar.gz: cd5983d2ff18ee8e2a29da6bea364c03bdaf6a43871d45b16483a8996d129894
5
5
  SHA512:
6
- metadata.gz: 96a95683c52b4a7546d2cb1ce399dd6c278a7783305d70e12a0a8ac5c70df739705a0ccb06a14f8861ca5794193f201ab185cd7e994e6fcc4eef56a0f038504e
7
- data.tar.gz: 51991405ec7dae5c31dcc1ff6294172279d046975647ca8676b4e28918d2ff954a19e671bae4cc7381963816f8b0826b4723c4bf61fb6a35fd8fce25e808ed63
6
+ metadata.gz: 47e4e75e5a4e473ab9e9726cb7774aec95eb4a26d1d48035e3f6a69df0162c6b004fa625f5ae9f3c973bb25f732c9e938c0008dd07abb759f3211258d943fcc8
7
+ data.tar.gz: 306fc1218c64d57b1ca82191060298f87f9ae996e43f278cd72144fa3b839e3e4e4b8d3168f34c2fca4bd1ba9fa8ca1ab0a42659980d115b2d3293edc5e75238
data/.rubocop.yml CHANGED
@@ -15,8 +15,8 @@ Layout/LineContinuationLeadingSpace:
15
15
 
16
16
  Layout/LineLength: # 2024-01-21 temp disable
17
17
  Enabled: false
18
- Max: 96
19
- Max: 120
18
+ # Max: 96
19
+ # Max: 120
20
20
 
21
21
  Lint/Debugger:
22
22
  Enabled: false
@@ -24,6 +24,9 @@ Lint/Debugger:
24
24
  Lint/SafeNavigationChain:
25
25
  Enabled: false
26
26
 
27
+ Lint/UnusedMethodArgument:
28
+ Enabled: false
29
+
27
30
  Metrics/AbcSize:
28
31
  Enabled: false
29
32
 
@@ -45,6 +48,9 @@ Metrics/CyclomaticComplexity:
45
48
  Metrics/MethodLength:
46
49
  Enabled: false
47
50
 
51
+ Metrics/ParameterLists:
52
+ Enabled: false
53
+
48
54
  Metrics/PerceivedComplexity:
49
55
  Enabled: false
50
56
 
@@ -54,9 +60,15 @@ Minitest/MultipleAssertions:
54
60
  Naming/RescuedExceptionsVariableName:
55
61
  PreferredName: err
56
62
 
63
+ Security/Eval:
64
+ Enabled: false
65
+
57
66
  Security/YAMLLoad:
58
67
  Enabled: false
59
68
 
69
+ Style/ClassVars:
70
+ Enabled: false
71
+
60
72
  Style/CommentedKeyword:
61
73
  Enabled: false
62
74
 
@@ -87,6 +99,9 @@ Style/MultilineBlockChain:
87
99
  Style/OpenStructUse:
88
100
  Enabled: false
89
101
 
102
+ Style/OptionalBooleanParameter:
103
+ Enabled: false
104
+
90
105
  Style/PerlBackrefs: # Prefer ::Regexp.last_match.post_match over $'.
91
106
  Enabled: false
92
107
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.7] - 2024-06-04
4
+
5
+ ### Added
6
+
7
+ - Color names that set foreground and background color.
8
+ Similar to the existing foreground-only color names.
9
+ The background colors follow the foreground color values in the name.
10
+ Two names, to accept values as decimal and hex.
11
+ - Example document for line wrapping.
12
+ - Menu entry to execute shell commands.
13
+ - Option to control menu entry for shell commands.
14
+ - Recognition of nicknames in command line processing.
15
+ - Trap user interrupting executing scripts.
16
+
17
+ ### Changed
18
+
19
+ - Do not decorate indentations.
20
+ - Line-wrap and center headings.
21
+ Headings are now centered, the text is case-folded and the color
22
+ (foreground and background) is according to the level.
23
+ Centering is based on the console width detected.
24
+ - Line-wrap normal document text and format headings.
25
+ - Parse lines into indentation, text, and trailing whitespace.
26
+ - Update nicknames example to exercise hidden blocks from the command line.
27
+ - The optional prompt to exit after execution is now more frequent.
28
+ - Set characters used in saved file names
29
+
30
+ ## [2.0.6] - 2024-05-28
31
+
32
+ ### Added
33
+
34
+ - Color-coding to folder names in the menu following a keyword search.
35
+ Implement color-coding for folder names. Each folder name is assigned a color based on the folder name to highlight repetitive folder structures.
36
+
37
+ - Load-code option to read one or more files into inherited lines.
38
+
39
+ - Automatic Load, Edit, Save, and View menu entries to manage inherited lines.
40
+ The value of `document_saved_lines_glob` is displayed above the menu items, if any.
41
+ The Load menu item appears when one or more files match the glob.
42
+ The Edit menu item appears when one or more lines have been inherited.
43
+ The Save menu item appears when one or more lines have been inherited.
44
+ The View menu item appears when one or more lines have been inherited.
45
+
46
+ ### Changed
47
+
48
+ - Fix block name processing for blocks with no name.
49
+ Demo in examples/block_names.md loads content of examples/load1.sh.
50
+
3
51
  ## [2.0.5] - 2024-04-24
4
52
 
5
53
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.0.5)
4
+ markdown_exec (2.0.7)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "2.0.5"
16
+ echo "2.0.7"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -36,15 +36,15 @@ _mde() {
36
36
 
37
37
  -d) COMPREPLY="0"; return 0 ;;
38
38
 
39
- --dump-dump-delegate-object) COMPREPLY="0"; return 0 ;;
39
+ --dump-delegate-object) COMPREPLY="0"; return 0 ;;
40
40
 
41
41
  --dump-blocks-in-file) COMPREPLY="0"; return 0 ;;
42
42
 
43
- --dump-dump-inherited-block_names) COMPREPLY="0"; return 0 ;;
43
+ --dump-inherited-block_names) COMPREPLY="0"; return 0 ;;
44
44
 
45
- --dump-dump-inherited-dependencies) COMPREPLY="0"; return 0 ;;
45
+ --dump-inherited-dependencies) COMPREPLY="0"; return 0 ;;
46
46
 
47
- --dump-dump-inherited-lines) COMPREPLY="0"; return 0 ;;
47
+ --dump-inherited-lines) COMPREPLY="0"; return 0 ;;
48
48
 
49
49
  --dump-menu-blocks) COMPREPLY="0"; return 0 ;;
50
50
 
@@ -66,12 +66,12 @@ _mde() {
66
66
 
67
67
  --list-count) COMPREPLY="32"; return 0 ;;
68
68
 
69
+ --load-code) COMPREPLY="''"; return 0 ;;
70
+
69
71
  --open) COMPREPLY="''"; return 0 ;;
70
72
 
71
73
  -o) COMPREPLY="''"; return 0 ;;
72
74
 
73
- --output-execution-summary) COMPREPLY="0"; return 0 ;;
74
-
75
75
  --output-script) COMPREPLY="0"; return 0 ;;
76
76
 
77
77
  --output-stdout) COMPREPLY="1"; return 0 ;;
@@ -80,14 +80,6 @@ _mde() {
80
80
 
81
81
  -p) COMPREPLY="."; return 0 ;;
82
82
 
83
- --save-executed-script) COMPREPLY="0"; return 0 ;;
84
-
85
- --save-execution-output) COMPREPLY="0"; return 0 ;;
86
-
87
- --saved-script-folder) COMPREPLY="logs"; return 0 ;;
88
-
89
- --saved-stdout-folder) COMPREPLY="logs"; return 0 ;;
90
-
91
83
  --user-must-approve) COMPREPLY="0"; return 0 ;;
92
84
 
93
85
  -q) COMPREPLY="0"; return 0 ;;
@@ -102,7 +94,7 @@ _mde() {
102
94
  # present matching option names
103
95
  #
104
96
  if [[ ${cur} == -* ]] ; then
105
- opts=("--block-name" "--config" "--debug" "--dump-dump-delegate-object" "--dump-blocks-in-file" "--dump-dump-inherited-block_names" "--dump-dump-inherited-dependencies" "--dump-dump-inherited-lines" "--dump-menu-blocks" "--dump-selected-block" "--exit" "--filename" "--find" "--find-path" "--help" "--how" "--list-blocks" "--list-count" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--open" "--output-execution-summary" "--output-script" "--output-stdout" "--path" "--pwd" "--run-last-script" "--save-executed-script" "--save-execution-output" "--saved-script-folder" "--saved-stdout-folder" "--select-recent-output" "--select-recent-script" "--tab-completions" "--user-must-approve" "--version" "--display-level")
97
+ opts=("--block-name" "--config" "--debug" "--dump-delegate-object" "--dump-blocks-in-file" "--dump-inherited-block_names" "--dump-inherited-dependencies" "--dump-inherited-lines" "--dump-menu-blocks" "--dump-selected-block" "--exit" "--filename" "--find" "--find-path" "--help" "--how" "--list-blocks" "--list-count" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--load-code" "--open" "--output-script" "--output-stdout" "--path" "--pwd" "--run-last-script" "--select-recent-output" "--select-recent-script" "--tab-completions" "--user-must-approve" "--version" "--display-level")
106
98
  COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
107
99
 
108
100
  return 0
@@ -125,15 +117,15 @@ _mde() {
125
117
 
126
118
  -d) COMPREPLY=".BOOL."; return 0 ;;
127
119
 
128
- --dump-dump-delegate-object) COMPREPLY=".BOOL."; return 0 ;;
120
+ --dump-delegate-object) COMPREPLY=".BOOL."; return 0 ;;
129
121
 
130
122
  --dump-blocks-in-file) COMPREPLY=".BOOL."; return 0 ;;
131
123
 
132
- --dump-dump-inherited-block_names) COMPREPLY=".BOOL."; return 0 ;;
124
+ --dump-inherited-block_names) COMPREPLY=".BOOL."; return 0 ;;
133
125
 
134
- --dump-dump-inherited-dependencies) COMPREPLY=".BOOL."; return 0 ;;
126
+ --dump-inherited-dependencies) COMPREPLY=".BOOL."; return 0 ;;
135
127
 
136
- --dump-dump-inherited-lines) COMPREPLY=".BOOL."; return 0 ;;
128
+ --dump-inherited-lines) COMPREPLY=".BOOL."; return 0 ;;
137
129
 
138
130
  --dump-menu-blocks) COMPREPLY=".BOOL."; return 0 ;;
139
131
 
@@ -155,12 +147,12 @@ _mde() {
155
147
 
156
148
  --list-count) COMPREPLY=".INT.1-."; return 0 ;;
157
149
 
150
+ --load-code) COMPREPLY=".PATH."; return 0 ;;
151
+
158
152
  --open) COMPREPLY=".OPEN."; return 0 ;;
159
153
 
160
154
  -o) COMPREPLY=".OPEN."; return 0 ;;
161
155
 
162
- --output-execution-summary) COMPREPLY=".BOOL."; return 0 ;;
163
-
164
156
  --output-script) COMPREPLY=".BOOL."; return 0 ;;
165
157
 
166
158
  --output-stdout) COMPREPLY=".BOOL."; return 0 ;;
@@ -169,14 +161,6 @@ _mde() {
169
161
 
170
162
  -p) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
171
163
 
172
- --save-executed-script) COMPREPLY=".BOOL."; return 0 ;;
173
-
174
- --save-execution-output) COMPREPLY=".BOOL."; return 0 ;;
175
-
176
- --saved-script-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
177
-
178
- --saved-stdout-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
179
-
180
164
  --user-must-approve) COMPREPLY=".BOOL."; return 0 ;;
181
165
 
182
166
  -q) COMPREPLY=".BOOL."; return 0 ;;
@@ -194,4 +178,4 @@ _mde() {
194
178
 
195
179
  complete -o filenames -o nospace -F _mde mde
196
180
  # _mde_echo_version
197
- # echo "Updated: 2024-04-26 15:37:23 UTC"
181
+ # echo "Updated: 2024-06-05 03:00:42 UTC"
@@ -0,0 +1,23 @@
1
+ Demonstrate display of block names and requiring blocks.
2
+
3
+ This block is listed by its name `A`.
4
+ It requires block `[C]`.
5
+ Executing it outputs `1`, `3`.
6
+ ```bash :A +[C]
7
+ echo "1"
8
+ ```
9
+
10
+ This block is listed according to its content `echo "2"`.
11
+ It requires blocks `A`, `[C]`.
12
+ Executing it outputs `1`, `2`, `3`.
13
+ It cannot be addressed/required.
14
+ ```bash +A
15
+ echo "2"
16
+ ```
17
+
18
+ This block is listed according to its content `echo "3"` and addressed by its nick name `[C]`.
19
+ It requires no blocks.
20
+ Executing it outputs `3`.
21
+ ```bash :[C]
22
+ echo "3"
23
+ ```
@@ -0,0 +1,9 @@
1
+ ```opts :(document_options)
2
+ pause_after_script_execution: false
3
+ ```
4
+ ```bash
5
+ tail -f ~/.bash_profile
6
+ ```
7
+ ```bash
8
+ tail -f ~/.profile
9
+ ```
@@ -0,0 +1,17 @@
1
+ # Demo wrapping long lines
2
+
3
+ MDE detects the screen's dimensions: height (lines) and width (characters)
4
+
5
+ If `select_page_height` is positive, the height of the MDE menu is fixed. Otherwise, the height is derived from the screen's height.
6
+
7
+ Normal document text is displayed as disabled menu lines. The width of these lines is limited according to the screen's width.
8
+
9
+ ::: Test Indented Lines
10
+
11
+ Indented with two spaces, this line should wrap in an aesthetically pleasing way. Indented with two spaces, this line should wrap in an aesthetically pleasing way.
12
+
13
+ Indented with a tab, this line should wrap in an aesthetically pleasing way. Indented with a tab, this line should wrap in an aesthetically pleasing way.
14
+
15
+ # Heading 1 - UPPER lower Mixed - Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega
16
+ ## Heading 2 - UPPER lower Mixed - Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega
17
+ ### Heading 3 - UPPER lower Mixed - Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega
data/examples/linked.md CHANGED
@@ -92,6 +92,14 @@ load: examples/load2.sh
92
92
  eval: true
93
93
  ```
94
94
 
95
+ ::: Load file into inherited lines and switch document
96
+ Load (do not evaluate) and append to inherited lines and switch document.
97
+ ```link :load_from_file_link_and_show
98
+ block: show_vars
99
+ file: examples/linked_show.md
100
+ load: examples/load1.sh
101
+ ```
102
+
95
103
  ::: Save and Load
96
104
  Save inherited lines to a file.
97
105
  ```link :save1
@@ -0,0 +1,7 @@
1
+ # Demo document linking
2
+
3
+ ::: Display variables set in the calling document
4
+ ```bash :show_vars
5
+ source bin/colorize_env_vars.sh
6
+ colorize_env_vars 'from linked.md load1.sh' var1 var2
7
+ ```
@@ -0,0 +1,10 @@
1
+ Demonstrate loading inherited code via the command line.
2
+
3
+ Run this command to display the inherited code.
4
+ `mde --load-code examples/load1.sh examples/load_code.md display_variables`
5
+
6
+ ```bash :display_variables
7
+ source bin/colorize_env_vars.sh
8
+ echo The current value of environment variables:
9
+ colorize_env_vars '' var1 var2
10
+ ```
data/examples/nickname.md CHANGED
@@ -1,26 +1,63 @@
1
1
  # Demo block nicknames
2
2
 
3
3
  ```opts :(document_options)
4
- save_executed_script: true
4
+ pause_after_script_execution: true
5
5
  ```
6
6
 
7
+ ## Blocks with no name
7
8
  ::: This block has no name.
8
9
  ::: The code block is displayed.
9
10
 
10
11
  ```bash
11
- echo Unnamed block
12
+ echo This block has no name.
12
13
  ```
13
14
 
14
- ::: These blocks use nicknames.
15
- ::: The code blocks are displayed.
16
- ::: The nicknames can be used for requiring blocks.
15
+ ## Blocks with nicknames
16
+ ::: The code block is displayed.
17
+ ::: The nickname can be used to require the block.
17
18
 
18
19
  ```bash :[A]
19
- echo From the required block 2
20
+ echo 'This block has a nickname: [A].'
21
+ echo The full block is displayed in the menu.
20
22
  ```
21
23
 
22
- ::: Execute this block that requires the block above.
23
-
24
+ ### Nicknames in documents
25
+ ::: Execute this block that requires the block above by its nickname.
24
26
  ```bash :[B] +[A]
25
- echo From the parent block 1
27
+ echo 'This block has a nickname: [B].'
28
+ echo 'This block requires block [A].'
29
+ ```
30
+
31
+ ### Nicknames from the command line
32
+ Block `[A]` is called from the command line.
33
+ ```bash
34
+ mde examples/nickname.md '[A]'
35
+ ```
36
+
37
+ ## Blocks with hidden names
38
+ ### There is a hidden block here.
39
+ ::: This block has a hidden name: (C).
40
+ ::: This block does not appear in the menu.
41
+ ::: This block requires the block above by its nickname.
42
+ ```bash :(C) +[A]
43
+ echo 'This block has a hidden name: (C).'
44
+ echo This block is hidden from the menu.
45
+ echo 'This block requires block [A].'
46
+ ```
47
+
48
+ ### Hidden names from the command line
49
+ Block `(C)` is called from the command line.
50
+ ```bash
51
+ mde examples/nickname.md '(C)'
52
+ ```
53
+
54
+ ### Block without a name
55
+ ::: This block does not have a name.
56
+ ::: It requires hidden block (D).
57
+ ```bash +(D)
58
+ echo "Block without a name"
59
+ ```
60
+ ::: This block has a hidden name: (D).
61
+ ```bash :(D)
62
+ echo "Block D"
26
63
  ```
@@ -0,0 +1,9 @@
1
+ # Demonstrate pause for user approval before returning to the menu
2
+ Controlled by option `pause_after_script_execution`.
3
+ ```opts :(document_options)
4
+ pause_after_script_execution: true
5
+ ```
6
+
7
+ ```bash
8
+ echo `date`
9
+ ```
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # encoding=utf-8
4
+
5
+ # A class that represents a color scheme based on configurable parameters
6
+ # that determine how the RGB values are calculated for a given string segment.
7
+ class ColorScheme
8
+ attr_accessor :base_red, :multiplier_red, :modulus_red,
9
+ :base_green, :multiplier_green, :modulus_green,
10
+ :base_blue, :multiplier_blue, :modulus_blue
11
+
12
+ # Initializes a new ColorScheme object with base values, multipliers, and moduli
13
+ # for the red, green, and blue components of an RGB color.
14
+ # @param [Integer] base_red Base red component value.
15
+ # @param [Integer] multiplier_red Multiplier for red component based on string hash.
16
+ # @param [Integer] modulus_red Modulus for calculating red component.
17
+ # @param [Integer] base_green Base green component value.
18
+ # @param [Integer] multiplier_green Multiplier for green component based on string hash.
19
+ # @param [Integer] modulus_green Modulus for calculating green component.
20
+ # @param [Integer] base_blue Base blue component value.
21
+ # @param [Integer] multiplier_blue Multiplier for blue component based on string hash.
22
+ # @param [Integer] modulus_blue Modulus for calculating blue component.
23
+ def initialize(base_red, multiplier_red, modulus_red,
24
+ base_green, multiplier_green, modulus_green,
25
+ base_blue, multiplier_blue, modulus_blue)
26
+ @base_red = base_red
27
+ @multiplier_red = multiplier_red
28
+ @modulus_red = modulus_red
29
+ @base_green = base_green
30
+ @multiplier_green = multiplier_green
31
+ @modulus_green = modulus_green
32
+ @base_blue = base_blue
33
+ @multiplier_blue = multiplier_blue
34
+ @modulus_blue = modulus_blue
35
+ end
36
+
37
+ # Calculates and returns the ANSI escape code for coloring a string segment
38
+ # based on its hash value.
39
+ # @param [String] segment The string segment to color.
40
+ # @return [String] ANSI escape code string with RGB color formatting.
41
+ def color_for(segment)
42
+ hash_value = segment.each_byte.reduce(0, :+)
43
+ red = @base_red + (@multiplier_red * (hash_value % @modulus_red))
44
+ green = @base_green + (@multiplier_green * (hash_value % @modulus_green))
45
+ blue = @base_blue + (@multiplier_blue * (hash_value % @modulus_blue))
46
+ "\e[38;2;#{red};#{green};#{blue}m#{segment}\e[0m"
47
+ end
48
+
49
+ # Applies color codes to each segment of a filesystem path, differentiating the
50
+ # final segment from others using a distinct color scheme.
51
+ # @param [String] path The filesystem path to colorize.
52
+ # @return [String] The colorized path.
53
+ def self.colorize_path(path)
54
+ segments = path.split('/')
55
+ segments.map.with_index do |segment, index|
56
+ color_scheme = if index == segments.size - 1
57
+ ColorScheme.new(192, 0, 1, 192, 0, 1, 192, 0, 1)
58
+ else
59
+ ColorScheme.new(32, 1, 192, 32, 1, 192, 255, 0, 1)
60
+ end
61
+
62
+ color_scheme.color_for(segment)
63
+ end.join('/')
64
+ end
65
+ end
data/lib/colorize.rb CHANGED
@@ -13,6 +13,11 @@ class String
13
13
  # @return [String] The formatted string.
14
14
  def method_missing(method_name, *args, &block)
15
15
  case method_name.to_s
16
+ when /^fg_bg_rgb_/
17
+ bytes = $'.split('_')
18
+ fg_bg_rgb_color(bytes[0..2].join(';'), bytes[3..5].join(';'))
19
+ when /^fg_bg_rgbh_/
20
+ hex_to_fg_bg_rgb($')
16
21
  when /^fg_rgb_/
17
22
  fg_rgb_color($'.gsub('_', ';'))
18
23
  when /^fg_rgbh_/
@@ -29,6 +34,14 @@ class String
29
34
  "\033[#{self}\033[0m"
30
35
  end
31
36
 
37
+ # Applies a 24-bit RGB foreground color to the string.
38
+ #
39
+ # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
40
+ # @return [String] The string with the applied RGB foreground color.
41
+ def fg_bg_rgb_color(fg_rgb, bg_rgb)
42
+ "38;2;#{fg_rgb}m\033[48;2;#{bg_rgb}m#{self}".ansi_control_sequence
43
+ end
44
+
32
45
  # Applies a 24-bit RGB foreground color to the string.
33
46
  #
34
47
  # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
@@ -37,6 +50,18 @@ class String
37
50
  "38;2;#{rgb}m#{self}".ansi_control_sequence
38
51
  end
39
52
 
53
+ # Converts hex color codes to RGB and applies them to the string.
54
+ #
55
+ # @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
56
+ # @return [String] The string with the applied RGB foreground color.
57
+ def hex_to_fg_bg_rgb(hex_str)
58
+ values = hex_str.split('_').map { |hex| hex.to_i(16).to_s }
59
+ fg_bg_rgb_color(
60
+ values[0..2].join(';'),
61
+ values[3..5].join(';')
62
+ )
63
+ end
64
+
40
65
  # Converts hex color codes to RGB and applies them to the string.
41
66
  #
42
67
  # @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
data/lib/constants.rb CHANGED
@@ -6,9 +6,9 @@
6
6
  require_relative 'block_types'
7
7
 
8
8
  class ExecutionStreams
9
- StdErr = :stderr
10
- StdIn = :stdin
11
- StdOut = :stdout
9
+ STD_ERR = :stderr
10
+ STD_IN = :stdin
11
+ STD_OUT = :stdout
12
12
  end
13
13
 
14
14
  IndexedLine = Struct.new(:index, :line) do
@@ -18,29 +18,24 @@ IndexedLine = Struct.new(:index, :line) do
18
18
  end
19
19
 
20
20
  class LinkKeys
21
- Block = 'block'
22
- Eval = 'eval'
23
- Exec = 'exec'
24
- File = 'file'
25
- Load = 'load'
26
- NextBlock = 'next_block'
27
- Return = 'return'
28
- Save = 'save'
29
- Vars = 'vars'
21
+ BLOCK = 'block'
22
+ EVAL = 'eval'
23
+ EXEC = 'exec'
24
+ FILE = 'file'
25
+ LOAD = 'load'
26
+ NEXT_BLOCK = 'next_block'
27
+ RETURN = 'return'
28
+ SAVE = 'save'
29
+ VARS = 'vars'
30
30
  end
31
31
 
32
32
  class LoadFile
33
- Load = true
34
- Reuse = false
33
+ LOAD = true
34
+ REUSE = false
35
35
  end
36
36
 
37
37
  LoadFileLinkState = Struct.new(:load_file, :link_state)
38
38
 
39
- class MenuControl
40
- Fresh = false
41
- Repeat = true
42
- end
43
-
44
39
  class MenuOptions
45
40
  YES = 1
46
41
  NO = 2
@@ -51,7 +46,12 @@ end
51
46
  class MenuState
52
47
  BACK = :back
53
48
  CONTINUE = :continue
49
+ EDIT = :edit
54
50
  EXIT = :exit
51
+ LOAD = :load
52
+ SAVE = :save
53
+ SHELL = :shell
54
+ VIEW = :view
55
55
  end
56
56
 
57
57
  # a struct to hold the data for a single line
data/lib/fcb.rb CHANGED
@@ -3,6 +3,21 @@
3
3
 
4
4
  # encoding=utf-8
5
5
 
6
+ class Hash
7
+ # block name in commands and documents
8
+ def pub_name
9
+ fetch(:nickname, nil) || fetch(:oname, nil)
10
+ end
11
+ end
12
+ # require 'ostruct'
13
+
14
+ # class BlkS < OpenStruct
15
+ # # Method to fetch the value associated with the attribute :nickname or :oname
16
+ # def pub_name
17
+ # self.nickname || self.oname
18
+ # end
19
+ # end
20
+
6
21
  module MarkdownExec
7
22
  class Error < StandardError; end
8
23