markdown_exec 2.0.7 → 2.0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -4
- data/bin/tab_completion.sh +2 -2
- data/lib/hash_delegator.rb +31 -6
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/menu.src.yml +7 -0
- data/lib/menu.yml +6 -1
- data/lib/resize_terminal.rb +215 -0
- data/lib/saved_assets.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf7b742cc128a608c349ed6ff8b9f921b2e400acb269c4aba3f24d72f43cf007
|
4
|
+
data.tar.gz: cb0c023316b682f309313167a6900d037df036fa48e451b2dd781d40fed35215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa191e7433c5dcb5c514894cfdf4bbc3c60b15c416aa7693374eafb40ad39cfeff46bcaa23eed470d8ca67804adc209b4ab6f744d62c8b3f6c4a2f336e43e0f2
|
7
|
+
data.tar.gz: 260e03667d03854c4d628465d346a1a53029cab8ea1df2614f3fa500df194adc373687e9e096735ed01c41a0bd968f2788a8a60a853c06e9d0ef540409326ab6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [2.0.8] - 2024-06-05
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Option to automatically resize the menu.
|
8
|
+
Detect the maximum supported screen dimensions.
|
9
|
+
Resize the terminal to the maximum dimensions.
|
10
|
+
Every time the menu is displayed, format it to the terminal dimensions.
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Remove "$" from saved file names to simplify handling.
|
15
|
+
|
3
16
|
## [2.0.7] - 2024-06-04
|
4
17
|
|
5
18
|
### Added
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -89,6 +89,7 @@ task :minitest do
|
|
89
89
|
'./lib/object_present.rb',
|
90
90
|
'./lib/option_value.rb',
|
91
91
|
'./lib/regexp.rb',
|
92
|
+
'./lib/resize_terminal.rb',
|
92
93
|
'./lib/saved_assets.rb',
|
93
94
|
'./lib/saved_files_matcher.rb'
|
94
95
|
]
|
@@ -133,10 +134,7 @@ task :update_menu_yml do
|
|
133
134
|
}
|
134
135
|
)
|
135
136
|
|
136
|
-
File.write(MENU_YML,
|
137
|
-
"# #{MarkdownExec::APP_NAME} - #{MarkdownExec::APP_DESC} " \
|
138
|
-
"(#{MarkdownExec::VERSION})\n" +
|
139
|
-
menu_options.to_yaml)
|
137
|
+
File.write(MENU_YML, menu_options.to_yaml)
|
140
138
|
puts `stat #{MENU_YML}`
|
141
139
|
end
|
142
140
|
|
data/bin/tab_completion.sh
CHANGED
@@ -13,7 +13,7 @@ __filedirs_all()
|
|
13
13
|
}
|
14
14
|
|
15
15
|
_mde_echo_version() {
|
16
|
-
echo "2.0.
|
16
|
+
echo "2.0.8.1"
|
17
17
|
}
|
18
18
|
|
19
19
|
_mde() {
|
@@ -178,4 +178,4 @@ _mde() {
|
|
178
178
|
|
179
179
|
complete -o filenames -o nospace -F _mde mde
|
180
180
|
# _mde_echo_version
|
181
|
-
# echo "Updated: 2024-06-
|
181
|
+
# echo "Updated: 2024-06-06 01:08:57 UTC"
|
data/lib/hash_delegator.rb
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
require 'clipboard'
|
7
7
|
require 'English'
|
8
8
|
require 'fileutils'
|
9
|
+
require 'io/console'
|
9
10
|
require 'open3'
|
10
11
|
require 'optparse'
|
11
12
|
require 'ostruct'
|
@@ -31,6 +32,7 @@ require_relative 'hash'
|
|
31
32
|
require_relative 'link_history'
|
32
33
|
require_relative 'mdoc'
|
33
34
|
require_relative 'regexp'
|
35
|
+
require_relative 'resize_terminal'
|
34
36
|
require_relative 'std_out_err_logger'
|
35
37
|
require_relative 'string_util'
|
36
38
|
|
@@ -2485,14 +2487,37 @@ module MarkdownExec
|
|
2485
2487
|
))
|
2486
2488
|
end
|
2487
2489
|
|
2490
|
+
# Registers console attributes by modifying the options hash.
|
2491
|
+
# This method handles terminal resizing and adjusts the console dimensions
|
2492
|
+
# and pagination settings based on the current terminal size.
|
2493
|
+
#
|
2494
|
+
# @param opts [Hash] a hash containing various options for the console settings.
|
2495
|
+
# - :console_width [Integer, nil] The width of the console. If not provided or if the terminal is resized, it will be set to the current console width.
|
2496
|
+
# - :console_height [Integer, nil] The height of the console. If not provided or if the terminal is resized, it will be set to the current console height.
|
2497
|
+
# - :console_winsize [Array<Integer>, nil] The dimensions of the console [height, width]. If not provided or if the terminal is resized, it will be set to the current console dimensions.
|
2498
|
+
# - :select_page_height [Integer, nil] The height of the page for selection. If not provided or if not positive, it will be set to the maximum of (console height - 3) or 4.
|
2499
|
+
# - :per_page [Integer, nil] The number of items per page. If :select_page_height is not provided or if not positive, it will be set to the maximum of (console height - 3) or 4.
|
2500
|
+
#
|
2501
|
+
# @raise [StandardError] If an error occurs during the process, it will be caught and handled by calling HashDelegator.error_handler with 'register_console_attributes' and { abort: true }.
|
2502
|
+
#
|
2503
|
+
# @example
|
2504
|
+
# opts = { console_width: nil, console_height: nil, select_page_height: nil }
|
2505
|
+
# register_console_attributes(opts)
|
2506
|
+
# # opts will be updated with the current console dimensions and pagination settings.
|
2488
2507
|
def register_console_attributes(opts)
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2508
|
+
begin
|
2509
|
+
if (resized = @delegate_object[:menu_resize_terminal])
|
2510
|
+
resize_terminal
|
2511
|
+
end
|
2512
|
+
|
2513
|
+
if resized || !opts[:console_width]
|
2514
|
+
opts[:console_height], opts[:console_width] = opts[:console_winsize] = IO.console.winsize
|
2515
|
+
end
|
2516
|
+
|
2517
|
+
opts[:per_page] = opts[:select_page_height] = [opts[:console_height] - 3, 4].max unless opts[:select_page_height]&.positive?
|
2518
|
+
rescue StandardError
|
2519
|
+
HashDelegator.error_handler('register_console_attributes', { abort: true })
|
2492
2520
|
end
|
2493
|
-
opts[:per_page] = opts[:select_page_height] = [opts[:console_height] - 3, 4].max unless opts[:select_page_height]&.positive?
|
2494
|
-
rescue StandardError
|
2495
|
-
HashDelegator.error_handler('register_console_attributes', { abort: true })
|
2496
2521
|
end
|
2497
2522
|
|
2498
2523
|
# Check if the delegate object responds to a given method.
|
data/lib/menu.src.yml
CHANGED
@@ -727,6 +727,13 @@
|
|
727
727
|
:opt_name: menu_persist_block_name
|
728
728
|
:procname: val_as_str
|
729
729
|
|
730
|
+
- :arg_name: BOOL
|
731
|
+
:default: true
|
732
|
+
:description: Resize terminal when displaying menu.
|
733
|
+
:env_var: MDE_MENU_RESIZE_TERMINAL
|
734
|
+
:opt_name: menu_resize_terminal
|
735
|
+
:procname: val_as_bool
|
736
|
+
|
730
737
|
- :default: fg_rgbh_ff_ff_ff
|
731
738
|
:description: Color of menu task
|
732
739
|
:env_var: MDE_MENU_TASK_COLOR
|
data/lib/menu.yml
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# MDE - Markdown Executor (2.0.7)
|
2
1
|
---
|
3
2
|
- :description: Show current configuration values
|
4
3
|
:procname: show_config
|
@@ -609,6 +608,12 @@
|
|
609
608
|
:env_var: MDE_MENU_PERSIST_BLOCK_NAME
|
610
609
|
:opt_name: menu_persist_block_name
|
611
610
|
:procname: val_as_str
|
611
|
+
- :arg_name: BOOL
|
612
|
+
:default: true
|
613
|
+
:description: Resize terminal when displaying menu.
|
614
|
+
:env_var: MDE_MENU_RESIZE_TERMINAL
|
615
|
+
:opt_name: menu_resize_terminal
|
616
|
+
:procname: val_as_bool
|
612
617
|
- :default: fg_rgbh_ff_ff_ff
|
613
618
|
:description: Color of menu task
|
614
619
|
:env_var: MDE_MENU_TASK_COLOR
|
@@ -0,0 +1,215 @@
|
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
require 'io/console'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
# This function attempts to resize the terminal to its maximum supported size.
|
9
|
+
# It checks if the script is running in an interactive terminal with no arguments.
|
10
|
+
# If so, it sends escape sequences to query the terminal size and reads the response.
|
11
|
+
# It then compares the current terminal size with the calculated size and adjusts if necessary.
|
12
|
+
# If the terminal emulator is unsupported, it prints an error message.
|
13
|
+
def resize_terminal(show_dims: false, show_rectangle: false)
|
14
|
+
# Check if running in an interactive terminal and no arguments are provided
|
15
|
+
if $stdin.tty?
|
16
|
+
begin
|
17
|
+
# Save the current state and send the escape sequence to get the cursor position
|
18
|
+
print "\e7\e[r\e[999;999H\e[6n\e8"
|
19
|
+
$stdout.flush
|
20
|
+
|
21
|
+
# Read the response from the terminal
|
22
|
+
response = String.new
|
23
|
+
Timeout.timeout(5) do
|
24
|
+
loop do
|
25
|
+
char = $stdin.getch
|
26
|
+
response << char
|
27
|
+
break if response.include?('R')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if response.empty?
|
32
|
+
warn "Error: No response received from terminal. Response: #{response.inspect}"
|
33
|
+
return 1
|
34
|
+
end
|
35
|
+
|
36
|
+
# Match the response to extract the terminal dimensions
|
37
|
+
match_data = response.match(/\[(\d+);(\d+)R/)
|
38
|
+
unless match_data
|
39
|
+
warn "Error: Failed to match terminal response pattern. Response: #{response.inspect}"
|
40
|
+
return 1
|
41
|
+
end
|
42
|
+
|
43
|
+
calculated_rows, calculated_columns = match_data.captures.map(&:to_i)
|
44
|
+
|
45
|
+
if ENV['COLUMNS'].to_i == calculated_columns && ENV['LINES'].to_i == calculated_rows
|
46
|
+
puts "#{ENV.fetch('TERM', nil)} #{calculated_columns}x#{calculated_rows}"
|
47
|
+
elsif calculated_columns.positive? && calculated_rows.positive?
|
48
|
+
warn "#{ENV.fetch('COLUMNS', nil)}x#{ENV.fetch('LINES', nil)} -> #{calculated_columns}x#{calculated_rows}" if show_dims
|
49
|
+
system("stty cols #{calculated_columns} rows #{calculated_rows}")
|
50
|
+
else
|
51
|
+
warn "Error: Calculated terminal size is invalid. Columns: #{calculated_columns}, Rows: #{calculated_rows}"
|
52
|
+
return 1
|
53
|
+
end
|
54
|
+
|
55
|
+
# Display a text rectangle if the option is enabled
|
56
|
+
display_terminal_rectangle(calculated_columns, calculated_rows) if show_rectangle
|
57
|
+
rescue Timeout::Error
|
58
|
+
warn 'Error: Timeout while reading terminal response. Unsupported terminal emulator.'
|
59
|
+
1
|
60
|
+
rescue StandardError => err
|
61
|
+
warn "Error: #{err.message}. Unsupported terminal emulator."
|
62
|
+
1
|
63
|
+
end
|
64
|
+
else
|
65
|
+
warn 'Usage: resize_terminal'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This function draws a rectangle of the given width and height
|
70
|
+
# with stars on the edges and empty space inside.
|
71
|
+
def display_terminal_rectangle(width, height)
|
72
|
+
puts '*' * width
|
73
|
+
(height - 2).times { puts "*#{' ' * (width - 2)}*" }
|
74
|
+
puts '*' * width
|
75
|
+
end
|
76
|
+
|
77
|
+
# resize_terminal(show_rectangle: true) if __FILE__ == $PROGRAM_NAME
|
78
|
+
return if __FILE__ != $PROGRAM_NAME
|
79
|
+
|
80
|
+
require 'minitest/autorun'
|
81
|
+
|
82
|
+
class ResizeTerminalTest < Minitest::Test
|
83
|
+
def setup
|
84
|
+
# Backup original ARGV and environment variables
|
85
|
+
@original_argv = ARGV.dup
|
86
|
+
@original_columns = ENV.fetch('COLUMNS', nil)
|
87
|
+
@original_lines = ENV.fetch('LINES', nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
# Restore original ARGV and environment variables
|
92
|
+
ARGV.replace(@original_argv)
|
93
|
+
ENV['COLUMNS'] = @original_columns
|
94
|
+
ENV['LINES'] = @original_lines
|
95
|
+
end
|
96
|
+
|
97
|
+
# def test_resize_terminal_successful
|
98
|
+
# # Simulate interactive terminal
|
99
|
+
# $stdin.stub(:tty?, true) do
|
100
|
+
# ARGV.replace([])
|
101
|
+
# ENV['COLUMNS'] = '80'
|
102
|
+
# ENV['LINES'] = '24'
|
103
|
+
# response = "\e[999;999H\e[6n\e[24;80R"
|
104
|
+
# $stdin.stub(:getch, -> { response.slice!(0) || '' }) do
|
105
|
+
# assert_output(nil, /24x80/) do
|
106
|
+
# resize_terminal
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
def test_resize_terminal_successful
|
112
|
+
# Simulate interactive terminal
|
113
|
+
$stdin.stub(:tty?, true) do
|
114
|
+
ARGV.replace([])
|
115
|
+
columns = 40 + (2 * rand(10))
|
116
|
+
ENV['COLUMNS'] = columns.to_s
|
117
|
+
ENV['LINES'] = '24'
|
118
|
+
response = "\e[999;999H\e[6n\e[24;#{columns}R".dup
|
119
|
+
$stdin.stub(:getch, -> { response.slice!(0) || '' }) do
|
120
|
+
assert_output("\e7\e[r\e[999;999H\e[6n\e8xterm-256color #{columns}x24\n") do
|
121
|
+
# assert_output('', '') do
|
122
|
+
resize_terminal
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_resize_terminal_no_response
|
129
|
+
# Simulate interactive terminal with no response
|
130
|
+
$stdin.stub(:tty?, true) do
|
131
|
+
ARGV.replace([])
|
132
|
+
$stdin.stub(:getch, -> { '' }) do
|
133
|
+
# assert_output(nil, /Error: No response received from terminal/) do
|
134
|
+
assert_output(nil, "Error: Timeout while reading terminal response. Unsupported terminal emulator.\n") do
|
135
|
+
assert_equal 1, resize_terminal
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_resize_terminal_invalid_response
|
142
|
+
# Simulate interactive terminal with invalid response
|
143
|
+
$stdin.stub(:tty?, true) do
|
144
|
+
ARGV.replace([])
|
145
|
+
response = "\e[999;999H\e[6n\e[InvalidResponse".dup
|
146
|
+
$stdin.stub(:getch, -> { response.slice!(0) || '' }) do
|
147
|
+
assert_output(nil, /Error: Failed to match terminal response pattern/) do
|
148
|
+
assert_equal 1, resize_terminal
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_resize_terminal_timeout
|
155
|
+
# Simulate interactive terminal with timeout
|
156
|
+
$stdin.stub(:tty?, true) do
|
157
|
+
ARGV.replace([])
|
158
|
+
Timeout.stub(:timeout, ->(_) { raise Timeout::Error }) do
|
159
|
+
assert_output(nil, /Error: Timeout while reading terminal response/) do
|
160
|
+
assert_equal 1, resize_terminal
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_resize_terminal_non_interactive
|
167
|
+
# Simulate non-interactive terminal
|
168
|
+
$stdin.stub(:tty?, false) do
|
169
|
+
assert_output(nil, /Usage: resize_terminal/) do
|
170
|
+
resize_terminal
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# def test_resize_terminal_display_rectangle
|
176
|
+
# # Simulate interactive terminal with rectangle display
|
177
|
+
# $stdin.stub(:tty?, true) do
|
178
|
+
# ARGV.replace([])
|
179
|
+
# ENV['COLUMNS'] = '80'
|
180
|
+
# ENV['LINES'] = '24'
|
181
|
+
# response = "\e[999;999H\e[6n\e[24;80R".dup
|
182
|
+
# $stdin.stub(:getch, -> { response.slice!(0) || '' }) do
|
183
|
+
# expected_output = "\e7\e[r\e[999;999H\e[6n\e8"
|
184
|
+
# # expected_output = <<-RECTANGLE
|
185
|
+
# # ********************************************************************************
|
186
|
+
# # * *
|
187
|
+
# # * *
|
188
|
+
# # * *
|
189
|
+
# # * *
|
190
|
+
# # * *
|
191
|
+
# # * *
|
192
|
+
# # * *
|
193
|
+
# # * *
|
194
|
+
# # * *
|
195
|
+
# # * *
|
196
|
+
# # * *
|
197
|
+
# # * *
|
198
|
+
# # * *
|
199
|
+
# # * *
|
200
|
+
# # * *
|
201
|
+
# # * *
|
202
|
+
# # * *
|
203
|
+
# # * *
|
204
|
+
# # * *
|
205
|
+
# # * *
|
206
|
+
# # * *
|
207
|
+
# # ********************************************************************************
|
208
|
+
# # RECTANGLE
|
209
|
+
# assert_output(expected_output.strip) do
|
210
|
+
# resize_terminal(show_rectangle: true)
|
211
|
+
# end
|
212
|
+
# end
|
213
|
+
# end
|
214
|
+
# end
|
215
|
+
end
|
data/lib/saved_assets.rb
CHANGED
@@ -12,7 +12,7 @@ module MarkdownExec
|
|
12
12
|
# method derives a name for stdout redirection.
|
13
13
|
#
|
14
14
|
class SavedAsset
|
15
|
-
FNR11 = %r{[
|
15
|
+
FNR11 = %r{[^!#%&()\+,\-0-9=A-Z_a-z~]}.freeze
|
16
16
|
# / !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
17
17
|
FNR12 = '_'
|
18
18
|
DEFAULT_FTIME = '%F-%H-%M-%S'
|
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: 2.0.
|
4
|
+
version: 2.0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/object_present.rb
|
174
174
|
- lib/option_value.rb
|
175
175
|
- lib/regexp.rb
|
176
|
+
- lib/resize_terminal.rb
|
176
177
|
- lib/rspec_helpers.rb
|
177
178
|
- lib/saved_assets.rb
|
178
179
|
- lib/saved_files_matcher.rb
|