From ace18ab7c32bc77ac809e8eaf8a3d7533cada193 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Sun, 22 Jun 2014 11:30:35 +0200 Subject: [PATCH 1/3] We don't have a Rails logger --- .hound.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.hound.yml b/.hound.yml index 43a079a..7f9e4f4 100644 --- a/.hound.yml +++ b/.hound.yml @@ -112,3 +112,6 @@ FileName: # Double negations are extremely useful DoubleNegation: Enabled: false + +Output: + Enabled: false From 6dd1a6f0792baf82008e280abe3d0d1f2dfe5bac Mon Sep 17 00:00:00 2001 From: moonglum Date: Mon, 31 Mar 2014 22:55:36 +0200 Subject: [PATCH 2/3] First shot at using Megingiard for output --- exogenesis.gemspec | 1 + lib/exogenesis/passengers/dotfile.rb | 1 + lib/exogenesis/passengers/fonts.rb | 1 + lib/exogenesis/passengers/git_repo.rb | 1 + lib/exogenesis/passengers/homebrew.rb | 1 + lib/exogenesis/passengers/homebrew_cask.rb | 1 + lib/exogenesis/passengers/npm.rb | 1 + lib/exogenesis/passengers/python.rb | 1 + lib/exogenesis/passengers/rbenv.rb | 1 + lib/exogenesis/passengers/rvm.rb | 1 + lib/exogenesis/passengers/vundle.rb | 1 + lib/exogenesis/support/executor.rb | 4 +- lib/exogenesis/support/output.rb | 172 ++++----------------- lib/exogenesis/support/passenger.rb | 8 + lib/exogenesis/support/spacesuit.rb | 4 +- 15 files changed, 57 insertions(+), 142 deletions(-) diff --git a/exogenesis.gemspec b/exogenesis.gemspec index 561ef25..bcb3872 100644 --- a/exogenesis.gemspec +++ b/exogenesis.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] + spec.add_dependency 'megingiard', '~> 0.1.0' spec.add_development_dependency 'bundler', '~> 1.6.0' spec.add_development_dependency 'rake', '~> 10.3.2' spec.add_development_dependency 'rspec', '~> 3.0.0' diff --git a/lib/exogenesis/passengers/dotfile.rb b/lib/exogenesis/passengers/dotfile.rb index d563cda..90408df 100644 --- a/lib/exogenesis/passengers/dotfile.rb +++ b/lib/exogenesis/passengers/dotfile.rb @@ -4,6 +4,7 @@ class Dotfile < Passenger register_as :dotfile needs :directory_name + with_emoji :house def up each_dotfile do |source, destination| diff --git a/lib/exogenesis/passengers/fonts.rb b/lib/exogenesis/passengers/fonts.rb index 38b87e0..d98411f 100644 --- a/lib/exogenesis/passengers/fonts.rb +++ b/lib/exogenesis/passengers/fonts.rb @@ -4,6 +4,7 @@ class Fonts < Passenger register_as :fonts needs :fonts_path + with_emoji :book def up install_all_fonts diff --git a/lib/exogenesis/passengers/git_repo.rb b/lib/exogenesis/passengers/git_repo.rb index 2232627..a7d8bac 100644 --- a/lib/exogenesis/passengers/git_repo.rb +++ b/lib/exogenesis/passengers/git_repo.rb @@ -5,6 +5,7 @@ class GitRepo < Passenger register_as :git_repo needs :repos + with_emoji :arrow_down # Clone the Repo if it doesn't exist # Pull the Repo if it does diff --git a/lib/exogenesis/passengers/homebrew.rb b/lib/exogenesis/passengers/homebrew.rb index 9a91e18..afef076 100644 --- a/lib/exogenesis/passengers/homebrew.rb +++ b/lib/exogenesis/passengers/homebrew.rb @@ -7,6 +7,7 @@ class Homebrew < Passenger register_as :homebrew needs :brews + with_emoji :beer def up install_homebrew diff --git a/lib/exogenesis/passengers/homebrew_cask.rb b/lib/exogenesis/passengers/homebrew_cask.rb index 40ca568..7a2f90a 100644 --- a/lib/exogenesis/passengers/homebrew_cask.rb +++ b/lib/exogenesis/passengers/homebrew_cask.rb @@ -5,6 +5,7 @@ class HomebrewCask < Passenger register_as :homebrew_cask needs :casks + with_emoji :beer def up tap_cask diff --git a/lib/exogenesis/passengers/npm.rb b/lib/exogenesis/passengers/npm.rb index 1beefec..0dc3cb9 100644 --- a/lib/exogenesis/passengers/npm.rb +++ b/lib/exogenesis/passengers/npm.rb @@ -5,6 +5,7 @@ class Npm < Passenger register_as :npm needs :npms + with_emoji :cyclone def up install_node diff --git a/lib/exogenesis/passengers/python.rb b/lib/exogenesis/passengers/python.rb index 74f9b91..f5ac930 100644 --- a/lib/exogenesis/passengers/python.rb +++ b/lib/exogenesis/passengers/python.rb @@ -5,6 +5,7 @@ class Python < Passenger register_as :python needs :pips + with_emoji :snake def up if command_exists? 'pip' diff --git a/lib/exogenesis/passengers/rbenv.rb b/lib/exogenesis/passengers/rbenv.rb index ee166ea..35dcefc 100644 --- a/lib/exogenesis/passengers/rbenv.rb +++ b/lib/exogenesis/passengers/rbenv.rb @@ -4,6 +4,7 @@ class Rbenv < Passenger register_as :rbenv needs :rubies + with_emoji :cyclone def up if command_exists? 'rbenv' diff --git a/lib/exogenesis/passengers/rvm.rb b/lib/exogenesis/passengers/rvm.rb index 43b7c34..331b7a9 100644 --- a/lib/exogenesis/passengers/rvm.rb +++ b/lib/exogenesis/passengers/rvm.rb @@ -4,6 +4,7 @@ class Rvm < Passenger register_as :rvm needs :rubies + with_emoji :cyclone def up if command_exists? 'rvm' diff --git a/lib/exogenesis/passengers/vundle.rb b/lib/exogenesis/passengers/vundle.rb index 516f9e0..e38425b 100644 --- a/lib/exogenesis/passengers/vundle.rb +++ b/lib/exogenesis/passengers/vundle.rb @@ -5,6 +5,7 @@ class Vundle < Passenger VUNDLE_REPO = 'git://github.com/gmarik/vundle.git' register_as :vundle + with_emoji :gift def up if vundle_folder.exist? diff --git a/lib/exogenesis/support/executor.rb b/lib/exogenesis/support/executor.rb index 78c55bd..6cac29a 100644 --- a/lib/exogenesis/support/executor.rb +++ b/lib/exogenesis/support/executor.rb @@ -19,8 +19,8 @@ def initialize # Start a new output section with a given # text - def start_section(text) - @output.decorated_header(text) + def start_section(text, emoji_name) + @output.decorated_header(text, emoji_name) end # Notify the user that you started with a diff --git a/lib/exogenesis/support/output.rb b/lib/exogenesis/support/output.rb index 3459bad..1a6c7c3 100644 --- a/lib/exogenesis/support/output.rb +++ b/lib/exogenesis/support/output.rb @@ -1,143 +1,69 @@ require 'singleton' +require 'megingiard/centered_canvas' +require 'megingiard/emoji_node' +require 'megingiard/bold_node' +require 'megingiard/color_node' +require 'megingiard/node' -# Output is a Singleton. Get the instance -# via `Output.instance` +# Output is a Singleton. Get the instance via `Output.instance` class Output include Singleton + include Megingiard def initialize - @verbose = false - @center = false - @decoration = false - @success = 'Success' - @failure = 'Failure' - @skip = 'Skipped' - @header_start = '' - @header_end = '' - end - - # Activates fancy output by activating all other - # options except verbose. - def fancy - activate_centering.activate_decoration.activate_utf8 - end - - # Activates fancy output by activating all other - # options except verbose. - def self.fancy - instance.fancy - end - - # Activates the centering of output - def activate_centering - @center = true - self - end - - # Activates the centering of output - def self.activate_centering - instance.activate_centering - end - - # Activates bold and colored output - def activate_decoration - @decoration = true - self - end - - # Activates bold and colored output - def self.activate_decoration - instance.decoration - end - - # Output the additional information for - # the success method - def verbose - @verbose = false - self - end - - # Output the additional information for - # the success method - def self.verbose - instance.verbose - end - - # Activate the usage of 'UTF8 Icons' - def activate_utf8 - @success = "\u2713" - @failure = "\u2717" - @skip = "\u219D" - @header_start = "\u2605 " - @header_end = " \u2605" - @border = { - top_left: "\u250C", - top_center: "\u2500", - top_right: "\u2510", - bottom_left: "\u2514", - bottom_center: "\u2500", - bottom_right: "\u2518" - } - self - end - - # Activate the usage of 'UTF8 Icons' - def self.activate_utf8 - instance.activate_utf8 + @canvas = CenteredCanvas.new(STDOUT) + @success_node = EmojiNode.new(:thumbsup) + @failure_node = EmojiNode.new(:thumbsdown) + @skipped_node = EmojiNode.new(:point_right) end # Print the text as a decorated header - def decorated_header(text) - puts - puts bold(center("#{@header_start}#{text}#{@header_end}")) + def decorated_header(text, emoji_name) + emoji = EmojiNode.new(emoji_name) + header = Node.new(emoji, ' ', BoldNode.new(text), ' ', emoji) + @canvas.draw_centered_row(header) end # Print the left side of an output def left(text) - print left_aligned("#{text}:") + text_with_colon = Node.new(text, ':') + left = ColorNode.new(:white, BoldNode.new(text_with_colon)) + @canvas.draw_left_column(left) end # Print the right side with a success message - # If verbose is active, the further_information - # will be printed - def success(further_information) - puts green_bold(" #{@success}") - puts further_information if @verbose and further_information != '' + def success(_info) + success = Node.new(' ', @success_node) + @canvas.draw_right_column(success) end # Print the right side with a failure message - # Will always print the further_information - def failure(further_information) - puts red_bold(" #{@failure}") - puts further_information + def failure(info) + failure = Node.new(' ', info, ' ', @failure_node) + @canvas.draw_right_column(failure) end # Print the right side with a skipped message - # If verbose is active, the further_information - # will be printed - def skipped(further_information) - puts green_bold(" #{@skip}") - puts further_information if @verbose and further_information != '' + def skipped(_info) + skipped = Node.new(' ', @skipped_node) + @canvas.draw_right_column(skipped) end # Print some arbitrary information on the right - def info(information) - puts " #{information}" + def info(info) + info_node = Node.new(' ', info) + @canvas.draw_right_column(info_node) end # Draw the upper bound of a border - def start_border(header) - header = " #{header} " - puts @border[:top_left] + - header.center((terminal_width - 2), @border[:top_center]) + - @border[:top_right] + def start_border(info) + width = (terminal_width - 4 - info.length) / 2 + puts "\u250C#{("\u2500" * width)} #{info} #{("\u2500" * width)}\u2510" end # Draw the lower bound of a border def end_border - puts @border[:bottom_left] + - (@border[:bottom_center] * (terminal_width - 2)) + - @border[:bottom_right] + puts "\u2514#{"\u2500" * (terminal_width - 2)}\u2518" end private @@ -146,34 +72,4 @@ def end_border def terminal_width Integer(`tput cols`) end - - # Return the text as bold if and only if decoration - # is active - def bold(text) - @decoration ? "\033[1m#{text}\033[0m" : text - end - - # Return the text as centered if and only if center - # is active - def center(text) - @center ? text.center(terminal_width) : text - end - - # Return the text as left aligned if and only if center - # is active - def left_aligned(text) - @center ? text.rjust(terminal_width / 2) : text - end - - # Return the text as green bold if and only if decoration - # is active - def green_bold(text) - @decoration ? "\033[1;32m#{text}\033[0m" : text - end - - # Return the text as red bold if and only if decoration - # is active - def red_bold(text) - @decoration ? "\033[1;31m#{text}\033[0m" : text - end end diff --git a/lib/exogenesis/support/passenger.rb b/lib/exogenesis/support/passenger.rb index 0856163..474c4e0 100644 --- a/lib/exogenesis/support/passenger.rb +++ b/lib/exogenesis/support/passenger.rb @@ -19,6 +19,14 @@ def register_as(name) def needs(config_name) def_delegator :@config, config_name end + + def with_emoji(emoji_name) + @emoji_name = emoji_name + end + + def emoji_name + @emoji_name || :alien + end end def_delegators :@executor, diff --git a/lib/exogenesis/support/spacesuit.rb b/lib/exogenesis/support/spacesuit.rb index 1b9829f..6c2bf30 100644 --- a/lib/exogenesis/support/spacesuit.rb +++ b/lib/exogenesis/support/spacesuit.rb @@ -25,7 +25,7 @@ def down def wrap(task_name) return unless @passenger.respond_to? task_name - @passenger.start_section @passenger.class.to_s - @passenger.public_send task_name + @passenger.start_section(@passenger.class.to_s, @passenger.class.emoji_name) + @passenger.public_send(task_name) end end From ab07fb218d99faf8bc71fe0b696fb53d29ce3bd0 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Sun, 22 Jun 2014 22:17:48 +0200 Subject: [PATCH 3/3] Add warnings for the configurations of the output --- README.md | 9 --------- lib/exogenesis/support/output.rb | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1d1c431..b0292f7 100644 --- a/README.md +++ b/README.md @@ -52,15 +52,6 @@ You can find a list of real-world usage of this gem [here](https://github.com/mo [![badge](http://img.shields.io/badge/%F0%9F%9A%80-Created_with_Exogenesis-be1d77.svg)](https://github.com/moonglum/exogenesis) ``` -## Configuration - -You can configure the output of Exogenesis via the `Output` class: - -* `Output.activate_centering` centers the output -* `Output.activate_decoration` makes parts of the output colored and bold -* `Output.activate_utf8` uses UTF8 'icons' for certain outputs -* `Output.fancy` activates all options mentioned above at once. - ## The Interface of the classes Every class has the following methods (with the exception of `initialize` they all take no arguments): diff --git a/lib/exogenesis/support/output.rb b/lib/exogenesis/support/output.rb index 1a6c7c3..704e5e0 100644 --- a/lib/exogenesis/support/output.rb +++ b/lib/exogenesis/support/output.rb @@ -10,6 +10,8 @@ class Output include Singleton include Megingiard + WARNING = 'The output of exogenesis is not configurable, the methods for that will be removed in the next version' + def initialize @canvas = CenteredCanvas.new(STDOUT) @success_node = EmojiNode.new(:thumbsup) @@ -17,6 +19,22 @@ def initialize @skipped_node = EmojiNode.new(:point_right) end + def self.fancy + puts WARNING + end + + def self.activate_centering + puts WARNING + end + + def self.activate_decoration + puts WARNING + end + + def self.activate_utf8 + puts WARNING + end + # Print the text as a decorated header def decorated_header(text, emoji_name) emoji = EmojiNode.new(emoji_name)