Module: Pod::UserInterface
- Extended by:
- Config::Mixin
- Defined in:
- lib/cocoapods/user_interface.rb,
lib/cocoapods/user_interface/error_report.rb,
lib/cocoapods/user_interface/inspector_reporter.rb
Overview
Provides support for UI output. It provides support for nested sections of information and for a verbose mode.
Defined Under Namespace
Modules: ErrorReport Classes: InspectorReporter
Class Attribute Summary collapse
-
.disable_wrap ⇒ Boolean
(also: disable_wrap?)
Whether the wrapping of the strings to the width of the terminal should be disabled.
-
.indentation_level ⇒ Object
Returns the value of attribute indentation_level.
-
.output_io ⇒ IO
IO object to which UI output will be directed.
-
.title_level ⇒ Object
Returns the value of attribute title_level.
-
.warnings ⇒ Object
Returns the value of attribute warnings.
Basic methods collapse
-
.gets ⇒ Object
gets input from $stdin.
-
.print(message) ⇒ Object
prints a message followed by a new line unless config is silent.
-
.puts(message = '') ⇒ Object
prints a message followed by a new line unless config is silent.
-
.warn(message, actions = [], verbose_only = false) ⇒ Object
Stores important warning to the user optionally followed by actions that the user should take.
-
.with_pager { ... } ⇒ Object
Pipes all output inside given block to a pager.
Class Method Summary collapse
-
.choose_from_array(array, message) ⇒ Fixnum
Presents a choice among the elements of an array to the user.
-
.info(message) ⇒ Object
Prints an info to the user.
-
.labeled(label, value, justification = 12) ⇒ Object
Prints a message with a label.
-
.message(message, verbose_prefix = '', relative_indentation = 2) { ... } ⇒ void
Prints a verbose message taking an optional verbose prefix and a relative indentation valid for the UI action in the passed block.
-
.notice(message) ⇒ Object
Prints an important message to the user.
-
.path(pathname) ⇒ Object
Returns a string containing relative location of a path from the Podfile.
-
.pod(set, mode = :normal) ⇒ Object
Prints the textual representation of a given set.
-
.print_warnings ⇒ void
Prints the stored warnings.
-
.puts_indented(message = '') ⇒ Object
Prints a message respecting the current indentation level and wrapping it to the terminal width if necessary.
-
.section(title, verbose_prefix = '', relative_indentation = 0) ⇒ Object
Prints a title taking an optional verbose prefix and a relative indentation valid for the UI action in the passed block.
-
.title(title, verbose_prefix = '', relative_indentation = 2) ⇒ Object
A title opposed to a section is always visible.
-
.titled_section(title, options = {}) ⇒ void
In verbose mode it shows the sections and the contents.
Methods included from Config::Mixin
Class Attribute Details
.disable_wrap ⇒ Boolean Also known as: disable_wrap?
Returns Whether the wrapping of the strings to the width of the terminal should be disabled.
31 32 33 |
# File 'lib/cocoapods/user_interface.rb', line 31 def disable_wrap @disable_wrap end |
.indentation_level ⇒ Object
Returns the value of attribute indentation_level.
20 21 22 |
# File 'lib/cocoapods/user_interface.rb', line 20 def indentation_level @indentation_level end |
.output_io ⇒ IO
Returns IO object to which UI output will be directed.
26 27 28 |
# File 'lib/cocoapods/user_interface.rb', line 26 def output_io @output_io end |
.title_level ⇒ Object
Returns the value of attribute title_level.
21 22 23 |
# File 'lib/cocoapods/user_interface.rb', line 21 def title_level @title_level end |
.warnings ⇒ Object
Returns the value of attribute warnings.
22 23 24 |
# File 'lib/cocoapods/user_interface.rb', line 22 def warnings @warnings end |
Class Method Details
.choose_from_array(array, message) ⇒ Fixnum
Presents a choice among the elements of an array to the user.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/cocoapods/user_interface.rb', line 314 def choose_from_array(array, ) array.each_with_index do |item, index| UI.puts "#{index + 1}: #{item}" end UI.puts index = UI.gets.chomp.to_i - 1 if index < 0 || index > array.count - 1 raise Informative, "#{index + 1} is invalid [1-#{array.count}]" else index end end |
.gets ⇒ Object
gets input from $stdin
364 365 366 |
# File 'lib/cocoapods/user_interface.rb', line 364 def gets $stdin.gets end |
.info(message) ⇒ Object
Prints an info to the user. The info is always displayed. It respects the current indentation level only in verbose mode.
Any title printed in the optional block is treated as a message.
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cocoapods/user_interface.rb', line 163 def info() indentation = config.verbose? ? self.indentation_level : 0 indented = wrap_string(, indentation) puts(indented) self.indentation_level += 2 @treat_titles_as_messages = true yield if block_given? ensure @treat_titles_as_messages = false self.indentation_level -= 2 end |
.labeled(label, value, justification = 12) ⇒ Object
Prints a message with a label.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/cocoapods/user_interface.rb', line 259 def labeled(label, value, justification = 12) if value title = "- #{label}:" if value.is_a?(Array) lines = [wrap_string(title, self.indentation_level)] value.each do |v| lines << wrap_string("- #{v}", self.indentation_level + 2) end puts lines.join("\n") else puts wrap_string(title.ljust(justification) + "#{value}", self.indentation_level) end end end |
.message(message, verbose_prefix = '', relative_indentation = 2) { ... } ⇒ void
Clean interface.
This method returns an undefined value.
Prints a verbose message taking an optional verbose prefix and a relative indentation valid for the UI action in the passed block.
144 145 146 147 148 149 150 151 152 |
# File 'lib/cocoapods/user_interface.rb', line 144 def (, verbose_prefix = '', relative_indentation = 2) = verbose_prefix + if config.verbose? puts_indented if config.verbose? self.indentation_level += relative_indentation yield if block_given? ensure self.indentation_level -= relative_indentation end |
.notice(message) ⇒ Object
Prints an important message to the user.
return [void]
182 183 184 |
# File 'lib/cocoapods/user_interface.rb', line 182 def notice() puts("\n[!] #{}".green) end |
.path(pathname) ⇒ Object
Returns a string containing relative location of a path from the Podfile. The returned path is quoted. If the argument is nil it returns the empty string.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/cocoapods/user_interface.rb', line 193 def path(pathname) if pathname from_path = config.podfile_path.dirname if config.podfile_path from_path ||= Pathname.pwd path = begin Pathname(pathname).relative_path_from(from_path) rescue pathname end "`#{path}`" else '' end end |
.pod(set, mode = :normal) ⇒ Object
Prints the textual representation of a given set.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/cocoapods/user_interface.rb', line 216 def pod(set, mode = :normal) if mode == :name_and_version puts_indented "#{set.name} #{set.versions.first.version}" else pod = Specification::Set::Presenter.new(set) title = "-> #{pod.name} (#{pod.version})" if pod.spec.deprecated? title += " #{pod.deprecation_description}" colored_title = title.red else colored_title = title.green end title(colored_title, '', 1) do puts_indented pod.summary if pod.summary puts_indented "pod '#{pod.name}', '~> #{pod.version}'" labeled('Homepage', pod.homepage) labeled('Source', pod.source_url) labeled('Versions', pod.versions_by_source) if mode == :stats labeled('Authors', pod.) if pod. =~ /,/ labeled('Author', pod.) if pod. !~ /,/ labeled('License', pod.license) labeled('Platform', pod.platform) labeled('Stars', pod.github_stargazers) labeled('Forks', pod.github_forks) end labeled('Subspecs', pod.subspecs) end end end |
.print(message) ⇒ Object
prints a message followed by a new line unless config is silent.
353 354 355 356 357 358 359 360 |
# File 'lib/cocoapods/user_interface.rb', line 353 def print() return if config.silent? begin (output_io || STDOUT).print() rescue Errno::EPIPE exit 0 end end |
.print_warnings ⇒ void
This method returns an undefined value.
Prints the stored warnings. This method is intended to be called at the end of the execution of the binary.
290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/cocoapods/user_interface.rb', line 290 def print_warnings STDOUT.flush warnings.each do |warning| next if warning[:verbose_only] && !config.verbose? STDERR.puts("\n[!] #{warning[:message]}".yellow) warning[:actions].each do |action| string = "- #{action}" string = wrap_string(string, 4) puts(string) end end end |
.puts(message = '') ⇒ Object
prints a message followed by a new line unless config is silent.
339 340 341 342 343 344 345 346 |
# File 'lib/cocoapods/user_interface.rb', line 339 def puts( = '') return if config.silent? begin (output_io || STDOUT).puts() rescue Errno::EPIPE exit 0 end end |
.puts_indented(message = '') ⇒ Object
Prints a message respecting the current indentation level and wrapping it to the terminal width if necessary.
280 281 282 283 |
# File 'lib/cocoapods/user_interface.rb', line 280 def puts_indented( = '') indented = wrap_string(, self.indentation_level) puts(indented) end |
.section(title, verbose_prefix = '', relative_indentation = 0) ⇒ Object
Refactor to title (for always visible titles like search) and sections (titles that represent collapsible sections).
Prints a title taking an optional verbose prefix and a relative indentation valid for the UI action in the passed block.
In verbose mode titles are printed with a color according to their level. In normal mode titles are printed only if they have nesting level smaller than 2.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cocoapods/user_interface.rb', line 55 def section(title, verbose_prefix = '', relative_indentation = 0) if config.verbose? title(title, verbose_prefix, relative_indentation) elsif title_level < 1 puts title end self.indentation_level += relative_indentation self.title_level += 1 yield if block_given? ensure self.indentation_level -= relative_indentation self.title_level -= 1 end |
.title(title, verbose_prefix = '', relative_indentation = 2) ⇒ Object
A title opposed to a section is always visible
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cocoapods/user_interface.rb', line 104 def title(title, verbose_prefix = '', relative_indentation = 2) if @treat_titles_as_messages (title, verbose_prefix) else title = verbose_prefix + title if config.verbose? title = "\n#{title}" if @title_level < 2 if (color = @title_colors[@title_level]) title = title.send(color) end puts "#{title}" end self.indentation_level += relative_indentation self.title_level += 1 yield if block_given? ensure self.indentation_level -= relative_indentation self.title_level -= 1 end |
.titled_section(title, options = {}) ⇒ void
This method returns an undefined value.
In verbose mode it shows the sections and the contents. In normal mode it just prints the title.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cocoapods/user_interface.rb', line 75 def titled_section(title, = {}) relative_indentation = [:relative_indentation] || 0 verbose_prefix = [:verbose_prefix] || '' if config.verbose? title(title, verbose_prefix, relative_indentation) else puts title end self.indentation_level += relative_indentation self.title_level += 1 yield if block_given? ensure self.indentation_level -= relative_indentation self.title_level -= 1 end |
.warn(message, actions = [], verbose_only = false) ⇒ Object
Stores important warning to the user optionally followed by actions that the user should take. To print them use #print_warnings.
return [void]
378 379 380 |
# File 'lib/cocoapods/user_interface.rb', line 378 def warn(, actions = [], verbose_only = false) warnings << { :message => , :actions => actions, :verbose_only => verbose_only } end |
.with_pager { ... } ⇒ Object
Pipes all output inside given block to a pager.
386 387 388 389 390 391 392 393 394 395 |
# File 'lib/cocoapods/user_interface.rb', line 386 def with_pager prev_handler = Signal.trap('INT', 'IGNORE') IO.popen((ENV['PAGER'] || 'less -R'), 'w') do |io| UI.output_io = io yield end ensure Signal.trap('INT', prev_handler) UI.output_io = nil end |