mysh 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -55
- data/lib/mysh.rb +2 -1
- data/lib/mysh/exceptions.rb +0 -3
- data/lib/mysh/globalize.rb +0 -18
- data/lib/mysh/internal.rb +0 -1
- data/lib/mysh/internal/actions/command_line.rb +1 -1
- data/lib/mysh/internal/actions/gls.rb +2 -2
- data/lib/mysh/internal/actions/help.rb +1 -1
- data/lib/mysh/internal/actions/help/h_o_h.txt +1 -1
- data/lib/mysh/internal/actions/help/help.txt +1 -1
- data/lib/mysh/internal/actions/help/show.txt +1 -1
- data/lib/mysh/internal/actions/help/usage.txt +1 -1
- data/lib/mysh/internal/actions/mls.rb +1 -1
- data/lib/mysh/internal/actions/show/env.rb +3 -2
- data/lib/mysh/internal/actions/show/gem.rb +16 -11
- data/lib/mysh/internal/actions/show/ruby.rb +2 -2
- data/lib/mysh/internal/actions/show/term.rb +2 -1
- data/lib/mysh/internal/actions/vars.rb +1 -1
- data/lib/mysh/process.rb +1 -1
- data/lib/mysh/version.rb +1 -1
- data/mysh.gemspec +3 -0
- data/samples/show.txt +1 -1
- data/tests/my_shell_tests.rb +0 -46
- metadata +44 -10
- data/lib/mysh/internal/format.rb +0 -9
- data/lib/mysh/internal/format/array.rb +0 -77
- data/lib/mysh/internal/format/bullets.rb +0 -58
- data/lib/mysh/internal/format/columns.rb +0 -117
- data/lib/mysh/internal/format/nil.rb +0 -13
- data/lib/mysh/internal/format/object.rb +0 -18
- data/lib/mysh/internal/format/string.rb +0 -60
- data/lib/mysh/output_pager.rb +0 -106
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc2ce1a31750c110022b543778cb28e70b4f2456
|
4
|
+
data.tar.gz: e5f15032fa38956e7f06be1f8cc92ce5de7feba9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4484f3c07c6ac22a7ccba4b29dd87116926f0731d4b9c54bd54ecefcefcea8676c8fe111d7f7c98be1331ed7ea17798af7d3566ef064d94d879fae89619001fa
|
7
|
+
data.tar.gz: 7c4a82903c595abd907bd02285051bbb0805481fa54b65f3993359fea6c24376d6f58646f3400ddc9aab36c636fde249d9265c94960339c365954bdad01f9f42
|
data/README.md
CHANGED
@@ -292,65 +292,20 @@ are:
|
|
292
292
|
|
293
293
|
* String#to_host_spec - given a string with a file path/name value, express that
|
294
294
|
string in a manner compatible with the current operating environment.
|
295
|
-
* Array#format_mysh_columns - take an array and convert it to a string with nice
|
296
|
-
regular columns.
|
297
|
-
* Array#puts_mysh_columns - as above, but print the string.
|
298
|
-
* Array#format_mysh_bullets - take an array and convert it to a string with nice
|
299
|
-
bullet points. The appearance of each point depends on its structure. See below:
|
300
|
-
* Array#puts_mysh_bullets - as above, but print the string.
|
301
|
-
|
302
|
-
This must all be confusing. Some examples may help:
|
303
|
-
|
304
|
-
```
|
305
|
-
mysh>=puts "lib/mysh/expression/lineage.rb".to_host_spec
|
306
|
-
lib\mysh\expression\lineage.rb
|
307
|
-
|
308
|
-
mysh>=(1..100).to_a.puts_mysh_columns
|
309
|
-
1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97
|
310
|
-
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98
|
311
|
-
3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99
|
312
|
-
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100
|
313
|
-
|
314
|
-
mysh>=["foo", "bar "*30, "some "*25, "stuff"].puts_mysh_bullets
|
315
|
-
* foo
|
316
|
-
* bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
|
317
|
-
bar bar bar bar bar bar bar bar bar bar bar
|
318
|
-
* some some some some some some some some some some some some some some some
|
319
|
-
some some some some some some some some some some
|
320
|
-
* stuff
|
321
|
-
|
322
|
-
mysh>=[["foo", "bar "*20], ["sna", "foo young "*10 ] ].puts_mysh_bullets
|
323
|
-
foo bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
|
324
|
-
bar bar
|
325
|
-
sna foo young foo young foo young foo young foo young foo young foo young foo
|
326
|
-
young foo young foo young
|
327
|
-
|
328
|
-
mysh>=[["foo", 1,2,3]].puts_mysh_bullets
|
329
|
-
foo 1
|
330
|
-
2
|
331
|
-
3
|
332
|
-
|
333
|
-
mysh>=[[(1..100).to_a]].puts_mysh_bullets
|
334
|
-
* 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97
|
335
|
-
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98
|
336
|
-
3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99
|
337
|
-
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100
|
338
|
-
|
339
|
-
mysh>=[["foo", (1..100).to_a], ["baz", "yes"]].puts_mysh_bullets
|
340
|
-
foo 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97
|
341
|
-
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98
|
342
|
-
3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99
|
343
|
-
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100
|
344
|
-
baz yes
|
345
295
|
|
346
|
-
|
296
|
+
###### Formatting
|
297
|
+
|
298
|
+
To assist in creating nicely formatted output, the mysh employs the
|
299
|
+
format_output gem. Please refer to that gem for more information.
|
347
300
|
|
348
301
|
###### Page Pause
|
349
302
|
|
350
303
|
Some commands can generate very lengthy output that can scroll off the top of
|
351
|
-
the screen.
|
352
|
-
|
353
|
-
|
304
|
+
the screen. To handle this, mysh automatically inserts pauses once per screen.
|
305
|
+
Now this capability has been moved into the pause_output gem, but since it has
|
306
|
+
an impact on the user "experience" it is discussed here. When a pause point is
|
307
|
+
reached, mysh displays a prompt and waits for the users to press a key that
|
308
|
+
will determine the action to take. The default pause prompt message is:
|
354
309
|
|
355
310
|
Press a key, a space, or q:
|
356
311
|
|
@@ -996,7 +951,6 @@ application gem uses the following exception classes:
|
|
996
951
|
StandardError # From Ruby.
|
997
952
|
MyshException # The abstract base exception for mysh.
|
998
953
|
MyshExit # Exit the current mysh processing loop.
|
999
|
-
MyshStopOutput # Stop further output from a verbose command.
|
1000
954
|
MyshUsage # Internal: Used by the --help options.
|
1001
955
|
|
1002
956
|
|
data/lib/mysh.rb
CHANGED
@@ -4,11 +4,12 @@
|
|
4
4
|
|
5
5
|
require 'English'
|
6
6
|
require 'in_array'
|
7
|
+
require 'pause_output'
|
8
|
+
require 'format_output'
|
7
9
|
|
8
10
|
require_relative 'mysh/exceptions'
|
9
11
|
require_relative 'mysh/binding_wrapper'
|
10
12
|
require_relative 'mysh/input_wrapper'
|
11
|
-
require_relative 'mysh/output_pager'
|
12
13
|
require_relative 'mysh/user_input'
|
13
14
|
require_relative 'mysh/expression'
|
14
15
|
require_relative 'mysh/internal'
|
data/lib/mysh/exceptions.rb
CHANGED
@@ -6,8 +6,5 @@ class MyshException < StandardError; end
|
|
6
6
|
# Exit the current mysh processing loop.
|
7
7
|
class MyshExit < MyshException; end
|
8
8
|
|
9
|
-
# Stop further output from a verbose command.
|
10
|
-
class MyshStopOutput < MyshException; end
|
11
|
-
|
12
9
|
# Display usage info and exit.
|
13
10
|
class MyshUsage < MyshException; end
|
data/lib/mysh/globalize.rb
CHANGED
@@ -15,24 +15,6 @@ class Object
|
|
15
15
|
Mysh.try_execute_command(str)
|
16
16
|
end
|
17
17
|
|
18
|
-
# Execute a block with page paused output.
|
19
|
-
def more
|
20
|
-
saved = $stdout
|
21
|
-
|
22
|
-
if MNV[:page_pause].extract_boolean
|
23
|
-
$stdout = OutputPager.new if (outer = $stdout.equal?($mysh_out))
|
24
|
-
end
|
25
|
-
|
26
|
-
yield
|
27
|
-
|
28
|
-
rescue MyshStopOutput
|
29
|
-
raise unless outer
|
30
|
-
return
|
31
|
-
|
32
|
-
ensure
|
33
|
-
$stdout = saved
|
34
|
-
end
|
35
|
-
|
36
18
|
# Unwrap one mysh layer.
|
37
19
|
def cancel
|
38
20
|
raise MyshExit
|
data/lib/mysh/internal.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative 'internal/actions/actions_path'
|
|
4
4
|
require_relative 'internal/action'
|
5
5
|
require_relative 'internal/action_pool'
|
6
6
|
require_relative 'internal/manage'
|
7
|
-
require_relative 'internal/format'
|
8
7
|
require_relative 'internal/to_file_spec'
|
9
8
|
|
10
9
|
#Load up the internal actions!
|
@@ -45,7 +45,7 @@ module Mysh
|
|
45
45
|
|
46
46
|
#The brief gem list report.
|
47
47
|
def short_report
|
48
|
-
puts @specs.map {|spec| spec.name}.
|
48
|
+
puts @specs.map {|spec| spec.name}.format_output_columns, ""
|
49
49
|
end
|
50
50
|
|
51
51
|
#The long-winded gem list report.
|
@@ -54,7 +54,7 @@ module Mysh
|
|
54
54
|
buffer.concat(info(spec))
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
report.puts_format_output_bullets
|
58
58
|
end
|
59
59
|
|
60
60
|
#Get detailed information on a gem specification.
|
@@ -11,7 +11,7 @@ In mysh, commands fall into one of three broad categories. There are:
|
|
11
11
|
2) Internal mysh commands are processed within mysh itself. The following set
|
12
12
|
of commands are supported:
|
13
13
|
|
14
|
-
{{ Mysh::COMMANDS.actions_info.
|
14
|
+
{{ Mysh::COMMANDS.actions_info.format_output_bullets }}
|
15
15
|
|
16
16
|
3) All other commands are executed by the system using the standard shell or
|
17
17
|
the appropriate ruby interpreter. If the command has a '.rb' extension, it
|
@@ -9,10 +9,11 @@ module Mysh
|
|
9
9
|
# Execute the @env shell command.
|
10
10
|
def process_command(_args)
|
11
11
|
print WORKING unless @ran_once
|
12
|
+
Gem.refresh
|
12
13
|
|
13
14
|
puts "Key mysh environment information.", "",
|
14
|
-
info.
|
15
|
-
path.
|
15
|
+
info.format_output_bullets, "",
|
16
|
+
path.format_output_bullets, ""
|
16
17
|
|
17
18
|
@ran_once = true
|
18
19
|
end
|
@@ -3,12 +3,13 @@
|
|
3
3
|
# Get help on the gem environment.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
# Get
|
6
|
+
# Get information on the gem environment.
|
7
7
|
class GemInfoCommand < Action
|
8
8
|
|
9
9
|
#Execute the @gem shell command.
|
10
10
|
def process_command(input)
|
11
11
|
print WORKING unless @ran_once
|
12
|
+
Gem.refresh
|
12
13
|
|
13
14
|
args = input.cooked_body.split(" ")[1..-1]
|
14
15
|
|
@@ -26,8 +27,8 @@ module Mysh
|
|
26
27
|
# A general info request
|
27
28
|
def general
|
28
29
|
puts "Key gem system information.", "",
|
29
|
-
info.
|
30
|
-
path.
|
30
|
+
info.format_output_bullets, "",
|
31
|
+
path.format_output_bullets, ""
|
31
32
|
end
|
32
33
|
|
33
34
|
# Get the info
|
@@ -62,27 +63,31 @@ module Mysh
|
|
62
63
|
def specific(args)
|
63
64
|
details = []
|
64
65
|
|
65
|
-
args.each do |
|
66
|
-
version_list = Gem::Specification.find_all_by_name(
|
67
|
-
.map{|
|
66
|
+
args.each do |gem_name|
|
67
|
+
version_list = Gem::Specification.find_all_by_name(gem_name)
|
68
|
+
.map {|spec| spec.version.to_s}
|
68
69
|
.join(", ")
|
69
|
-
details << [
|
70
|
+
details << [gem_name, version_list]
|
70
71
|
|
71
|
-
latest = insouciant {latest_version_for(
|
72
|
+
latest = insouciant {latest_version_for(gem_name).to_s}
|
72
73
|
details << ["latest", latest]
|
73
74
|
details << [" ", " "]
|
74
75
|
end
|
75
76
|
|
76
77
|
puts "Info on specified gems.", "",
|
77
|
-
details.
|
78
|
+
details.format_output_bullets
|
78
79
|
end
|
79
80
|
|
80
81
|
# Get the latest version for the named gem. Patched code.
|
81
82
|
def latest_version_for(name)
|
82
83
|
dependency = Gem::Dependency.new(name)
|
83
84
|
fetcher = Gem::SpecFetcher.fetcher
|
84
|
-
|
85
|
-
|
85
|
+
if specs = fetcher.spec_for_dependency(dependency)[0][-1]
|
86
|
+
spec = specs[0]
|
87
|
+
spec && spec.version
|
88
|
+
else
|
89
|
+
"<Not found in repository>"
|
90
|
+
end
|
86
91
|
end
|
87
92
|
|
88
93
|
end
|
@@ -9,8 +9,8 @@ module Mysh
|
|
9
9
|
#Execute the @ruby shell command.
|
10
10
|
def process_command(_input)
|
11
11
|
puts "Key ruby environment information.", ""
|
12
|
-
puts info.
|
13
|
-
path.
|
12
|
+
puts info.format_output_bullets, "",
|
13
|
+
path.format_output_bullets, ""
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -9,9 +9,10 @@ module Mysh
|
|
9
9
|
#Execute the @term shell command.
|
10
10
|
def process_command(_args)
|
11
11
|
print WORKING unless @ran_once
|
12
|
+
Gem.refresh
|
12
13
|
|
13
14
|
puts "Key term information.", "",
|
14
|
-
info.
|
15
|
+
info.format_output_bullets, ""
|
15
16
|
|
16
17
|
@ran_once = true
|
17
18
|
end
|
data/lib/mysh/process.rb
CHANGED
data/lib/mysh/version.rb
CHANGED
data/mysh.gemspec
CHANGED
@@ -31,6 +31,9 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'reek', "~> 5.0.2"
|
32
32
|
|
33
33
|
spec.add_runtime_dependency 'mini_readline', "~> 0.9.0"
|
34
|
+
spec.add_runtime_dependency 'mini_term', "~> 0.1.0"
|
35
|
+
spec.add_runtime_dependency 'pause_output', "~> 0.1.0"
|
36
|
+
spec.add_runtime_dependency 'format_output', "~> 0.1.0"
|
34
37
|
spec.add_runtime_dependency 'vls', "~> 0.4.1"
|
35
38
|
spec.add_runtime_dependency 'in_array', "~> 0.1.8"
|
36
39
|
end
|
data/samples/show.txt
CHANGED
data/tests/my_shell_tests.rb
CHANGED
@@ -73,52 +73,6 @@ class MyShellTester < Minitest::Test
|
|
73
73
|
(4).lineage)
|
74
74
|
end
|
75
75
|
|
76
|
-
def test_some_formatting
|
77
|
-
assert_equal("1 4\n2 5\n3 ", [1,2,3,4,5].format_mysh_columns(5))
|
78
|
-
assert_equal(["1 4", "2 5", "3 "], [1,2,3,4,5].format_description(5))
|
79
|
-
|
80
|
-
assert_equal(["1 2", "3 4", "5"], "1 2 3 4 5".format_description(5))
|
81
|
-
|
82
|
-
assert_equal([], [].format_description(5))
|
83
|
-
assert_equal([], nil.format_description(5))
|
84
|
-
|
85
|
-
result =
|
86
|
-
"1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 \n" +
|
87
|
-
"2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 \n" +
|
88
|
-
"3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 \n" +
|
89
|
-
"4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100"
|
90
|
-
|
91
|
-
assert_equal(result, (1..100).to_a.format_mysh_columns)
|
92
|
-
|
93
|
-
data =
|
94
|
-
[["key_largo", "/long_folder_name_one/long_folder_name_two/long_folder_name_three/fine_descriptive_name"],
|
95
|
-
["key_west", "Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. "],
|
96
|
-
["counting", Array.new(100) {|i| i} ],
|
97
|
-
["pie", Math::PI]
|
98
|
-
]
|
99
|
-
|
100
|
-
result =
|
101
|
-
"key_largo /long_folder_name_one/long_folder_name_two/long_folder_name_three/fin\n" +
|
102
|
-
" e_descriptive_name\n" +
|
103
|
-
"key_west Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper\n" +
|
104
|
-
" ubi sub ubi.\n" +
|
105
|
-
"counting 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95\n" +
|
106
|
-
" 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96\n" +
|
107
|
-
" 2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 82 87 92 97\n" +
|
108
|
-
" 3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98\n" +
|
109
|
-
" 4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99\n" +
|
110
|
-
"pie 3.141592653589793"
|
111
|
-
|
112
|
-
assert_equal(result, data.format_mysh_bullets)
|
113
|
-
|
114
|
-
assert_equal("", [].format_mysh_bullets)
|
115
|
-
|
116
|
-
data = ["apple", "cherry", "victory"]
|
117
|
-
result = "* apple\n* cherry\n* victory"
|
118
|
-
assert_equal(result, data.format_mysh_bullets)
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
76
|
def test_mysh_variables
|
123
77
|
assert_equal("", MNV[:test])
|
124
78
|
assert_equal("", MNV.get_source(:test))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,6 +108,48 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.9.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mini_term
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.1.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.1.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pause_output
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.1.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: format_output
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.1.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.1.0
|
111
153
|
- !ruby/object:Gem::Dependency
|
112
154
|
name: vls
|
113
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,16 +257,8 @@ files:
|
|
215
257
|
- lib/mysh/internal/actions/show/term.rb
|
216
258
|
- lib/mysh/internal/actions/type.rb
|
217
259
|
- lib/mysh/internal/actions/vars.rb
|
218
|
-
- lib/mysh/internal/format.rb
|
219
|
-
- lib/mysh/internal/format/array.rb
|
220
|
-
- lib/mysh/internal/format/bullets.rb
|
221
|
-
- lib/mysh/internal/format/columns.rb
|
222
|
-
- lib/mysh/internal/format/nil.rb
|
223
|
-
- lib/mysh/internal/format/object.rb
|
224
|
-
- lib/mysh/internal/format/string.rb
|
225
260
|
- lib/mysh/internal/manage.rb
|
226
261
|
- lib/mysh/internal/to_file_spec.rb
|
227
|
-
- lib/mysh/output_pager.rb
|
228
262
|
- lib/mysh/pre_processor.rb
|
229
263
|
- lib/mysh/process.rb
|
230
264
|
- lib/mysh/quick.rb
|
data/lib/mysh/internal/format.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
#* internal/format/array.rb - Support for displaying an array formatted neatly.
|
4
|
-
class Array
|
5
|
-
|
6
|
-
# Columns ========================================================
|
7
|
-
|
8
|
-
#Print out the array with efficient columns.
|
9
|
-
def puts_mysh_columns(page_width = MiniTerm.width)
|
10
|
-
puts format_mysh_columns(page_width)
|
11
|
-
end
|
12
|
-
|
13
|
-
#Convert the array to strings with efficient columns.
|
14
|
-
#<br>Returns
|
15
|
-
#* An array of strings.
|
16
|
-
#<br>Endemic Code Smells
|
17
|
-
#* :reek:FeatureEnvy -- false positive.
|
18
|
-
def raw_mysh_columns(page_width)
|
19
|
-
builder = Mysh::ColumnizedPage.new(page_width)
|
20
|
-
|
21
|
-
each {|item| builder.add(item)}
|
22
|
-
|
23
|
-
builder.render
|
24
|
-
end
|
25
|
-
|
26
|
-
alias :format_description :raw_mysh_columns
|
27
|
-
|
28
|
-
#Convert the array to strings with efficient columns.
|
29
|
-
#<br>Returns
|
30
|
-
#* A string.
|
31
|
-
#<br>Endemic Code Smells
|
32
|
-
#* :reek:FeatureEnvy -- false positive.
|
33
|
-
def format_mysh_columns(page_width = MiniTerm.width)
|
34
|
-
raw_mysh_columns(page_width).join("\n")
|
35
|
-
end
|
36
|
-
|
37
|
-
#Get the widest element of an array.
|
38
|
-
#<br>Returns
|
39
|
-
#* The width of the widest string in the array.
|
40
|
-
def mysh_column_width
|
41
|
-
max_by {|item| item.length}.length
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
# Bullets ========================================================
|
46
|
-
|
47
|
-
#Print out the array as bullet points.
|
48
|
-
def puts_mysh_bullets(page_width = MiniTerm.width)
|
49
|
-
puts format_mysh_bullets(page_width)
|
50
|
-
end
|
51
|
-
|
52
|
-
#Convert the array to strings with bullet points.
|
53
|
-
#<br>Returns
|
54
|
-
#* A string.
|
55
|
-
#<br>Endemic Code Smells
|
56
|
-
#* :reek:FeatureEnvy -- false positive.
|
57
|
-
def format_mysh_bullets(page_width = MiniTerm.width)
|
58
|
-
return "" if empty?
|
59
|
-
|
60
|
-
builder = Mysh::BulletPoints.new(page_width)
|
61
|
-
|
62
|
-
each {|pair| builder.add(*pair.prepare_bullet_data)}
|
63
|
-
|
64
|
-
builder.render.join("\n")
|
65
|
-
end
|
66
|
-
|
67
|
-
#Get data ready for being in a bullet point.
|
68
|
-
def prepare_bullet_data
|
69
|
-
if length < 2
|
70
|
-
["*", self[0]]
|
71
|
-
else
|
72
|
-
self
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
#* mysh/internal/format/bullets.rb - Print out bullet points.
|
4
|
-
module Mysh
|
5
|
-
|
6
|
-
#* mysh/internal/format/bullets.rb - A class to display data in bullet points.
|
7
|
-
class BulletPoints
|
8
|
-
|
9
|
-
#Prepare a blank slate.
|
10
|
-
def initialize(page_width)
|
11
|
-
@page_width = page_width
|
12
|
-
@bullet_data = []
|
13
|
-
@key_length = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
#Add items to these bullet points.
|
17
|
-
def add(bullet, *items)
|
18
|
-
items.each do |item|
|
19
|
-
@bullet_data << [bullet.to_s, item]
|
20
|
-
bullet = ""
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
#Render the bullet points as an array of strings.
|
25
|
-
def render
|
26
|
-
@key_length, results = get_key_length, []
|
27
|
-
|
28
|
-
@bullet_data.each do |key, item|
|
29
|
-
results.concat(render_bullet(key, item))
|
30
|
-
end
|
31
|
-
|
32
|
-
@bullet_data = []
|
33
|
-
results
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
#Allowing for a trailing space, how large is the largest bullet?
|
39
|
-
def get_key_length
|
40
|
-
(@bullet_data.max_by {|line| line[0].length})[0].length + 1
|
41
|
-
end
|
42
|
-
|
43
|
-
#Render one bullet point.
|
44
|
-
def render_bullet(key, item)
|
45
|
-
result = []
|
46
|
-
|
47
|
-
item.format_description(@page_width - @key_length - 1).each do |desc_line|
|
48
|
-
result << key.ljust(@key_length) + desc_line
|
49
|
-
key = ""
|
50
|
-
end
|
51
|
-
|
52
|
-
result
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
#* mysh/internal/format/columns.rb - Print out data in neat columns.
|
4
|
-
module Mysh
|
5
|
-
|
6
|
-
#* mysh/internal/format/columns.rb - A class to display data in columns.
|
7
|
-
class ColumnizedPage
|
8
|
-
#Prepare a blank page.
|
9
|
-
def initialize(page_width)
|
10
|
-
@page_width = page_width
|
11
|
-
@page_data = []
|
12
|
-
end
|
13
|
-
|
14
|
-
#Add an item to this page.
|
15
|
-
#<br>Returns
|
16
|
-
#* The number if items that did not fit in the page.
|
17
|
-
def add(raw_item)
|
18
|
-
item = raw_item.to_s
|
19
|
-
fail "Item too large to fit." unless item.length < @page_width
|
20
|
-
|
21
|
-
if (column = find_next_column)
|
22
|
-
@page_data[column] << item
|
23
|
-
else
|
24
|
-
@page_data << [item]
|
25
|
-
end
|
26
|
-
|
27
|
-
adjust_configuration
|
28
|
-
end
|
29
|
-
|
30
|
-
#Render the page as an array of strings.
|
31
|
-
def render
|
32
|
-
results, column_widths = [], get_column_widths
|
33
|
-
|
34
|
-
rows.times { |row_index| results << render_row(row_index, column_widths)}
|
35
|
-
|
36
|
-
@page_data.clear
|
37
|
-
results
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
#Get the widths of all columns
|
43
|
-
def get_column_widths
|
44
|
-
@page_data.map {|column| column.mysh_column_width}
|
45
|
-
end
|
46
|
-
|
47
|
-
#Render a single row of data.
|
48
|
-
def render_row(row_index, widths)
|
49
|
-
@page_data.each_with_index.map do |column, index|
|
50
|
-
column[row_index].to_s.ljust(widths[index])
|
51
|
-
end.join(" ")
|
52
|
-
end
|
53
|
-
|
54
|
-
#Make sure the page fits within its boundaries.
|
55
|
-
def adjust_configuration
|
56
|
-
while total_width >= @page_width
|
57
|
-
add_a_row
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
#Add a row to the page, moving items as needed.
|
62
|
-
def add_a_row
|
63
|
-
new_rows = rows + 1
|
64
|
-
pool, @page_data = @page_data.flatten, []
|
65
|
-
|
66
|
-
until pool.empty?
|
67
|
-
@page_data << pool.shift(new_rows)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
#Compute the total width of all of the columns.
|
72
|
-
#<br>Returns
|
73
|
-
#* The sum of the widths of the widest items of each column plus a space
|
74
|
-
# between each of those columns.
|
75
|
-
def total_width
|
76
|
-
if empty?
|
77
|
-
0
|
78
|
-
else
|
79
|
-
#The starting point, @page_data.length-1, represents the spaces needed
|
80
|
-
#between the columns. So N columns means N-1 spaces.
|
81
|
-
@page_data.inject(@page_data.length-1) do |sum, column|
|
82
|
-
sum + column.mysh_column_width
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
#Does the data fit on the page?
|
88
|
-
def fits?
|
89
|
-
total_width < @page_width
|
90
|
-
end
|
91
|
-
|
92
|
-
#How many rows are currently in this page?
|
93
|
-
def rows
|
94
|
-
empty? ? 0 : @page_data[0].length
|
95
|
-
end
|
96
|
-
|
97
|
-
#Is this page empty?
|
98
|
-
def empty?
|
99
|
-
@page_data.empty?
|
100
|
-
end
|
101
|
-
|
102
|
-
#Which column will receive the next item?
|
103
|
-
#<br>Returns
|
104
|
-
#* The index of the first non-filled column or nil if none found.
|
105
|
-
def find_next_column
|
106
|
-
(1...(@page_data.length)).each do |index|
|
107
|
-
if @page_data[index].length < @page_data[index-1].length
|
108
|
-
return index
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
nil
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
#* internal/format/object.rb - Support for displaying data formatted neatly.
|
4
|
-
class Object
|
5
|
-
|
6
|
-
#Create a bullet point description from this object.
|
7
|
-
def format_description(max_width)
|
8
|
-
self.to_s.format_description(max_width)
|
9
|
-
end
|
10
|
-
|
11
|
-
#Get data ready for being in a bullet point.
|
12
|
-
def prepare_bullet_data
|
13
|
-
["*", self]
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
#* internal/format/string.rb - Support for displaying data formatted neatly.
|
4
|
-
class String
|
5
|
-
|
6
|
-
#Create a bullet point description from this string.
|
7
|
-
#<br>Returns
|
8
|
-
#* An array of strings.
|
9
|
-
def format_description(max_width)
|
10
|
-
do_format_description(split(' ').each, max_width)
|
11
|
-
end
|
12
|
-
|
13
|
-
#Do the formatting legwork.
|
14
|
-
#<br>Returns
|
15
|
-
#* An array of strings.
|
16
|
-
def do_format_description(input, max_width)
|
17
|
-
buffer, build, empty = [], "", false
|
18
|
-
|
19
|
-
loop do #Grab "words" of input, splitting off lines as needed.
|
20
|
-
empty = (build = build.split_if_over(input.next, max_width, buffer)
|
21
|
-
.split_if_huge(max_width, buffer)).empty?
|
22
|
-
end
|
23
|
-
|
24
|
-
unless empty
|
25
|
-
buffer << build
|
26
|
-
end
|
27
|
-
|
28
|
-
buffer
|
29
|
-
end
|
30
|
-
|
31
|
-
#Split if adding a word goes over a little.
|
32
|
-
#<br>Returns
|
33
|
-
#* A string.
|
34
|
-
def split_if_over(word, max_width, buffer)
|
35
|
-
word.prepend(" ") unless empty? #Add a space except for the first word.
|
36
|
-
|
37
|
-
word_len = word.length
|
38
|
-
|
39
|
-
if (length + word_len) >= max_width && word_len < max_width
|
40
|
-
buffer << self #Line done, add to buffer.
|
41
|
-
word.lstrip #Start of a new line, remove the leading space.
|
42
|
-
else
|
43
|
-
self + word
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#Split up a overlong blob of text.
|
48
|
-
#<br>Returns
|
49
|
-
#* A string.
|
50
|
-
def split_if_huge(max_width, buffer)
|
51
|
-
|
52
|
-
#Slice away any excess text into lines in the buffer.
|
53
|
-
while length >= max_width
|
54
|
-
buffer << slice!(0, max_width)
|
55
|
-
end
|
56
|
-
|
57
|
-
self
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
data/lib/mysh/output_pager.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
$mysh_out = $stdout # Keep a copy of the real $stdout.
|
4
|
-
|
5
|
-
# A class to manage paged output.
|
6
|
-
class OutputPager
|
7
|
-
|
8
|
-
# Set up the initial values.
|
9
|
-
def initialize
|
10
|
-
@lines = 0
|
11
|
-
@chars = 0
|
12
|
-
end
|
13
|
-
|
14
|
-
# Write out a general string with page pauses.
|
15
|
-
def write(str)
|
16
|
-
while !str.empty?
|
17
|
-
pre,mid,str = str.partition("\n")
|
18
|
-
write_str(pre) unless pre.empty?
|
19
|
-
writeln unless mid.empty?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Write out an object as a string.
|
24
|
-
def <<(obj)
|
25
|
-
write(obj.to_s)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# Write out a simple string with no embedded new-lines.
|
31
|
-
def write_str(str)
|
32
|
-
loop do
|
33
|
-
len = str.length
|
34
|
-
|
35
|
-
if @chars + len < chars_per_line
|
36
|
-
$mysh_out.write(str)
|
37
|
-
@chars += len
|
38
|
-
return
|
39
|
-
else
|
40
|
-
tilt = chars_per_line - @chars
|
41
|
-
$mysh_out.write(str[0, tilt])
|
42
|
-
count_lines
|
43
|
-
|
44
|
-
str = (str[tilt..-1])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Write out a new-line.
|
50
|
-
def writeln
|
51
|
-
$mysh_out.write("\n")
|
52
|
-
count_lines
|
53
|
-
end
|
54
|
-
|
55
|
-
# A new line is out, count it!
|
56
|
-
def count_lines
|
57
|
-
@chars = 0
|
58
|
-
@lines += 1
|
59
|
-
|
60
|
-
if @lines >= (lines_per_page - 1)
|
61
|
-
case pause.downcase
|
62
|
-
when " "
|
63
|
-
@lines -= 1
|
64
|
-
when "q"
|
65
|
-
raise MyshStopOutput
|
66
|
-
else
|
67
|
-
@lines = 0
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Pause waiting for the user.
|
73
|
-
def pause
|
74
|
-
msg = pause_message
|
75
|
-
$mysh_out.write(msg)
|
76
|
-
|
77
|
-
MiniTerm.raw do |term|
|
78
|
-
result = term.get_raw_char
|
79
|
-
term.flush
|
80
|
-
result
|
81
|
-
end
|
82
|
-
|
83
|
-
ensure
|
84
|
-
$mysh_out.write("\r" + " " * msg.length + "\r")
|
85
|
-
end
|
86
|
-
|
87
|
-
# How many lines fit on a page?
|
88
|
-
def lines_per_page
|
89
|
-
result = MNV[:page_height].to_i
|
90
|
-
result = MiniTerm.height if result < 2
|
91
|
-
result
|
92
|
-
end
|
93
|
-
|
94
|
-
# How many characters fit on a line?
|
95
|
-
def chars_per_line
|
96
|
-
result = MNV[:page_width].to_i
|
97
|
-
result = MiniTerm.width if result < 20
|
98
|
-
result
|
99
|
-
end
|
100
|
-
|
101
|
-
# Get the text of the pause message.
|
102
|
-
def pause_message
|
103
|
-
MNV.key?(:page_msg) ? MNV[:page_msg] : "Press enter, space or q:"
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|