Module: LitCLI
- Defined in:
- lib/config.rb,
lib/lit_cli.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- @@pastel =
Pastel.new
- @@config =
Config.new
Class Method Summary collapse
- .colorize(text, color) ⇒ Object
-
.configure {|@@config| ... } ⇒ Object
Override config from application.
Instance Method Summary collapse
- #delay ⇒ Object
- #filter?(type) ⇒ Boolean
- #lit(message, type = :info) ⇒ Object (also: #🔥)
- #render(type) ⇒ Object
- #step ⇒ Object
Class Method Details
.colorize(text, color) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lit_cli.rb', line 52 def self.colorize(text, color) case color when :blue return @@pastel.bright_blue(text) when :green return @@pastel.green(text) when :yellow return @@pastel.yellow(text) when :red return @@pastel.red(text) when :purple, :magenta return @@pastel.magenta(text) when :cyan return @@pastel.cyan(text) else return text end end |
.configure {|@@config| ... } ⇒ Object
Override config from application.
72 73 74 75 76 77 |
# File 'lib/lit_cli.rb', line 72 def self.configure() yield(@@config) # Override config from command line. @@config.cli_configure() end |
Instance Method Details
#delay ⇒ Object
46 47 48 49 50 |
# File 'lib/lit_cli.rb', line 46 def delay() if @@config.delay > 0 sleep(@@config.delay) end end |
#filter?(type) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/lit_cli.rb', line 38 def filter? type unless @@config.type.nil? || @@config.type.include?(type) return true end false end |
#lit(message, type = :info) ⇒ Object Also known as: 🔥
8 9 10 11 12 13 14 15 |
# File 'lib/lit_cli.rb', line 8 def lit(, type = :info) if @@config.enabled return if filter? type render(type) step() delay() end end |
#render(type) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lit_cli.rb', line 18 def render(type) type_config = @@config.types[type] time_text = LitCLI.colorize(Time.now().strftime("%k:%M"), :cyan) type_text = type_config[:icon] + " " + type.to_s type_text_color = LitCLI.colorize(type_text, type_config[:color]) = "🔥 #{time_text} #{type_text_color} #{message}" puts end |
#step ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lit_cli.rb', line 30 def step() if @@config.step puts "🔥 PRESS ENTER:" input = gets.chomp binding while input == nil end end |