Commit 0eadc218 authored by Fabio Pelosin's avatar Fabio Pelosin

[Dependency] indent fetching messages.

parent 7df2566a
...@@ -193,7 +193,7 @@ module Pod ...@@ -193,7 +193,7 @@ module Pod
class GitSource < AbstractExternalSource class GitSource < AbstractExternalSource
def copy_external_source_into_sandbox(sandbox, platform) def copy_external_source_into_sandbox(sandbox, platform)
puts "-> Pre-downloading: '#{name}'" unless config.silent? UI.info("->".green + " Pre-downloading: '#{name}'") do
target = sandbox.root + name target = sandbox.root + name
target.rmtree if target.exist? target.rmtree if target.exist?
downloader = Downloader.for_target(sandbox.root + name, @params) downloader = Downloader.for_target(sandbox.root + name, @params)
...@@ -203,6 +203,7 @@ module Pod ...@@ -203,6 +203,7 @@ module Pod
local_pod.downloaded = true local_pod.downloaded = true
end end
end end
end
def description def description
"from `#{@params[:git]}'".tap do |description| "from `#{@params[:git]}'".tap do |description|
...@@ -216,11 +217,12 @@ module Pod ...@@ -216,11 +217,12 @@ module Pod
# can be http, file, etc # can be http, file, etc
class PodspecSource < AbstractExternalSource class PodspecSource < AbstractExternalSource
def copy_external_source_into_sandbox(sandbox, _) def copy_external_source_into_sandbox(sandbox, _)
puts "-> Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent? UI.info("->".green + " Fetching podspec for `#{name}' from: #{@params[:podspec]}") do
path = @params[:podspec] path = @params[:podspec]
path = Pathname.new(path).expand_path if path.start_with?("~") path = Pathname.new(path).expand_path if path.start_with?("~")
open(path) { |io| store_podspec(sandbox, io.read) } open(path) { |io| store_podspec(sandbox, io.read) }
end end
end
def description def description
"from `#{@params[:podspec]}'" "from `#{@params[:podspec]}'"
......
...@@ -4,9 +4,10 @@ module Pod ...@@ -4,9 +4,10 @@ module Pod
autoload :UIPod, 'cocoapods/user_interface/ui_pod' autoload :UIPod, 'cocoapods/user_interface/ui_pod'
@indentation_level = 0
@title_level = 0
@title_colors = %w|yellow green| @title_colors = %w|yellow green|
@title_level = 0
@indentation_level = 0
@treat_titles_as_messages = false
class << self class << self
include Config::Mixin include Config::Mixin
...@@ -41,12 +42,16 @@ module Pod ...@@ -41,12 +42,16 @@ module Pod
# A title oposed to a section is always visible # A title oposed to a section is always visible
# #
def title(title, verbose_prefix = '', relative_indentation = 2) def title(title, verbose_prefix = '', relative_indentation = 2)
if(@treat_titles_as_messages)
message(title, verbose_prefix)
else
title = verbose_prefix + title if config.verbose? title = verbose_prefix + title if config.verbose?
title = "\n#{title}" if @title_level < 2 title = "\n#{title}" if @title_level < 2
if (color = @title_colors[@title_level]) if (color = @title_colors[@title_level])
title = title.send(color) title = title.send(color)
end end
puts "#{title}" puts "#{title}"
end
self.indentation_level += relative_indentation self.indentation_level += relative_indentation
self.title_level += 1 self.title_level += 1
...@@ -73,18 +78,22 @@ module Pod ...@@ -73,18 +78,22 @@ module Pod
self.indentation_level -= relative_indentation self.indentation_level -= relative_indentation
end end
# Prints a message unless config is silent. # Prints an info to the user. The info is always displayed.
# It respects the current indentation level only in verbose
# mode.
# #
def puts(message = '') # Any title printed in the optional block is treated as a message.
super(message) unless config.silent?
end
# Prints a message respecting the current indentation level and
# wrapping it to the termina width if necessary.
# #
def puts_indented(message = '') def info(message)
indented = wrap_string(message, " " * self.indentation_level) indentation = config.verbose? ? self.indentation_level : 0
indented = wrap_string(message, " " * indentation)
puts(indented) puts(indented)
self.indentation_level += 2
@treat_titles_as_messages = true
yield if block_given?
@treat_titles_as_messages = false
self.indentation_level -= 2
end end
# Returns a string containing relative location of a path from the Podfile. # Returns a string containing relative location of a path from the Podfile.
...@@ -141,8 +150,34 @@ module Pod ...@@ -141,8 +150,34 @@ module Pod
end end
end end
# Wraps a string with a given indent to the width of the terminal. # @!group Basic printing
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
# Prints a message unless config is silent.
#
def puts(message = '')
super(message) unless config.silent?
end
# Prints a message respecting the current indentation level and
# wrapping it to the terminal width if necessary.
#
def puts_indented(message = '')
indented = wrap_string(message, " " * self.indentation_level)
puts(indented)
end
private
# @!group Helpers
# Wraps a string taking into account the width of the terminal and an
# option indent. Adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
#
# @param [String] txt The string to wrap
#
# @param [String] indent The string to use to indent the result.
#
# @return [String] The formatted string.
# #
def wrap_string(txt, indent = '') def wrap_string(txt, indent = '')
width = `stty size`.split(' ')[1].to_i - indent.length width = `stty size`.split(' ')[1].to_i - indent.length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment