incolor 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +2 -0
  5. data/incolor.gemspec +18 -0
  6. data/lib/incolor.rb +56 -0
  7. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bb79e4df44d4d492090846aae884a7cf36607d1b3aead4de71a83dfcae32b93
4
+ data.tar.gz: eec540ac012175eb1e6fdd5da5845bf6cd8f7cc68e8e1c570139476ee9796184
5
+ SHA512:
6
+ metadata.gz: c779c6f1ad78b8da2f936cc888c9160a5c66462f3efbfb13b3726680eae61ab7deee0d72a8d5dc09ee374fab71b298e8dc46956d7fef98e7ff9e13f2bf1be9c2
7
+ data.tar.gz: df36ddb681733a829db82d259a25fe9faf1d4b828e9fca031208d28dcfbf77c41c494d762d1c74bfeb83017c857ad64d7b5bdb06ee71b6f0280db2d4b1505199
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Pavel Nazarov
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # ruby-incolor
2
+ Library for output colorizing
data/incolor.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'incolor'
3
+ spec.version = '0.1'
4
+ spec.authors = ['Pavel Nazarov']
5
+ spec.email = ['nazarov.pn@gmail.com']
6
+ spec.licenses = ['MIT']
7
+
8
+ spec.summary = 'Library for output colorizing'
9
+ spec.description = 'Library for output colorizing'
10
+ spec.homepage = 'https://github.com/alsvartr/ruby-incolor'
11
+
12
+ spec.required_ruby_version = '>= 2.0.0'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = 'exe'
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ['lib']
18
+ end
data/lib/incolor.rb ADDED
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ # incolor.rb - Library for colorizing console output
3
+ #
4
+ # This file is part of the incolor project
5
+ # Copyright (C) 2010 Pavel Nazarov
6
+
7
+ class String
8
+ @@colors = Hash[
9
+ 'reset' => '0',
10
+ 'bold' => '1',
11
+ 'ul' => '4',
12
+ 'frame' => '7',
13
+ 'black' => '30',
14
+ 'red' => '31',
15
+ 'green' => '32',
16
+ 'yellow' => '33',
17
+ 'blue' => '34',
18
+ 'pink' => '35',
19
+ 'cyan' => '36',
20
+ 'white' => '37',
21
+ ]
22
+
23
+ def tags?
24
+ if self =~ /<.+?>.+?\/>/
25
+ return true
26
+ else return false
27
+ end
28
+ end
29
+
30
+ def colorize(string)
31
+ string.scan(/<.+?>.+?\/>/) do |s|
32
+ color = s.scan(/<[a-z]+>/)[0][1..-2]
33
+ text = s.scan(/>.+\//)[0][1..-2]
34
+ code = "\e[#{@@colors[color]}m"
35
+ std = "\e[#{@@colors['reset']}m"
36
+
37
+ string = string.sub(s, "#{code}#{text}#{std}")
38
+ end
39
+
40
+ return string
41
+ end
42
+
43
+ def incolor
44
+ string = self
45
+ until string.tags? == false
46
+ string = colorize(string)
47
+ end
48
+
49
+ begin
50
+ printf string
51
+ rescue
52
+ puts string
53
+ end
54
+ end
55
+
56
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: incolor
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Nazarov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library for output colorizing
14
+ email:
15
+ - nazarov.pn@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - LICENSE
22
+ - README.md
23
+ - incolor.gemspec
24
+ - lib/incolor.rb
25
+ homepage: https://github.com/alsvartr/ruby-incolor
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.0
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubygems_version: 3.4.13
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Library for output colorizing
48
+ test_files: []