Module: Alchemy::Shell
Overview
Provides methods for collecting sentences and displaying them in a list on the shell / log
Constant Summary collapse
- COLORS =
{ clear: Thor::Shell::Color::CLEAR, green: Thor::Shell::Color::GREEN, red: Thor::Shell::Color::RED, yellow: Thor::Shell::Color::YELLOW }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#add_todo(todo) ⇒ Object
Adds a sentence to the todos Array.
- #desc(message) ⇒ Object
-
#display_todos ⇒ Object
Prints out all the todos.
-
#log(message, type = nil) ⇒ Object
Prints out the given log message with the color due to its type.
- #todo(todo, title = "") ⇒ Object
-
#todos ⇒ Array
All todos.
Class Method Details
.silence! ⇒ Object
17 18 19 |
# File 'lib/alchemy/shell.rb', line 17 def self.silence! @silenced = true end |
.silenced? ⇒ Boolean
25 26 27 |
# File 'lib/alchemy/shell.rb', line 25 def self.silenced? @silenced ||= false end |
.verbose! ⇒ Object
21 22 23 |
# File 'lib/alchemy/shell.rb', line 21 def self.verbose! @silenced = false end |
Instance Method Details
#add_todo(todo) ⇒ Object
Adds a sentence to the todos Array
44 45 46 |
# File 'lib/alchemy/shell.rb', line 44 def add_todo(todo) todos << todo end |
#desc(message) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/alchemy/shell.rb', line 29 def desc() unless Alchemy::Shell.silenced? puts "\n#{}" puts "#{"-" * .length}\n" end end |
#display_todos ⇒ Object
Prints out all the todos
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/alchemy/shell.rb', line 58 def display_todos return if todos.empty? log "\n+---------+", :message log "| 📝 TODO |", :message log "+---------+\n", :message puts "\nWe did most of the work for you, but there are still some things left for you to do." todos.each_with_index do |todo, i| title = "\n#{i + 1}. #{todo[0]}" log title, :message puts "=" * title.length puts "" log todo[1], :message end puts "" puts "============================================================" puts "= ✨ Please take a minute and read the notes from above ✨ =" puts "============================================================" puts "" end |
#log(message, type = nil) ⇒ Object
Prints out the given log message with the color due to its type
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/alchemy/shell.rb', line 84 def log(, type = nil) unless Alchemy::Shell.silenced? case type when :skip puts "#{color(:yellow)}== Skipping! #{}#{color(:clear)}" when :error puts "#{color(:red)}!! ERROR: #{}#{color(:clear)}" when :message puts "#{color(:clear)}#{}" else puts "#{color(:green)}== #{}#{color(:clear)}" end end end |
#todo(todo, title = "") ⇒ Object
36 37 38 |
# File 'lib/alchemy/shell.rb', line 36 def todo(todo, title = "") add_todo [title, todo] end |
#todos ⇒ Array
All todos
52 53 54 |
# File 'lib/alchemy/shell.rb', line 52 def todos @@todos ||= [] end |