choosy 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## 0.4.0 (March 28, 2011)
2
2
 
3
+ Fixes:
4
+
5
+ - Minor cleanup of the formatting.
6
+
7
+ ## 0.4.0 (March 28, 2011)
8
+
3
9
  Features:
4
10
 
5
11
  - Added a 'section' operation to allow for subsection grouping in commands, for greater clarity.
data/lib/VERSION.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  date: 28/03/2011
3
3
  version:
4
- tiny: 0
4
+ tiny: 1
5
5
  major: 0
6
6
  minor: 4
@@ -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 << option_begin
107
+ value << highlight_begin
102
108
  value << option.short_flag
103
- value << option_end
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 << option_begin
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 << option_end
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 option_begin
200
+ def highlight_begin
194
201
  ''
195
202
  end
196
203
 
197
- def option_end
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
- if opt.length > optionlen
212
- optionlen = opt.length
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 option_begin
78
- @option_begin ||= color.multiple(nil, option_styles)
77
+ def highlight_begin
78
+ @highlight_begin ||= color.multiple(nil, option_styles)
79
79
  end
80
80
 
81
- def option_end
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 << ' ' * len
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)#, 'groff -t -e -W all -Tutf8 -mandoc'
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, '', cols).each do |line|
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 option_begin
87
+ def highlight_begin
89
88
  @manpage.format.italics
90
89
  end
91
90
 
92
- def option_end
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
- integer :count, "The count of something that should also really span multiple lines, if possible."
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] [-c|--count=COUNT] [--debug]
49
- [--version] [-h|--help] FOOS\n\n")
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', ' ')
@@ -64,7 +64,7 @@ option line here.')
64
64
  end
65
65
  @man.format_command(@cmd, 'cmd', ' ')
66
66
  output.should eql('.TP 4
67
- cmd
67
+ \fIcmd\fP
68
68
  this is a summary')
69
69
  end
70
70
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabe McArthur