class KLog::LogHelper
Simple console log helpers
Attributes
progress_position[RW]
progress_section[RW]
Public Class Methods
bg_blue(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 158 def self.bg_blue(value) "\033[44m#{value}\033[0m" end
bg_cyan(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 166 def self.bg_cyan(value) "\033[46m#{value}\033[0m" end
bg_green(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 150 def self.bg_green(value) "\033[42m#{value}\033[0m" end
bg_grey(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 170 def self.bg_grey(value) "\033[47m#{value}\033[0m" end
bg_purple(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 162 def self.bg_purple(value) "\033[45m#{value}\033[0m" end
bg_red(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 146 def self.bg_red(value) "\033[41m#{value}\033[0m" end
bg_yellow(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 154 def self.bg_yellow(value) "\033[43m#{value}\033[0m" end
block(messages, include_line: true, title: nil)
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity
# File lib/k_log/log_helper.rb, line 96 def self.block(messages, include_line: true, title: nil) result = include_line ? [line] : [] unless title.nil? result.push(title) result.push(line(70, '-')) end result.push messages if messages.is_a?(String) || messages.is_a?(Integer) if messages.is_a? Array messages.each do |message| result.push message end end result.push line if include_line result end
blue(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 130 def self.blue(value) "\033[34m#{value}\033[0m" end
cyan(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 138 def self.cyan(value) "\033[36m#{value}\033[0m" end
dynamic_heading(heading, size: 70, type: :heading)
click to toggle source
# File lib/k_log/log_helper.rb, line 46 def self.dynamic_heading(heading, size: 70, type: :heading) return heading(heading, size) if type == :heading return subheading(heading, size) if type == :subheading return [section_heading(heading, size)] if %i[section_heading section].include?(type) [] end
green(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 122 def self.green(value) "\033[32m#{value}\033[0m" end
grey(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 142 def self.grey(value) "\033[37m#{value}\033[0m" end
heading(heading, size = 70)
click to toggle source
# File lib/k_log/log_helper.rb, line 54 def self.heading(heading, size = 70) line = line(size) [ line, heading, line ] end
kv(key, value, key_width = 30)
click to toggle source
# File lib/k_log/log_helper.rb, line 18 def self.kv(key, value, key_width = 30) "#{green(key.to_s.ljust(key_width))}: #{value}" end
line(size = 70, character = '=')
click to toggle source
# File lib/k_log/log_helper.rb, line 42 def self.line(size = 70, character = '=') green(character * size) end
progress(pos = nil, section = nil)
click to toggle source
# File lib/k_log/log_helper.rb, line 22 def self.progress(pos = nil, section = nil) @progress_position = pos.nil? ? @progress_position : pos @progress_section = section unless section.nil? section_length = 28 section = if @progress_section.nil? ' ' * section_length else " #{@progress_section.ljust(section_length - 1, ' ')}" end result = "..#{section}:#{@progress_position.to_s.rjust(4)}" @progress_position += 1 result end
purple(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 134 def self.purple(value) "\033[35m#{value}\033[0m" end
red(value)
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity
# File lib/k_log/log_helper.rb, line 118 def self.red(value) "\033[31m#{value}\033[0m" end
section_heading(heading, size = 70)
click to toggle source
A section heading
example: [ I am a heading ]—————————————————-
# File lib/k_log/log_helper.rb, line 77 def self.section_heading(heading, size = 70) brace_open = green('[ ') brace_close = green(' ]') line_length = size - heading.length - 4 line = line_length.positive? ? line(line_length, '-') : '' # It is important that you set the colour after you have calculated the size "#{brace_open}#{heading}#{brace_close}#{green(line)}" end
subheading(heading, size = 70)
click to toggle source
# File lib/k_log/log_helper.rb, line 64 def self.subheading(heading, size = 70) line = line(size, '-') [ line, heading, line ] end
yellow(value)
click to toggle source
# File lib/k_log/log_helper.rb, line 126 def self.yellow(value) "\033[33m#{value}\033[0m" end