Sha256: 3bd2081e0b35ae7a54b42de9cf53a6f10206585407be81afc82865dc2d9f0dad
Contents?: true
Size: 1.98 KB
Versions: 6
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require "rfix" require "cli/ui" module Rfix::Log extend self def say(message) prt("{{v}} #{message}") end def say_error(message) prt("{{x}} #{message}") end def say_error_sub(message) prt(message.to_s) end def error_box(title) box(title, color: :red) { yield } end def abort_box(title) error_box(title) { yield } exit 1 end def say_test(message) prt("{{i}} #{strip(message)}") end def say_debug(message) if debug? || test? prt("{{i}} #{strip(message)}", to: $stderr) end end def say_abort(message) prt("{{x}} #{message}") exit 1 end def debug? return false unless defined?(RSpec) return RSpec.configuration.debug? end def test? Rfix.test? end def say_exit(message) prt("{{v}} #{message}") exit 0 end def say_plain(message) prt(message) end def debug_box(title) unless_debug do box(title) { yield } end end def prt(*args) CLI::UI.puts(*args) end def fmt(*args) CLI::UI.fmt(*args) end alias ftm fmt def log_items(items, title:) box("#{title} (#{items.count})") do return margin(2) do prt "{{warning:No items found}}" end if items.empty? items.each do |item| if block_given? say strip(yield item) else say strip(item.to_s) end end end end def box(title, color: :reset) margin do CLI::UI::Frame.open(title, color: color) do margin(2) do yield end end end end def strip(msg) msg # msg.gsub(current_path, "").gsub(Dir.pwd, ".").chomp end def current_path File.join(Dir.pwd, "/") end def div(title, **args) CLI::UI::Frame.divider(title, **args) margin { yield } end def margin(n = 1) new_line(n) yield new_line(n) end def new_line(n = 1) say_plain("\n" * n) end def unless_debug yield unless Rfix.debug? end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
rfix-1.4.1 | lib/rfix/log.rb |
rfix-1.4.0.pre.201 | lib/rfix/log.rb |
rfix-1.4.0 | lib/rfix/log.rb |
rfix-1.3.0.pre.199 | lib/rfix/log.rb |
rfix-1.2.6.pre.198 | lib/rfix/log.rb |
rfix-1.2.6 | lib/rfix/log.rb |