pretty_console 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/LICENCE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +8 -0
- data/lib/pretty_console/version.rb +3 -0
- data/pretty_console.gemspec +16 -0
- data/test/test_pretty_console.rb +115 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7c448cc8db805af8f24a2d0b17ab5d28b90bba1654ac053e6f0faccca8e3c3
|
4
|
+
data.tar.gz: 6e846615a2225dbc9e56352d75061a6baf6338b2512a302b1e4512293cfa0bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6422cbfaadded1686478de0f80b89a39aff3a2045f3e61f6b7dc4702614cea52ae42c324a06c6684e7b78656f3b92054ccbefd86653a729e200bc17362bba6d0
|
7
|
+
data.tar.gz: c583d214dfe4a5d316d209ee14b54c1488caefeea3270971846bf519f70a401d42964ab12ccc52ec6b6088cfccdb9e2bb1b73872d42b3fc85d2b2d85807c7f6b
|
data/.gitignore
ADDED
data/LICENCE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Joey Aghion
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# PrettyConsole
|
2
|
+
|
3
|
+
PrettyConsole adds colors to your console using the [bash colorization codes](http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html).
|
4
|
+
|
5
|
+
## Use
|
6
|
+
|
7
|
+
#### puts_in_< color >
|
8
|
+
|
9
|
+
PrettyConsole.puts_in_green('Some wording')
|
10
|
+
|
11
|
+
prints the following with standard system font
|
12
|
+
$${\color{green} Some\space wording}$$
|
13
|
+
|
14
|
+
|
15
|
+
##### Colors
|
16
|
+
where 'green' is a < color > that might be replaced with the following colors :
|
17
|
+
- red,
|
18
|
+
- green (as used)
|
19
|
+
- yellow
|
20
|
+
- blue
|
21
|
+
- purple
|
22
|
+
- cyan
|
23
|
+
- heavy_white
|
24
|
+
- and green
|
25
|
+
|
26
|
+
#### say_in_< color >
|
27
|
+
|
28
|
+
PrettyConsole.say_in_<color>('Some wording')
|
29
|
+
|
30
|
+
prints the following with standard system font
|
31
|
+
$${\color{green} =====>\space Some\space wording\space<=====}$$
|
32
|
+
|
33
|
+
#### print_in_< color >
|
34
|
+
|
35
|
+
PrettyConsole.print_in_<color>('x')
|
36
|
+
|
37
|
+
prints the following with standard system font
|
38
|
+
$${\color{green}x}$$
|
39
|
+
|
40
|
+
|
41
|
+
#### say_with_color_background
|
42
|
+
|
43
|
+
PrettyConsole.say_with_<color>_background('Some wording')
|
44
|
+
|
45
|
+
#### announce_task
|
46
|
+
|
47
|
+
desc 'your task'
|
48
|
+
task your_task: :environment do |task|
|
49
|
+
PrettyConsole.announce_task(task or string) do
|
50
|
+
...your task code
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
- prints a colored header with the task name and a footer
|
55
|
+
- it displays the time elapased inside the block
|
56
|
+
|
57
|
+
## Installation
|
58
|
+
|
59
|
+
Add this line to your application's Gemfile:
|
60
|
+
|
61
|
+
gem 'pretty_console'
|
62
|
+
|
63
|
+
And then execute:
|
64
|
+
|
65
|
+
$ bundle
|
66
|
+
|
67
|
+
Or install it yourself as:
|
68
|
+
|
69
|
+
$ gem install pretty_console
|
70
|
+
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create new Pull Request
|
79
|
+
|
80
|
+
|
81
|
+
© Etienne Weil
|
82
|
+
|
83
|
+
[LICENSE](LICENSE.txt)
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pretty_console/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "pretty_console"
|
7
|
+
s.version = PrettyConsole::VERSION
|
8
|
+
s.description = "A simple gem to colorize your console output"
|
9
|
+
s.summary = s.description
|
10
|
+
s.authors = ["Etienne Weil"]
|
11
|
+
s.email = "weil.etienne@hotmail.fr"
|
12
|
+
s.files = `git ls-files`.split($/)
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
s.homepage = "https://rubygems.org/gems/pretty_console"
|
15
|
+
s.license = "MIT"
|
16
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'pretty_console'
|
3
|
+
|
4
|
+
class PrettyConsoleTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@output = StringIO.new
|
7
|
+
@original_stdout = $stdout
|
8
|
+
$stdout = @output
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
$stdout = @original_stdout
|
13
|
+
end
|
14
|
+
|
15
|
+
class DummyTask
|
16
|
+
def name
|
17
|
+
@name
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(name)
|
21
|
+
@name = name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
PrettyConsole::COLOR_MAP.keys.each do |color|
|
26
|
+
define_method("test_say_in_#{color}") do
|
27
|
+
PrettyConsole.send("say_in_#{color}", 'Hello World')
|
28
|
+
assert_includes @output.string, PrettyConsole.express_in_color(PrettyConsole.enhance_str('Hello World'), color)
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method("test_say_in_#{color}_loudly") do
|
32
|
+
PrettyConsole.send("say_in_#{color}_loudly", 'Hello World')
|
33
|
+
assert_includes @output.string, PrettyConsole.express_in_color(PrettyConsole.enhance_str(PrettyConsole.bold('Hello World')), color)
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method("test_puts_in_#{color}") do
|
37
|
+
PrettyConsole.send("puts_in_#{color}", 'Hello World')
|
38
|
+
assert_includes @output.string, PrettyConsole.express_in_color('Hello World', color)
|
39
|
+
end
|
40
|
+
|
41
|
+
define_method("test_puts_in_#{color}_loudly") do
|
42
|
+
PrettyConsole.send("puts_in_#{color}_loudly", 'Hello World')
|
43
|
+
assert_includes @output.string, PrettyConsole.express_in_color(PrettyConsole.bold('Hello World'), color)
|
44
|
+
end
|
45
|
+
|
46
|
+
define_method("test_print_in_#{color}") do
|
47
|
+
PrettyConsole.send("print_in_#{color}", 'Hello World')
|
48
|
+
assert_includes @output.string, PrettyConsole.express_in_color('Hello World', color)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_express_in_color_with_default_map
|
52
|
+
result = PrettyConsole.express_in_color('Hello', :red)
|
53
|
+
assert_equal "\e[31mHello\e[0m", result
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_express_in_color_with_custom_map
|
57
|
+
custom_map = { red: 91 }
|
58
|
+
result = PrettyConsole.express_in_color('Hello', :red, custom_map)
|
59
|
+
assert_equal "\e[91mHello\e[0m", result
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_express_in_color_with_invalid_color
|
63
|
+
assert_includes PrettyConsole.express_in_color('Hello', :invalid_color),
|
64
|
+
"There's no method called"
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_bold
|
68
|
+
input = "Hello World"
|
69
|
+
expected_output = "\x1b[1mHello World\x1b[0m"
|
70
|
+
assert_equal expected_output, PrettyConsole.bold(input)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
def test_announce_task
|
75
|
+
task_name = "Sample Task"
|
76
|
+
PrettyConsole.announce_task(task_name) do
|
77
|
+
sleep 1
|
78
|
+
end
|
79
|
+
|
80
|
+
output = @output.string
|
81
|
+
assert_includes output, "-- Starting task : Sample Task"
|
82
|
+
assert_includes output, "-------- Task completed. Took"
|
83
|
+
assert_includes output, "-- end Sample Task ----"
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_announce_task_with_object
|
87
|
+
|
88
|
+
task = DummyTask.new(name: "Object Task")
|
89
|
+
PrettyConsole.announce_task(task) do
|
90
|
+
sleep 1
|
91
|
+
end
|
92
|
+
|
93
|
+
output = @output.string
|
94
|
+
assert_includes output, "-- Starting task : "
|
95
|
+
assert_includes output, "[0m\n\n\e[34m\e[1m-------- Task completed. Took 1."
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
PrettyConsole::BACKGROUND_COLOR_MAP.keys.each do |color|
|
100
|
+
define_method("test_say_with_#{color}_background") do
|
101
|
+
PrettyConsole.send("say_with_#{color}_background", 'Hello World')
|
102
|
+
assert_includes @output.string, PrettyConsole.express_in_color(PrettyConsole.enhance_str('Hello World'), color, PrettyConsole::BACKGROUND_COLOR_MAP)
|
103
|
+
end
|
104
|
+
|
105
|
+
define_method("test_puts_with_#{color}_background") do
|
106
|
+
PrettyConsole.send("puts_with_#{color}_background", 'Hello World')
|
107
|
+
assert_includes @output.string, PrettyConsole.express_in_color('Hello World', color, PrettyConsole::BACKGROUND_COLOR_MAP)
|
108
|
+
end
|
109
|
+
|
110
|
+
define_method("test_print_with_#{color}_background") do
|
111
|
+
PrettyConsole.send("print_with_#{color}_background", 'Hello World')
|
112
|
+
assert_includes @output.string, PrettyConsole.express_in_color('Hello World', color, PrettyConsole::BACKGROUND_COLOR_MAP)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Etienne Weil
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-09 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: A simple gem to colorize your console output
|
14
13
|
email: weil.etienne@hotmail.fr
|
@@ -16,13 +15,19 @@ executables: []
|
|
16
15
|
extensions: []
|
17
16
|
extra_rdoc_files: []
|
18
17
|
files:
|
18
|
+
- ".gitignore"
|
19
|
+
- LICENCE.txt
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
19
22
|
- lib/pretty_console.rb
|
20
23
|
- lib/pretty_console/invalid_color_error.rb
|
24
|
+
- lib/pretty_console/version.rb
|
25
|
+
- pretty_console.gemspec
|
26
|
+
- test/test_pretty_console.rb
|
21
27
|
homepage: https://rubygems.org/gems/pretty_console
|
22
28
|
licenses:
|
23
29
|
- MIT
|
24
30
|
metadata: {}
|
25
|
-
post_install_message:
|
26
31
|
rdoc_options: []
|
27
32
|
require_paths:
|
28
33
|
- lib
|
@@ -37,8 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
42
|
- !ruby/object:Gem::Version
|
38
43
|
version: '0'
|
39
44
|
requirements: []
|
40
|
-
rubygems_version: 3.5
|
41
|
-
signing_key:
|
45
|
+
rubygems_version: 3.6.5
|
42
46
|
specification_version: 4
|
43
|
-
summary:
|
44
|
-
test_files:
|
47
|
+
summary: A simple gem to colorize your console output
|
48
|
+
test_files:
|
49
|
+
- test/test_pretty_console.rb
|