pretty_console_output 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74a5edd872d03daf229343ca6008ab5543cc8bfa
4
+ data.tar.gz: 6c29be3f7b9f97d834f81a61db6ee11b62beba91
5
+ SHA512:
6
+ metadata.gz: 940fd39c0b32ec12a3144c24eb685de19d86a6fb03232ce30ca81b8a5d64bb482809d4667f11695a03cdbaaa623eaf7d9b7c8a43fc255d10c855515582167a95
7
+ data.tar.gz: b4988801f95fab5d57568c8790f6c48b3308c010c78089bbdab13540cd268276a027765f1ba079023ebb39389ee08bab9cb37b6682325cf5e46ae6211c21a024
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pretty_console_output.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Guanting Chen (@Sif)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ Pretty Console Output ( for Ruby 2 / Rails )
2
+ =================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/pretty_console_output.svg)](https://badge.fury.io/rb/pretty_console_output)
5
+ [![Code Climate](https://codeclimate.com/github/guanting112/pretty_console_output/badges/gpa.svg)](https://codeclimate.com/github/guanting112/pretty_console_output)
6
+
7
+ Installation
8
+ --------
9
+
10
+ Via Rubygems
11
+
12
+ ```shell
13
+ gem install pretty_console_output
14
+ ```
15
+
16
+ In your Gemfile:
17
+
18
+ ```ruby
19
+ gem 'pretty_console_output'
20
+ ```
21
+
22
+ Usage
23
+ --------
24
+
25
+ ```ruby
26
+ require 'pretty_console_output'
27
+
28
+ console = PrettyConsoleOutput::Console.new
29
+
30
+ console.tag "Reload Host files."
31
+ console.log "Start At: " + Time.now.localtime.to_s
32
+
33
+ console.tag "Check File Exists"
34
+ console.info 'Read .gitignore'
35
+ console.data IO.read('.gitignore')
36
+ console.error "sample.php Not Found"
37
+ console.error "upload/a05bf0.jpg Not Found"
38
+
39
+ console.tag "All Done"
40
+ console.done "OK: " + Time.now.to_s
41
+ ```
42
+
43
+ ![usage_output](http://i.imgur.com/pgzrEjV.png)
44
+
45
+
46
+ LICENSE
47
+ --------
48
+
49
+ MIT LICENSE ( See LICENSE.txt )
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pretty_console_output"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require "pretty_console_output/version"
2
+ require "pretty_console_output/color"
3
+ require "pretty_console_output/theme"
4
+
5
+ module PrettyConsoleOutput
6
+ class Console
7
+ def initialize(options={})
8
+ options[:theme] = {} if options[:theme].nil?
9
+ options[:stdout] = $stdout if options[:stdout].nil?
10
+
11
+ @color = Color.new(options[:stdout])
12
+ @theme = Theme.new(options[:theme])
13
+ end
14
+
15
+ def puts(obj)
16
+ $stdout.puts obj
17
+ end
18
+
19
+ def info(obj)
20
+ icon = @color.colorize(" ☞ ", @theme.info_color)
21
+ string = @color.colorize(obj.to_s, @theme.info_color)
22
+
23
+ puts "#{icon} #{string}"
24
+ end
25
+
26
+ def log(obj)
27
+ puts " #{@color.colorize(obj.to_s, @theme.log_color)}"
28
+ end
29
+
30
+ def data(obj)
31
+ puts @color.colorize(" #{obj.to_s}".gsub(/\n/, "\n "), @theme.log_color)
32
+ end
33
+
34
+ def error(obj)
35
+ icon = @color.colorize(" ✘ ", @theme.error_color)
36
+ string = @color.colorize(obj.to_s, @theme.error_color)
37
+
38
+ puts "#{icon} #{string}"
39
+ end
40
+
41
+ def done(obj)
42
+ icon = @color.colorize(" √ ", @theme.done_color)
43
+ string = @color.colorize(obj.to_s, @theme.done_color)
44
+
45
+ puts "#{icon} #{string}"
46
+ end
47
+
48
+ def tag(obj)
49
+ start_tag_time
50
+
51
+ time = @color.colorize(elapsed_time_tag, @theme.tag_date_color)
52
+ string = @color.colorize(obj, @theme.tag_text_color, bold: @theme.tag_bold, underscore: @theme.tag_underscore)
53
+
54
+ puts "\n#{time} #{string}\n\n"
55
+ end
56
+
57
+ private
58
+
59
+ def start_tag_time
60
+ @start_tag_time ||= Time.now.to_i
61
+ end
62
+
63
+ def elapsed_time_tag
64
+ elapsed_seconds = Time.now.to_i - start_tag_time
65
+
66
+ ( elapsed_seconds / 60 ).to_s.rjust(2, '0') + ":" + ( elapsed_seconds % 60 ).to_s.rjust(2, '0')
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,42 @@
1
+ module PrettyConsoleOutput
2
+ class Color
3
+ COLOR_CODES = {
4
+ black: 30,
5
+ red: 31,
6
+ green: 32,
7
+ yellow: 33,
8
+ blue: 34,
9
+ magenta: 35,
10
+ cyan: 36,
11
+ white: 37,
12
+ light_black: 90,
13
+ light_red: 91,
14
+ light_green: 92,
15
+ light_yellow: 93,
16
+ light_blue: 94,
17
+ light_magenta: 95,
18
+ light_cyan: 96,
19
+ light_white: 97
20
+ }.freeze
21
+
22
+ def initialize(output)
23
+ @output = output
24
+ end
25
+
26
+ def colorize(obj, color, mode={})
27
+ string = obj.to_s
28
+
29
+ return string unless colorize?
30
+ return string unless COLOR_CODES[color]
31
+
32
+ result = mode[:bold] ? "\e[1;" : "\e[0;"
33
+ result << "4;" unless mode[:underscore].nil?
34
+ result << COLOR_CODES[color].to_s
35
+ result << ";49m#{string}\e[0m"
36
+ end
37
+
38
+ def colorize?
39
+ (@output.respond_to?(:tty?) && @output.tty?)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module PrettyConsoleOutput
2
+ class Theme
3
+
4
+ attr_accessor :info_color
5
+ attr_accessor :log_color
6
+ attr_accessor :error_color
7
+ attr_accessor :done_color
8
+ attr_accessor :tag_text_color
9
+ attr_accessor :tag_date_color
10
+ attr_accessor :tag_bold
11
+ attr_accessor :tag_underscore
12
+
13
+ def initialize(options={})
14
+ @info_color = options.fetch(:info_color) { :light_yellow }
15
+ @log_color = options.fetch(:log_color) { :white }
16
+ @error_color = options.fetch(:error_color) { :light_red }
17
+ @done_color = options.fetch(:done_color) { :light_green }
18
+ @tag_text_color = options.fetch(:tag_text_color) { :light_white }
19
+ @tag_date_color = options.fetch(:tag_date_color) { :light_white }
20
+ @tag_bold = options.fetch(:tag_bold) { true }
21
+ @tag_underscore = options.fetch(:tag_underscore) { true }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module PrettyConsoleOutput
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pretty_console_output/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pretty_console_output"
8
+ spec.version = PrettyConsoleOutput::VERSION
9
+ spec.authors = ["Guanting Chen"]
10
+ spec.email = ["cgt886@gmail.com "]
11
+ spec.summary = %q{Pretty Console Output ( for Ruby 2 / Rails )}
12
+ spec.description = %q{Pretty Console Output ( for Ruby 2 / Rails )}
13
+ spec.homepage = "https://github.com/guanting112/pretty_console_output"
14
+ spec.license = "MIT"
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.required_ruby_version = '~> 2'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.13"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_console_output
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Guanting Chen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Pretty Console Output ( for Ruby 2 / Rails )
42
+ email:
43
+ - 'cgt886@gmail.com '
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/pretty_console_output.rb
56
+ - lib/pretty_console_output/color.rb
57
+ - lib/pretty_console_output/theme.rb
58
+ - lib/pretty_console_output/version.rb
59
+ - pretty_console_output.gemspec
60
+ homepage: https://github.com/guanting112/pretty_console_output
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Pretty Console Output ( for Ruby 2 / Rails )
85
+ test_files: []