Module: Xcode::TerminalOutput
- Included in:
- Builder::BaseBuilder, Builder::XcodebuildParser, Keychain, ProvisioningProfile, Shell::Command, Xcode::Test::Formatters::StdoutFormatter
- Defined in:
- lib/xcode/terminal_output.rb
Constant Summary collapse
- LEVELS =
[ :error, :warning, :notice, :info, :debug ]
- @@colour_enabled =
true
- @@log_level =
:info
Class Method Summary collapse
Instance Method Summary collapse
- #color_output=(color_output) ⇒ Object
- #color_output? ⇒ Boolean
- #format_lhs(left, right, terminator = ":") ⇒ Object
- #log_level ⇒ Object
- #print(text, color = :default) ⇒ Object
-
#print_input(message, level = :debug) ⇒ Object
Print an IO input interaction.
-
#print_output(message, level = :debug) ⇒ Object
Print an IO output interaction.
- #print_system(message, level = :debug) ⇒ Object
- #print_task(task, message, level = :info, cr = true) ⇒ Object
- #puts(text, color = :default) ⇒ Object
Class Method Details
.included(base) ⇒ Object
25 26 27 |
# File 'lib/xcode/terminal_output.rb', line 25 def self.included(base) @@colour_supported = terminal_supports_colors? end |
.log_level=(level) ⇒ Object
20 21 22 23 |
# File 'lib/xcode/terminal_output.rb', line 20 def self.log_level=(level) raise "Unknown log level #{level}, should be one of #{LEVELS.join(', ')}" unless LEVELS.include? level @@log_level = level end |
.terminal_supports_colors? ⇒ Boolean
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/xcode/terminal_output.rb', line 103 def self.terminal_supports_colors? # No colors unless we are being run via a TTY return false unless $stdout.isatty # Check if the terminal supports colors colors = `tput colors 2> /dev/null`.chomp if $?.exitstatus == 0 colors.to_i >= 8 else false end end |
Instance Method Details
#color_output=(color_output) ⇒ Object
29 30 31 |
# File 'lib/xcode/terminal_output.rb', line 29 def color_output= color_output @@colour_enabled = color_output end |
#color_output? ⇒ Boolean
33 34 35 |
# File 'lib/xcode/terminal_output.rb', line 33 def color_output? @@colour_supported and @@colour_enabled end |
#format_lhs(left, right, terminator = ":") ⇒ Object
57 58 59 60 |
# File 'lib/xcode/terminal_output.rb', line 57 def format_lhs(left, right, terminator=":") # "#{left.to_s.ljust(10)} #{right.rjust(6)}#{terminator} " "#{right.to_s.rjust(7)}#{terminator} " end |
#log_level ⇒ Object
16 17 18 |
# File 'lib/xcode/terminal_output.rb', line 16 def log_level @@log_level end |
#print(text, color = :default) ⇒ Object
98 99 100 101 |
# File 'lib/xcode/terminal_output.rb', line 98 def print(text, color = :default) color_params = color_output? ? color : {} super(text.colorize(color_params)) end |
#print_input(message, level = :debug) ⇒ Object
Print an IO input interaction
40 41 42 43 |
# File 'lib/xcode/terminal_output.rb', line 40 def print_input , level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", "<") + , :default end |
#print_output(message, level = :debug) ⇒ Object
Print an IO output interaction
47 48 49 50 |
# File 'lib/xcode/terminal_output.rb', line 47 def print_output , level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", ">") + , :default end |
#print_system(message, level = :debug) ⇒ Object
52 53 54 55 |
# File 'lib/xcode/terminal_output.rb', line 52 def print_system , level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", "!") + , :green end |
#print_task(task, message, level = :info, cr = true) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/xcode/terminal_output.rb', line 62 def print_task(task, , level=:info, cr=true) return if LEVELS.index(level) > LEVELS.index(@@log_level) level_str = "" case level when :error level_str = "ERROR" color = :red when :warning level_str = "WARN" color = :yellow when :notice level_str = "NOTICE" color = :green when :info level_str = "" color = :blue else color = :default end print format_lhs(task, level_str), color print , (level==:warning or level==:error or level==:notice) ? color : :default if block_given? yield end print "\n" if cr end |
#puts(text, color = :default) ⇒ Object
93 94 95 96 |
# File 'lib/xcode/terminal_output.rb', line 93 def puts(text, color = :default) color_params = color_output? ? color : {} super(text.colorize(color_params)) end |