ansi_palette 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9666c052c93ea22701018611c9928a1be41b6ae0
4
+ data.tar.gz: 740dd964c13115bf1df1eb40e816864a9fc39f7e
5
+ SHA512:
6
+ metadata.gz: 6c3d208981a273bfb96d97fae94983625f55e79c96b031fb7b265bb18e59ed479cff52c1a93bd71b3115086aed387e90098f4d9ef884945e11ceed4458679e7c
7
+ data.tar.gz: a0cfcef3cbe4624b551778bf3d9602466ea59759454d68847601585b5e93e556bc00044c1852a4ddcf9131144cab3d4abb96c28a75f075f4aadaba7e55845b3d
@@ -0,0 +1,37 @@
1
+ # This is a sample .codeclimate.yml configured for Engine analysis on Code
2
+ # Climate Platform. For an overview of the Code Climate Platform, see here:
3
+ # http://docs.codeclimate.com/article/300-the-codeclimate-platform
4
+
5
+ # Under the engines key, you can configure which engines will analyze your repo.
6
+ # Each key is an engine name. For each value, you need to specify enabled: true
7
+ # to enable the engine as well as any other engines-specific configuration.
8
+
9
+ # For more details, see here:
10
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
11
+
12
+ # For a list of all available engines, see here:
13
+ # http://docs.codeclimate.com/article/296-engines-available-engines
14
+
15
+ engines:
16
+ # to turn on an engine, add it here and set enabled to `true`
17
+ # to turn off an engine, set enabled to `false` or remove it
18
+ rubocop:
19
+ enabled: true
20
+
21
+ # Engines can analyze files and report issues on them, but you can separately
22
+ # decide which files will receive ratings based on those issues. This is
23
+ # specified by path patterns under the ratings key.
24
+
25
+ # For more details see here:
26
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
27
+
28
+ ratings:
29
+ paths:
30
+ - lib/**
31
+
32
+ # You can globally exclude files from being analyzed by any engine using the
33
+ # exclude_paths key.
34
+
35
+ #exclude_paths:
36
+ #- spec/**/*
37
+ #- vendor/**/*
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ sudo: required
3
+ rvm:
4
+ - 2.1.3
5
+ - 2.2.3
6
+ - 2.2.0
7
+ addons:
8
+ code_climate:
9
+ repo_token: 016bbfc875ea2906b5ba73b6bfba2e21c0dcd43e497f512d8c29114c4321b962
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansi_palette.gemspec
4
+ gemspec
5
+
6
+ gem "minitest-rg"
7
+ gem "minitest-focus"
8
+
9
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Begin
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.
@@ -0,0 +1,94 @@
1
+ # AnsiPalette
2
+
3
+ [![Build Status](https://travis-ci.org/presidentJFK/ansi_palette.svg?branch=master)](https://travis-ci.org/presidentJFK/ansi_palette) [![Test Coverage](https://codeclimate.com/github/presidentJFK/ansi_palette/badges/coverage.svg)](https://codeclimate.com/github/presidentJFK/ansi_palette/coverage) [![Code Climate](https://codeclimate.com/github/presidentJFK/ansi_palette/badges/gpa.svg)](https://codeclimate.com/github/presidentJFK/ansi_palette) [![Dependency Status](https://gemnasium.com/presidentJFK/ansi_palette.svg)](https://gemnasium.com/presidentJFK/ansi_palette)
4
+
5
+ AnsiPalette is yet another terminal coloring gem.
6
+ I have never been satisfied with the various coloring gems,
7
+ for one reason or another, and never knew the details of how each worked.
8
+
9
+ Goals of this Gem:
10
+ * Help me understand more about ANSI escape characters
11
+ * Create code the makes it easy to understand how ANSI escape charactors are used
12
+ * Create a simple and usable API for coloring strings
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'ansi_palette'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install ansi_palette
29
+
30
+ ---
31
+
32
+ Here is the new implementation I am working on, currently
33
+ still under heavy exploration.
34
+
35
+ ```ruby
36
+ puts "\n\n"
37
+ puts %!puts Red("hello")!
38
+ puts Red("hello")
39
+ puts "\n\n"
40
+
41
+ header = <<-HEADER
42
+ A Classy Comment Header
43
+ HEADER
44
+
45
+ body = <<-BODY
46
+ Some very interesting comment text.
47
+ With all these intricate details.
48
+ Explaining everything you could ever
49
+ want to know.
50
+ BODY
51
+
52
+ doc = <<-DOC
53
+ #{Red(header)}
54
+ #{Cyan(body)}
55
+ DOC
56
+
57
+ puts doc
58
+
59
+ color = Blue("Header")
60
+ puts color
61
+
62
+ color = Red("Header")
63
+ color.bold = true
64
+ puts color
65
+
66
+ color = Yellow("Header")
67
+ color.bold = true
68
+ color.blink = true
69
+ puts color
70
+
71
+ color = Yellow("Header")
72
+ color.bold = true
73
+ color.blink = true
74
+ color.modifier = 3
75
+ puts color
76
+
77
+ color = Cyan("Header")
78
+ color.bold = true
79
+ color.modifier = 4
80
+ puts color
81
+
82
+ color = Red("Header")
83
+ color.inverse_colors = true
84
+ color.bold
85
+ puts color
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork it ( https://github.com/[my-github-username]/ansi_palette/fork )
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create a new Pull Request
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => "test"
4
+
5
+ task :test do
6
+ Dir.glob("test/test*.rb").each do |file|
7
+ require_relative file
8
+ end
9
+ end
10
+
11
+ task :examples do
12
+ Dir.glob("examples/**.rb").each do |file|
13
+ require_relative file
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ansi_palette/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ansi_palette"
8
+ spec.version = AnsiPalette::VERSION
9
+ spec.authors = ["David Begin"]
10
+ spec.email = ["davidmichaelbe@gmail.com"]
11
+
12
+ spec.summary = %q{A gem for helping you color strings with ANSI escape codes.}
13
+ spec.description = %q{A gem for helping you color strings with ANSI escape codes.}
14
+ spec.homepage = "https://github.com/presidentJFK/ansi_palette"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ansi_palette"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,96 @@
1
+ require_relative "../lib/ansi_palette"
2
+
3
+ include AnsiPalette
4
+
5
+ puts "\n\n"
6
+ puts %!puts Red("hello")!
7
+ puts Red("hello")
8
+ puts "\n\n"
9
+
10
+ header = <<-HEADER
11
+ A Classy Comment Header
12
+ HEADER
13
+
14
+ body = <<-BODY
15
+ Some very interesting comment text.
16
+ With all these intricate details.
17
+ Explaining everything you could ever
18
+ want to know.
19
+ BODY
20
+
21
+ doc = <<-DOC
22
+ #{Red(header)}
23
+ #{Cyan(body)}
24
+ DOC
25
+
26
+ puts doc
27
+
28
+ color = Blue("Header")
29
+ puts color
30
+
31
+ color = Red("Header")
32
+ color.bold = true
33
+ puts color
34
+
35
+ color = Yellow("Header")
36
+ color.bold = true
37
+ color.blink = true
38
+ puts color
39
+
40
+ color = Yellow("Header")
41
+ color.bold = true
42
+ color.blink = true
43
+ color.modifier = 3
44
+ puts color
45
+
46
+ color = Cyan("Header")
47
+ color.bold = true
48
+ color.modifier = 4
49
+ puts color
50
+
51
+ color = Red("Header")
52
+ color.inverse_colors = true
53
+ color.bold
54
+ puts color
55
+
56
+ header = Red("WOAH")
57
+ header.blink = true
58
+
59
+ puts "$$$$$$$$"
60
+ puts "$ #{header} $"
61
+ puts "$$$$$$$$"
62
+
63
+ class Billboard
64
+ def initialize(text:, border: "†")
65
+ @text = text
66
+ @border = border
67
+ end
68
+
69
+ def display
70
+ puts "\n"
71
+ puts border * length
72
+ print border + " "
73
+ print text
74
+ puts " " + border
75
+ print border * length
76
+ puts "\n"
77
+ end
78
+
79
+ private
80
+
81
+ attr_reader :text, :border
82
+
83
+ def length
84
+ text.length + 4
85
+ end
86
+ end
87
+
88
+ billboad = Billboard.new(text: "DINOSAURS")
89
+ billboad.display
90
+
91
+ header = Cyan("PINOT NOIR")
92
+ header.blink = true
93
+ header.underline = true
94
+ header.bold = true
95
+ billboad = Billboard.new(text: header, border: "®")
96
+ billboad.display
@@ -0,0 +1,2 @@
1
+ require "ansi_palette/version"
2
+ require_relative "ansi_palette/colored_string"
@@ -0,0 +1,143 @@
1
+ require "forwardable"
2
+ require_relative "../ansi_palette"
3
+
4
+ module AnsiPalette
5
+ COLOR_HASH = {
6
+ :black => { :foreground => 30, :background => 40 },
7
+ :red => { :foreground => 31, :background => 41 },
8
+ :green => { :foreground => 32, :background => 42 },
9
+ :yellow => { :foreground => 33, :background => 43 },
10
+ :blue => { :foreground => 34, :background => 44 },
11
+ :magenta => { :foreground => 35, :background => 45 },
12
+ :cyan => { :foreground => 36, :background => 46 },
13
+ :white => { :foreground => 37, :background => 47 },
14
+ }
15
+
16
+ EFFECT_HASH = {
17
+ :reset => 0,
18
+ :bold => 1,
19
+ :underline => 4,
20
+ :blink => 5,
21
+ :inverse_colors => 7
22
+ }
23
+
24
+ COLOR_HASH.each_pair.each do |color, color_codes|
25
+ define_method color.to_s.capitalize do |string|
26
+ AnsiPalette::ColoredString.new(string: string, color: color)
27
+ end
28
+
29
+ define_method "Bg" + color.to_s.capitalize do |string|
30
+ AnsiPalette::ColoredString.new(string: string, background: color)
31
+ end
32
+
33
+ const_set("#{color.upcase}_FG", color_codes.fetch(:foreground))
34
+ const_set("#{color.upcase}_BG", color_codes.fetch(:background))
35
+ end
36
+
37
+ def Bold(str)
38
+ ColoredString.new(string: str, bold: true).bold
39
+ end
40
+
41
+ START_ESCAPE = "\e[" # "\033["
42
+ END_ESCAPE = "m"
43
+ RESET_COLOR = 0
44
+ class ColoredString < String
45
+ extend ::Forwardable
46
+
47
+ def initialize(string:,
48
+ color: nil,
49
+ foreground: nil,
50
+ background: nil,
51
+ modifier: nil,
52
+ bold: false,
53
+ blink: false
54
+ )
55
+
56
+ @string = string
57
+ @color = color
58
+ @modifier = modifier
59
+ @background = background
60
+ @foreground = foreground
61
+ @bold = bold
62
+ @blink = blink
63
+ end
64
+
65
+ EFFECT_HASH.keys.each do |modifier_method|
66
+ attr_accessor modifier_method
67
+ end
68
+
69
+ attr_accessor :modifier
70
+
71
+ def colored_string
72
+ set_modifiers +
73
+ set_foreground_color +
74
+ set_background_color +
75
+ string +
76
+ reset_color
77
+ end
78
+
79
+ def blink?; blink; end
80
+
81
+ def bold?; bold; end
82
+
83
+ alias_method :to_s, :colored_string
84
+ alias_method :to_str, :to_s
85
+
86
+ def_delegators :string, :length
87
+
88
+ private
89
+
90
+ attr_reader :string, :color, :modifier, :background, :foreground
91
+
92
+ def set_modifiers
93
+ set_modifier +
94
+ set_blink +
95
+ set_bold +
96
+ set_underline +
97
+ set_blink +
98
+ set_inverse_colors
99
+ end
100
+
101
+ EFFECT_HASH.each_pair do |modifier, code|
102
+ define_method "#{modifier}?" do
103
+ instance_variable_get("@#{modifier}")
104
+ end
105
+
106
+ define_method "set_#{modifier}" do
107
+ send("#{modifier}?") ? escape_sequence(code.to_s) : ""
108
+ end
109
+ end
110
+
111
+ def set_modifier
112
+ !modifier.nil? ? escape_sequence(modifier.to_s) : ""
113
+ end
114
+
115
+ def set_foreground_color
116
+ set_color(foreground_color, "_FG")
117
+ end
118
+
119
+ def set_background_color
120
+ set_color(background, "_BG")
121
+ end
122
+
123
+ def set_color(color, color_type)
124
+ return "" if color.nil?
125
+
126
+ escape_sequence(
127
+ AnsiPalette.const_get(color.to_s.upcase + color_type).to_s
128
+ )
129
+ end
130
+
131
+ def foreground_color
132
+ color || foreground
133
+ end
134
+
135
+ def reset_color
136
+ escape_sequence(RESET_COLOR.to_s)
137
+ end
138
+
139
+ def escape_sequence(content)
140
+ START_ESCAPE + content + END_ESCAPE
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,3 @@
1
+ module AnsiPalette
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansi_palette
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Begin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-13 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: A gem for helping you color strings with ANSI escape codes.
42
+ email:
43
+ - davidmichaelbe@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".codeclimate.yml"
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - ansi_palette.gemspec
57
+ - bin/console
58
+ - bin/setup
59
+ - examples/conversion.rb
60
+ - lib/ansi_palette.rb
61
+ - lib/ansi_palette/colored_string.rb
62
+ - lib/ansi_palette/version.rb
63
+ homepage: https://github.com/presidentJFK/ansi_palette
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A gem for helping you color strings with ANSI escape codes.
87
+ test_files: []
88
+ has_rdoc: