choosy 0.4.0 → 0.4.1
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.
- data/CHANGELOG.md +6 -0
- data/lib/VERSION.yml +1 -1
- data/lib/choosy/printing/base_printer.rb +17 -8
- data/lib/choosy/printing/help_printer.rb +5 -5
- data/lib/choosy/printing/manpage_printer.rb +5 -6
- data/spec/choosy/printing/help_printer_spec.rb +11 -3
- data/spec/choosy/printing/manpage_printer_spec.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/lib/VERSION.yml
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'choosy/errors'
|
2
2
|
require 'choosy/printing/terminal'
|
3
3
|
|
4
|
+
class String
|
5
|
+
def unformatted
|
6
|
+
gsub(/\e\[\d+m/, '').gsub(/\\f[IPB]/, '')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
module Choosy::Printing
|
5
11
|
class BasePrinter
|
6
12
|
include Terminal
|
@@ -98,9 +104,9 @@ module Choosy::Printing
|
|
98
104
|
|
99
105
|
def regular_option(option, value="")
|
100
106
|
if option.short_flag
|
101
|
-
value <<
|
107
|
+
value << highlight_begin
|
102
108
|
value << option.short_flag
|
103
|
-
value <<
|
109
|
+
value << highlight_end
|
104
110
|
if option.long_flag
|
105
111
|
value << ', '
|
106
112
|
end
|
@@ -109,7 +115,7 @@ module Choosy::Printing
|
|
109
115
|
end
|
110
116
|
|
111
117
|
if option.long_flag
|
112
|
-
value <<
|
118
|
+
value << highlight_begin
|
113
119
|
if option.negated?
|
114
120
|
value << '--['
|
115
121
|
value << option.negation
|
@@ -118,7 +124,7 @@ module Choosy::Printing
|
|
118
124
|
else
|
119
125
|
value << option.long_flag
|
120
126
|
end
|
121
|
-
value <<
|
127
|
+
value << highlight_end
|
122
128
|
end
|
123
129
|
|
124
130
|
if option.metaname
|
@@ -138,6 +144,7 @@ module Choosy::Printing
|
|
138
144
|
|
139
145
|
# doesn't indent the first line
|
140
146
|
def usage_wrapped(command, indent='', columns=80)
|
147
|
+
columns = (columns > 70) ? 70 : columns
|
141
148
|
lines = []
|
142
149
|
line = command_name(command)
|
143
150
|
starting_width = width = line.length + indent.length
|
@@ -190,11 +197,11 @@ module Choosy::Printing
|
|
190
197
|
end
|
191
198
|
end
|
192
199
|
|
193
|
-
def
|
200
|
+
def highlight_begin
|
194
201
|
''
|
195
202
|
end
|
196
203
|
|
197
|
-
def
|
204
|
+
def highlight_end
|
198
205
|
''
|
199
206
|
end
|
200
207
|
|
@@ -208,8 +215,9 @@ module Choosy::Printing
|
|
208
215
|
case item
|
209
216
|
when Choosy::Option
|
210
217
|
opt = regular_option(item)
|
211
|
-
|
212
|
-
|
218
|
+
len = opt.unformatted.length
|
219
|
+
if len > optionlen
|
220
|
+
optionlen = len
|
213
221
|
end
|
214
222
|
prefixes << opt
|
215
223
|
when Choosy::Command
|
@@ -224,6 +232,7 @@ module Choosy::Printing
|
|
224
232
|
end
|
225
233
|
|
226
234
|
option_indent = ' ' * (optionlen + indent.length + offset.length)
|
235
|
+
puts optionlen
|
227
236
|
cmd_indent = ' ' * (cmdlen + indent.length + offset.length)
|
228
237
|
[cmd_indent, option_indent, prefixes]
|
229
238
|
end
|
@@ -74,11 +74,11 @@ module Choosy::Printing
|
|
74
74
|
end
|
75
75
|
|
76
76
|
protected
|
77
|
-
def
|
78
|
-
@
|
77
|
+
def highlight_begin
|
78
|
+
@highlight_begin ||= color.multiple(nil, option_styles)
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def highlight_end
|
82
82
|
color.reset
|
83
83
|
end
|
84
84
|
|
@@ -88,10 +88,10 @@ module Choosy::Printing
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def write_prefix(prefix, after_indent)
|
91
|
-
len = after_indent.length - prefix.length - indent.length
|
91
|
+
len = after_indent.length - prefix.unformatted.length - indent.length
|
92
92
|
@buffer << indent
|
93
93
|
@buffer << prefix
|
94
|
-
@buffer <<
|
94
|
+
@buffer << " " * len
|
95
95
|
end
|
96
96
|
|
97
97
|
def write_lines(str, prefix, indent_first)
|
@@ -24,7 +24,7 @@ module Choosy::Printing
|
|
24
24
|
def print!(command)
|
25
25
|
if command_exists?('groff') && pager?
|
26
26
|
fix_termcap
|
27
|
-
page format!(command)
|
27
|
+
page format!(command), 'groff -t -e -W all -Tutf8 -mandoc'
|
28
28
|
else
|
29
29
|
# Fall back to a help printer if there is no pager
|
30
30
|
help = HelpPrinter.new(formatting_options)
|
@@ -56,9 +56,8 @@ module Choosy::Printing
|
|
56
56
|
|
57
57
|
def format_synopsis(command)
|
58
58
|
@manpage.section_heading(@synopsis)
|
59
|
-
cols = (columns > 70) ? 70 : columns
|
60
59
|
@manpage.nofill do |man|
|
61
|
-
usage_wrapped(command, '',
|
60
|
+
usage_wrapped(command, '', columns).each do |line|
|
62
61
|
man.text line
|
63
62
|
end
|
64
63
|
end
|
@@ -69,7 +68,7 @@ module Choosy::Printing
|
|
69
68
|
end
|
70
69
|
|
71
70
|
def format_command(command, formatted_command, indent)
|
72
|
-
@manpage.term_paragraph(formatted_command, command.summary || "", indent.length)
|
71
|
+
@manpage.term_paragraph(@manpage.format.italics(formatted_command), command.summary || "", indent.length)
|
73
72
|
end
|
74
73
|
|
75
74
|
def format_element(item)
|
@@ -85,11 +84,11 @@ module Choosy::Printing
|
|
85
84
|
end
|
86
85
|
|
87
86
|
protected
|
88
|
-
def
|
87
|
+
def highlight_begin
|
89
88
|
@manpage.format.italics
|
90
89
|
end
|
91
90
|
|
92
|
-
def
|
91
|
+
def highlight_end
|
93
92
|
@manpage.format.reset
|
94
93
|
end
|
95
94
|
end
|
@@ -15,7 +15,7 @@ module Choosy::Printing
|
|
15
15
|
|
16
16
|
heading 'OPTIONS'
|
17
17
|
boolean :evaluate, "The evaluation of some boolean something or other that really should span at least 3 lines of continuous text for testing the output of the option command."
|
18
|
-
|
18
|
+
integer_ :count, "The count of something that should also really span multiple lines, if possible."
|
19
19
|
boolean_ :debug, "Debug output"
|
20
20
|
version "1.2"
|
21
21
|
help
|
@@ -45,8 +45,8 @@ module Choosy::Printing
|
|
45
45
|
@h.columns = 60
|
46
46
|
@h.format_prologue(@c)
|
47
47
|
|
48
|
-
@h.buffer.should eql("Usage: foo [-e|--evaluate] [
|
49
|
-
[
|
48
|
+
@h.buffer.should eql("Usage: foo [-e|--evaluate] [--count=COUNT] [--debug] [--version]
|
49
|
+
[-h|--help] FOOS\n\n")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should know how to format a super command" do
|
@@ -91,6 +91,14 @@ module Choosy::Printing
|
|
91
91
|
')
|
92
92
|
end
|
93
93
|
|
94
|
+
it "should print out an option correctly that only has a single line" do
|
95
|
+
@h.columns = 70
|
96
|
+
@h.format_option(@c.listing[5], " \e[1m--count\e[0m COUNT", ' ' * 23)
|
97
|
+
@h.buffer.should eql(" \e[1m--count\e[0m COUNT The count of something that should also really
|
98
|
+
span multiple lines, if possible.
|
99
|
+
")
|
100
|
+
end
|
101
|
+
|
94
102
|
it "should print out any commands that are present" do
|
95
103
|
@h.columns = 70
|
96
104
|
@h.format_command(@c, 'foo', ' ')
|