Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #20 from moonglum/megingiard
Browse files Browse the repository at this point in the history
Introducing: Megingiard
  • Loading branch information
moonglum committed Jun 22, 2014
2 parents 3fae9e7 + ab07fb2 commit ff49f0f
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 139 deletions.
3 changes: 3 additions & 0 deletions .hound.yml
Expand Up @@ -112,3 +112,6 @@ FileName:
# Double negations are extremely useful
DoubleNegation:
Enabled: false

Output:
Enabled: false
9 changes: 0 additions & 9 deletions README.md
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions exogenesis.gemspec
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/dotfile.rb
Expand Up @@ -4,6 +4,7 @@
class Dotfile < Passenger
register_as :dotfile
needs :directory_name
with_emoji :house

def up
each_dotfile do |source, destination|
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/fonts.rb
Expand Up @@ -4,6 +4,7 @@
class Fonts < Passenger
register_as :fonts
needs :fonts_path
with_emoji :book

def up
install_all_fonts
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/git_repo.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/homebrew.rb
Expand Up @@ -7,6 +7,7 @@ class Homebrew < Passenger

register_as :homebrew
needs :brews
with_emoji :beer

def up
install_homebrew
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/homebrew_cask.rb
Expand Up @@ -5,6 +5,7 @@ class HomebrewCask < Passenger

register_as :homebrew_cask
needs :casks
with_emoji :beer

def up
tap_cask
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/npm.rb
Expand Up @@ -5,6 +5,7 @@
class Npm < Passenger
register_as :npm
needs :npms
with_emoji :cyclone

def up
install_node
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/python.rb
Expand Up @@ -5,6 +5,7 @@
class Python < Passenger
register_as :python
needs :pips
with_emoji :snake

def up
if command_exists? 'pip'
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/rbenv.rb
Expand Up @@ -4,6 +4,7 @@
class Rbenv < Passenger
register_as :rbenv
needs :rubies
with_emoji :cyclone

def up
if command_exists? 'rbenv'
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/rvm.rb
Expand Up @@ -4,6 +4,7 @@
class Rvm < Passenger
register_as :rvm
needs :rubies
with_emoji :cyclone

def up
if command_exists? 'rvm'
Expand Down
1 change: 1 addition & 0 deletions lib/exogenesis/passengers/vundle.rb
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions lib/exogenesis/support/executor.rb
Expand Up @@ -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
Expand Down
166 changes: 40 additions & 126 deletions lib/exogenesis/support/output.rb
@@ -1,143 +1,87 @@
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
WARNING = 'The output of exogenesis is not configurable, the methods for that will be removed in the next version'

# Activates fancy output by activating all other
# options except verbose.
def fancy
activate_centering.activate_decoration.activate_utf8
def initialize
@canvas = CenteredCanvas.new(STDOUT)
@success_node = EmojiNode.new(:thumbsup)
@failure_node = EmojiNode.new(:thumbsdown)
@skipped_node = EmojiNode.new(:point_right)
end

# Activates fancy output by activating all other
# options except verbose.
def self.fancy
instance.fancy
puts WARNING
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
puts WARNING
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
puts WARNING
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
puts WARNING
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
Expand All @@ -146,34 +90,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
8 changes: 8 additions & 0 deletions lib/exogenesis/support/passenger.rb
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/exogenesis/support/spacesuit.rb
Expand Up @@ -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

0 comments on commit ff49f0f

Please sign in to comment.