module CfScript::UI

Constants

COLORS
EMOJI
TAGS

Public Instance Methods

alert(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 137
def alert(tag, message)
  puts_out ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_alert
call_type(callee) click to toggle source
# File lib/cf_script/ui.rb, line 125
def call_type(callee)
  callee.to_s =~ /\Aui_(.+)\z/ ? $1.to_sym : callee
end
debug(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 168
def debug(tag, message)
  puts_err ui_format(call_type(__callee__), tag, message.inspect)
 #binding.pry; __pry__.???
end
Also aliased as: ui_debug
detail(tag, message, indent = 1) click to toggle source
# File lib/cf_script/ui.rb, line 157
def detail(tag, message, indent = 1)
  puts_out ui_format(call_type(__callee__), tag, "#{'  ' * indent}#{message}")
end
Also aliased as: ui_detail
emoji(type) click to toggle source
# File lib/cf_script/ui.rb, line 75
def emoji(type)
  "#{(EMOJI.key?(type) ? EMOJI[type] : EMOJI[:default])} "
end
emoji_for(type) click to toggle source
# File lib/cf_script/ui.rb, line 79
def emoji_for(type)
  emoji(type) if CfScript.config.ui.emoji
end
error(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 133
def error(tag, message)
  puts_err ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_error
info(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 141
def info(tag, message)
  puts_out ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_info
print_err(text) click to toggle source
print_out(text) click to toggle source
progress(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 145
def progress(tag, message)
  puts_out ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_progress
puts_err(text) click to toggle source
# File lib/cf_script/ui.rb, line 61
def puts_err(text)
  CfScript.stderr.puts text
  nil # Make it explicit
end
puts_out(text) click to toggle source
# File lib/cf_script/ui.rb, line 51
def puts_out(text)
  CfScript.stdout.puts text
  nil # Make it explicit
end
step(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 149
def step(tag, message)
  puts_out ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_step
success(tag, message) click to toggle source
# File lib/cf_script/ui.rb, line 129
def success(tag, message)
  puts_out ui_format(call_type(__callee__), tag, message)
end
Also aliased as: ui_success
tag_char(type, which) click to toggle source
# File lib/cf_script/ui.rb, line 91
def tag_char(type, which)
  (TAGS.key?(type) ? TAGS[type] : TAGS[:other]).send(which)
end
tag_close(type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 99
def tag_close(type = :default)
  tag_char(tag_style(type), :last)
end
tag_color(type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 87
def tag_color(type = :default)
  type
end
tag_format(tag, type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 103
def tag_format(tag, type = :default)
  if tag && CfScript.config.ui.tags
    list = []

    list << tag_open(type)
    list << tag
    list << tag_close(type)

    list.join.colorize with_color_of(tag_color(type))
  end
end
Also aliased as: ui_tag_format
tag_open(type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 95
def tag_open(type = :default)
  tag_char(tag_style(type), :first)
end
tag_style(type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 83
def tag_style(type = :default)
  type
end
title(tag, message, indent = 0) click to toggle source
# File lib/cf_script/ui.rb, line 153
def title(tag, message, indent = 0)
  puts_out ui_format(call_type(__callee__), tag, "#{'  ' * indent}#{message}")
end
Also aliased as: ui_title
trace(tag, message, use_print = false) click to toggle source
# File lib/cf_script/ui.rb, line 161
def trace(tag, message, use_print = false)
  if CfScript.config.runtime.trace
    text = ui_format(call_type(__callee__), tag, message)
    use_print ? print_out(text) : puts_out(text)
  end
end
Also aliased as: ui_trace
ui_alert(tag, message)
Alias for: alert
ui_debug(tag, message)
Alias for: debug
ui_detail(tag, message, indent = 1)
Alias for: detail
ui_error(tag, message)
Alias for: error
ui_format(type, tag, message, tag_type = nil) click to toggle source
# File lib/cf_script/ui.rb, line 115
def ui_format(type, tag, message, tag_type = nil)
  list = []

  list << emoji_for(type)
  list << tag_format(tag, tag_type ? tag_type : type)
  list << message.colorize(with_color_of(type))

  list.compact.reject(&:empty?).join(' ')
end
ui_info(tag, message)
Alias for: info
ui_progress(tag, message)
Alias for: progress
ui_step(tag, message)
Alias for: step
ui_success(tag, message)
Alias for: success
ui_tag_format(tag, type = :default)

For overriding to use a default tag

Alias for: tag_format
ui_title(tag, message, indent = 0)
Alias for: title
ui_trace(tag, message, use_print = false)
Alias for: trace
with_color_of(type = :default) click to toggle source
# File lib/cf_script/ui.rb, line 71
def with_color_of(type = :default)
  COLORS[CfScript.config.ui.color ? type : :default]
end