formatador 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +18 -0
- data/CONTRIBUTORS.md +16 -0
- data/LICENSE.md +20 -0
- data/{README.rdoc → README.md} +95 -41
- data/Rakefile +2 -8
- data/changelog.txt +44 -0
- data/formatador.gemspec +10 -6
- data/lib/formatador/progressbar.rb +31 -0
- data/lib/formatador/table.rb +9 -2
- data/lib/formatador.rb +21 -20
- data/tests/table_tests.rb +20 -1
- data/tests/tests_helper.rb +12 -0
- metadata +46 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58153bcd41291dcdd4aa4bbcfb724d233604d130470634682306fb0e8859f041
|
4
|
+
data.tar.gz: 20d3a52adff269f0a29fc6c1dda6dd87679151fa13bc496f0fbb1a7edc3ae07b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12616b0af1aea1c3b5ee100440096e7b8def45f9ed5340efd98bbc958384005b80cb9dde10d16e0f443f8520b7466a67d93fe5d03a980a19988c3db9e08eef0f
|
7
|
+
data.tar.gz: 7fd4a23d9cd157ed4e86dcec4ad15cbd277220c1c62346f36d414af5aac1db8a634a57e952073cca1feb015c039cd777b18dbbb9fadf24c983025ee4bdbf7e01
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
## Getting Involved
|
2
|
+
|
3
|
+
New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
|
4
|
+
|
5
|
+
### Coding
|
6
|
+
|
7
|
+
* Pick a task:
|
8
|
+
* Offer feedback on open [pull requests](https://github.com/geemus/formatador/pulls).
|
9
|
+
* Review open [issues](https://github.com/geemus/formatador/issues) for things to help on.
|
10
|
+
* [Create an issue](https://github.com/geemus/formatador/issues/new) to start a discussion on additions or features.
|
11
|
+
* Fork the project, add your changes and tests to cover them in a topic branch.
|
12
|
+
* Commit your changes and rebase against `geemus/formatador` to ensure everything is up to date.
|
13
|
+
* [Submit a pull request](https://github.com/geemus/formatador/compare/).
|
14
|
+
|
15
|
+
### Non-Coding
|
16
|
+
|
17
|
+
* Offer feedback on open [issues](https://github.com/geemus/formatador/issues).
|
18
|
+
* Organize or volunteer at events.
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
* Bohuslav Kabrda <bkabrda@redhat.com>
|
2
|
+
* Chris Howe <chris@howeville.com>
|
3
|
+
* Damien Pollet <damien.pollet@gmail.com>
|
4
|
+
* Daniel Lv <lgn21st@gmail.com>
|
5
|
+
* Gabe Martin-Dempesy <gabe@mudbugmedia.com>
|
6
|
+
* Kevin Menard <nirvdrum@gmail.com>
|
7
|
+
* Mal Curtis <mal@sitepoint.com>
|
8
|
+
* Matt Bridges <mbridges.91@gmail.com>
|
9
|
+
* Matt Petty <matt@kizmeta.com>
|
10
|
+
* Nathaniel Eliot <temujin9@t9productions.com>
|
11
|
+
* Wesley Beary <geemus@engineyard.com>
|
12
|
+
* Wesley Beary <geemus@gmail.com>
|
13
|
+
* Wesley Beary <wbeary@engineyard.com>
|
14
|
+
* Wesley Beary <wesley@heroku.com>
|
15
|
+
* geemus (Wesley Beary) <wbeary@engineyard.com>
|
16
|
+
* geemus <geemus@gmail.com>
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2009-2013 [CONTRIBUTORS.md](https://github.com/geemus/formatador/blob/master/CONTRIBUTORS.md)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,75 +1,129 @@
|
|
1
|
-
|
1
|
+
# formatador
|
2
2
|
|
3
3
|
STDOUT text formatting
|
4
4
|
|
5
|
-
|
5
|
+
[![Build Status](https://github.com/geemus/formatador/actions/workflows/ruby.yml/badge.svg)](https://github.com/geemus/formatador/actions/workflows/ruby.yml)
|
6
|
+
|
7
|
+
## Quick and dirty
|
6
8
|
|
7
9
|
You can call class methods to print out single lines like this:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
Formatador.display_line('Hello World')
|
13
|
+
```
|
10
14
|
|
11
15
|
You use tags, similar to html, to set formatting options:
|
12
16
|
|
13
|
-
|
17
|
+
```ruby
|
18
|
+
Formatador.display_line('[green]Hello World[/]')
|
19
|
+
```
|
14
20
|
|
15
|
-
|
21
|
+
`[/]` resets everything to normal, colors are supported and `[_color_]` sets the background color.
|
16
22
|
|
17
|
-
|
23
|
+
## Standard options
|
18
24
|
|
19
25
|
* format - and adds color codes if STDOUT.tty? is true
|
20
26
|
* display - calls format on the input and prints it
|
21
27
|
* display_line - calls display, but adds on a newline (\n)
|
22
28
|
* redisplay - Displays text, prepended with \r which will overwrite the last existing line
|
23
29
|
|
24
|
-
|
30
|
+
## Extensions
|
25
31
|
|
26
32
|
* display_table: takes an array of hashes. Each hash is a row, with the keys being the headers and values being the data. An optional second argument can specify which headers/columns to include and in what order they should appear.
|
27
33
|
* display_compact_table: Same as display_table, execpt that split lines are not drawn by default in the body of the table. If you need a split line, put a :split constant in the body array.
|
28
34
|
* redisplay_progressbar: takes the current and total values as its first two arguments and redisplays a progressbar (until current = total and then it display_lines). An optional third argument represents the start time and will add an elapsed time counter.
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
### Progress Bar examples
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
total = 1000
|
40
|
+
progress = Formatador::ProgressBar.new(total)
|
41
|
+
|
42
|
+
1000.times do
|
43
|
+
progress.increment
|
44
|
+
end
|
45
|
+
|
46
|
+
#=> 978/1000 |************************************************* |
|
47
|
+
|
48
|
+
# Change the color of the bar
|
49
|
+
total = 1000
|
50
|
+
progress = Formatador::ProgressBar.new(total, :color => "light_blue")
|
51
|
+
|
52
|
+
1000.times do
|
53
|
+
progress.increment
|
54
|
+
end
|
55
|
+
|
56
|
+
# Change the color of a completed progress bar
|
57
|
+
total = 1000
|
58
|
+
progress = Formatador::ProgressBar.new(total) { |b| b.opts[:color] = "green" }
|
59
|
+
|
60
|
+
1000.times do
|
61
|
+
progress.increment
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
### Table examples
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
table_data = [
|
69
|
+
{ :name => "Joe", :food => "Burger" },
|
70
|
+
{ :name => "Bill", :food => "French fries" }
|
71
|
+
]
|
72
|
+
Formatador.display_table(table_data)
|
73
|
+
|
74
|
+
#=> +------+--------------+
|
75
|
+
# | name | food |
|
76
|
+
# +------+--------------+
|
77
|
+
# | Joe | Burger |
|
78
|
+
# +------+--------------+
|
79
|
+
# | Bill | French fries |
|
80
|
+
# +------+--------------+
|
81
|
+
|
82
|
+
table_data = [
|
83
|
+
{
|
84
|
+
:name => "Joe",
|
85
|
+
:meal => {
|
86
|
+
:main_dish => "Burger",
|
87
|
+
:drink => "water"
|
88
|
+
}
|
89
|
+
},
|
90
|
+
{
|
91
|
+
:name => "Bill",
|
92
|
+
:meal => {
|
93
|
+
:main_dish => "Chicken",
|
94
|
+
:drink => "soda"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
]
|
98
|
+
Formatador.display_table(table_data, [:name, :"meal.drink"])
|
48
99
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
100
|
+
#=> +------+------------+
|
101
|
+
# | name | meal.drink |
|
102
|
+
# +------+------------+
|
103
|
+
# | Joe | water |
|
104
|
+
# +------+------------+
|
105
|
+
# | Bill | soda |
|
106
|
+
# +------+------------+
|
107
|
+
```
|
56
108
|
|
57
|
-
|
109
|
+
## Indentation
|
58
110
|
|
59
111
|
By initializing a formatador object you can keep track of indentation:
|
60
112
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
113
|
+
```ruby
|
114
|
+
formatador = Formatador.new
|
115
|
+
formatador.display_line('one level of indentation')
|
116
|
+
formatador.indent {
|
117
|
+
formatador.display_line('two levels of indentation')
|
118
|
+
}
|
119
|
+
formatador.display_line('one level of indentation')
|
120
|
+
```
|
67
121
|
|
68
|
-
|
122
|
+
## Copyright
|
69
123
|
|
70
124
|
(The MIT License)
|
71
125
|
|
72
|
-
Copyright (c)
|
126
|
+
Copyright (c) 2022 [geemus (Wesley Beary)](http://github.com/geemus)
|
73
127
|
|
74
128
|
Permission is hereby granted, free of charge, to any person obtaining
|
75
129
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -21,10 +21,6 @@ def date
|
|
21
21
|
Date.today.to_s
|
22
22
|
end
|
23
23
|
|
24
|
-
def rubyforge_project
|
25
|
-
name
|
26
|
-
end
|
27
|
-
|
28
24
|
def gemspec_file
|
29
25
|
"#{name}.gemspec"
|
30
26
|
end
|
@@ -56,7 +52,7 @@ task :coverage do
|
|
56
52
|
sh "open coverage/index.html"
|
57
53
|
end
|
58
54
|
|
59
|
-
require '
|
55
|
+
require 'rdoc/task'
|
60
56
|
Rake::RDocTask.new do |rdoc|
|
61
57
|
rdoc.rdoc_dir = 'rdoc'
|
62
58
|
rdoc.title = "#{name} #{version}"
|
@@ -88,7 +84,7 @@ task :release => :build do
|
|
88
84
|
puts "You must be on the master branch to release!"
|
89
85
|
exit!
|
90
86
|
end
|
91
|
-
sh "
|
87
|
+
sh "gem install pkg/#{name}-#{version}.gem"
|
92
88
|
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
93
89
|
sh "git tag v#{version}"
|
94
90
|
sh "git push origin master"
|
@@ -111,8 +107,6 @@ task :gemspec => :validate do
|
|
111
107
|
replace_header(head, :name)
|
112
108
|
replace_header(head, :version)
|
113
109
|
replace_header(head, :date)
|
114
|
-
#comment this out if your rubyforge_project has a different name
|
115
|
-
replace_header(head, :rubyforge_project)
|
116
110
|
|
117
111
|
# determine file list from git ls-files
|
118
112
|
files = `git ls-files`.
|
data/changelog.txt
CHANGED
@@ -1,3 +1,47 @@
|
|
1
|
+
v1.0.0 01/20/21
|
2
|
+
===============
|
3
|
+
|
4
|
+
release v1, it's been stable for ages
|
5
|
+
|
6
|
+
v0.3.0 06/17/21
|
7
|
+
===============
|
8
|
+
|
9
|
+
add travis badge to readme
|
10
|
+
change readme to md
|
11
|
+
fix markdown readme
|
12
|
+
fix travis badge
|
13
|
+
monkey-patch StringIO to try and fix jruby build
|
14
|
+
override tty? for jruby build
|
15
|
+
fix copyright statement
|
16
|
+
use unicode.width instead of string.length
|
17
|
+
remove unicode from requirements, use only if loaded
|
18
|
+
display datum who's value is a FalseClass
|
19
|
+
more colors with syntax-specific code/length limitations
|
20
|
+
better code visualization in readme
|
21
|
+
update readme
|
22
|
+
remove broken rubinius build from CI
|
23
|
+
fix length method to detect multibyte char width
|
24
|
+
fix test for table with multi byte chars
|
25
|
+
support multibyte characters
|
26
|
+
update CI to 2.2.7, 2.3.4, and 2.4.1
|
27
|
+
drop rubyforge_project from gemspec and rakefile
|
28
|
+
change github reference to https
|
29
|
+
change readme.rdoc to readme.md in gemspec
|
30
|
+
|
31
|
+
v0.2.5 05/23/14
|
32
|
+
===============
|
33
|
+
|
34
|
+
* fix typo in readme
|
35
|
+
* ensure indent is reset
|
36
|
+
* add progress bar object
|
37
|
+
* improve thread safety for progress bar
|
38
|
+
|
39
|
+
v0.2.4 10/26/12
|
40
|
+
===============
|
41
|
+
|
42
|
+
* sort background colors higher
|
43
|
+
* fix homepage link in gem metadata
|
44
|
+
|
1
45
|
v0.2.3 05/18/12
|
2
46
|
===============
|
3
47
|
|
data/formatador.gemspec
CHANGED
@@ -13,9 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'formatador'
|
16
|
-
s.version = '0.
|
17
|
-
s.date = '
|
18
|
-
s.rubyforge_project = 'formatador'
|
16
|
+
s.version = '1.0.0'
|
17
|
+
s.date = '2022-01-20'
|
19
18
|
|
20
19
|
## Make sure your summary is short. The description may be as long
|
21
20
|
## as you like.
|
@@ -27,7 +26,8 @@ Gem::Specification.new do |s|
|
|
27
26
|
## a custom homepage, consider using your GitHub URL or the like.
|
28
27
|
s.authors = ["geemus (Wesley Beary)"]
|
29
28
|
s.email = 'geemus@gmail.com'
|
30
|
-
s.homepage =
|
29
|
+
s.homepage = "https://github.com/geemus/#{s.name}"
|
30
|
+
s.license = 'MIT'
|
31
31
|
|
32
32
|
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
33
|
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
## Specify any RDoc options here. You'll want to add your README and
|
45
45
|
## LICENSE files to the extra_rdoc_files list.
|
46
46
|
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
-
s.extra_rdoc_files = %w[README.
|
47
|
+
s.extra_rdoc_files = %w[README.md]
|
48
48
|
|
49
49
|
## List your runtime dependencies here. Runtime dependencies are those
|
50
50
|
## that are needed for an end user to actually USE your code.
|
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
|
|
53
53
|
## List your development dependencies here. Development dependencies are
|
54
54
|
## those that are only needed during development
|
55
55
|
s.add_development_dependency('rake')
|
56
|
+
s.add_development_dependency('rdoc')
|
56
57
|
s.add_development_dependency('shindo')
|
57
58
|
|
58
59
|
## Leave this section as-is. It will be automatically generated from the
|
@@ -60,8 +61,11 @@ Gem::Specification.new do |s|
|
|
60
61
|
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
61
62
|
# = MANIFEST =
|
62
63
|
s.files = %w[
|
64
|
+
CONTRIBUTING.md
|
65
|
+
CONTRIBUTORS.md
|
63
66
|
Gemfile
|
64
|
-
|
67
|
+
LICENSE.md
|
68
|
+
README.md
|
65
69
|
Rakefile
|
66
70
|
changelog.txt
|
67
71
|
formatador.gemspec
|
@@ -1,5 +1,36 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
class Formatador
|
2
4
|
|
5
|
+
class ProgressBar
|
6
|
+
|
7
|
+
attr_accessor :current, :total, :opts
|
8
|
+
|
9
|
+
def initialize(total, opts = {}, &block)
|
10
|
+
@current = opts.delete(:start) || 0
|
11
|
+
@total = total.to_i
|
12
|
+
@opts = opts
|
13
|
+
@lock = Mutex.new
|
14
|
+
@complete_proc = block_given? ? block : Proc.new { }
|
15
|
+
end
|
16
|
+
|
17
|
+
def increment(increment = 1)
|
18
|
+
@lock.synchronize do
|
19
|
+
return if complete?
|
20
|
+
@current += increment.to_i
|
21
|
+
@complete_proc.call(self) if complete?
|
22
|
+
Formatador.redisplay_progressbar(current, total, opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def complete?
|
29
|
+
current == total
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
3
34
|
def redisplay_progressbar(current, total, options = {})
|
4
35
|
options = { :color => 'white', :width => 50, :new_line => true }.merge!(options)
|
5
36
|
data = progressbar(current, total, options)
|
data/lib/formatador/table.rb
CHANGED
@@ -80,7 +80,14 @@ class Formatador
|
|
80
80
|
private
|
81
81
|
|
82
82
|
def length(value)
|
83
|
-
|
83
|
+
if Module.const_defined?(:Unicode)
|
84
|
+
Unicode.width(value.to_s.gsub(PARSE_REGEX, ''))
|
85
|
+
else
|
86
|
+
value.to_s.gsub(PARSE_REGEX, '').chars.reduce(0) { |sum, char| sum += char.bytesize > 1 ? 2 : 1 }
|
87
|
+
end
|
88
|
+
|
89
|
+
rescue NotImplementedError
|
90
|
+
value.to_s.gsub(PARSE_REGEX, '').chars.reduce(0) { |sum, char| sum += char.bytesize > 1 ? 2 : 1 }
|
84
91
|
end
|
85
92
|
|
86
93
|
def calculate_datum(header, hash)
|
@@ -91,7 +98,7 @@ class Formatador
|
|
91
98
|
datum = d[split] || d[split.to_sym] || ''
|
92
99
|
end
|
93
100
|
else
|
94
|
-
datum = hash
|
101
|
+
datum = hash.fetch(header, '')
|
95
102
|
end
|
96
103
|
datum
|
97
104
|
end
|
data/lib/formatador.rb
CHANGED
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'formatador', 'progressbar')
|
|
3
3
|
|
4
4
|
class Formatador
|
5
5
|
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '1.0.0'
|
7
7
|
|
8
8
|
STYLES = {
|
9
9
|
:"\/" => "0",
|
@@ -17,15 +17,6 @@ class Formatador
|
|
17
17
|
:underline_none => "24",
|
18
18
|
:blink_off => "25",
|
19
19
|
:positive => "27", # revert color/color
|
20
|
-
:black => "30",
|
21
|
-
:red => "31",
|
22
|
-
:green => "32",
|
23
|
-
:yellow => "33",
|
24
|
-
:blue => "34",
|
25
|
-
:magenta => "35",
|
26
|
-
:purple => "35",
|
27
|
-
:cyan => "36",
|
28
|
-
:white => "37",
|
29
20
|
:_black_ => "40",
|
30
21
|
:_red_ => "41",
|
31
22
|
:_green_ => "42",
|
@@ -35,14 +26,6 @@ class Formatador
|
|
35
26
|
:_purple_ => "45",
|
36
27
|
:_cyan_ => "46",
|
37
28
|
:_white_ => "47",
|
38
|
-
:light_black => "90",
|
39
|
-
:light_red => "91",
|
40
|
-
:light_green => "92",
|
41
|
-
:light_yellow => "93",
|
42
|
-
:light_blue => "94",
|
43
|
-
:light_magenta => "95",
|
44
|
-
:light_purple => "95",
|
45
|
-
:light_cyan => "96",
|
46
29
|
:_light_black_ => "100",
|
47
30
|
:_light_red_ => "101",
|
48
31
|
:_light_green_ => "102",
|
@@ -51,6 +34,23 @@ class Formatador
|
|
51
34
|
:_light_magenta_ => "105",
|
52
35
|
:_light_purple_ => "105",
|
53
36
|
:_light_cyan_ => "106",
|
37
|
+
:black => "30",
|
38
|
+
:red => "31",
|
39
|
+
:green => "32",
|
40
|
+
:yellow => "33",
|
41
|
+
:blue => "34",
|
42
|
+
:magenta => "35",
|
43
|
+
:purple => "35",
|
44
|
+
:cyan => "36",
|
45
|
+
:white => "37",
|
46
|
+
:light_black => "90",
|
47
|
+
:light_red => "91",
|
48
|
+
:light_green => "92",
|
49
|
+
:light_yellow => "93",
|
50
|
+
:light_blue => "94",
|
51
|
+
:light_magenta => "95",
|
52
|
+
:light_purple => "95",
|
53
|
+
:light_cyan => "96",
|
54
54
|
}
|
55
55
|
|
56
56
|
PARSE_REGEX = /\[(#{ STYLES.keys.join('|') })\]/ix
|
@@ -62,7 +62,7 @@ class Formatador
|
|
62
62
|
|
63
63
|
def display(string = '')
|
64
64
|
print(parse("[indent]#{string}"))
|
65
|
-
|
65
|
+
$stdout.flush
|
66
66
|
nil
|
67
67
|
end
|
68
68
|
|
@@ -80,7 +80,7 @@ class Formatador
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def parse(string)
|
83
|
-
if
|
83
|
+
if $stdout.tty?
|
84
84
|
string.gsub(PARSE_REGEX) { "\e[#{STYLES[$1.to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
|
85
85
|
else
|
86
86
|
strip(string)
|
@@ -90,6 +90,7 @@ class Formatador
|
|
90
90
|
def indent(&block)
|
91
91
|
@indent += 1
|
92
92
|
yield
|
93
|
+
ensure
|
93
94
|
@indent -= 1
|
94
95
|
end
|
95
96
|
|
data/tests/table_tests.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
Shindo.tests("Formatador: tables") do
|
2
3
|
|
3
4
|
output = <<-OUTPUT
|
@@ -93,4 +94,22 @@ output = Formatador.parse(output)
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
|
97
|
+
|
98
|
+
output = <<-OUTPUT
|
99
|
+
+------+
|
100
|
+
| [bold]a[/] |
|
101
|
+
+------+
|
102
|
+
| 1 |
|
103
|
+
+------+
|
104
|
+
| 震度 |
|
105
|
+
+------+
|
106
|
+
OUTPUT
|
107
|
+
output = Formatador.parse(output)
|
108
|
+
|
109
|
+
tests("#display_table([{:a => 1}, {:a => '震度'}])").returns(output) do
|
110
|
+
capture_stdout do
|
111
|
+
Formatador.display_table([{:a => 1}, {:a => "震度"}])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/tests/tests_helper.rb
CHANGED
metadata
CHANGED
@@ -1,47 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatador
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- geemus (Wesley Beary)
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
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: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
25
41
|
- !ruby/object:Gem::Dependency
|
26
42
|
name: shindo
|
27
|
-
requirement:
|
28
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
29
44
|
requirements:
|
30
|
-
- -
|
45
|
+
- - ">="
|
31
46
|
- !ruby/object:Gem::Version
|
32
47
|
version: '0'
|
33
48
|
type: :development
|
34
49
|
prerelease: false
|
35
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
36
55
|
description: STDOUT text formatting
|
37
56
|
email: geemus@gmail.com
|
38
57
|
executables: []
|
39
58
|
extensions: []
|
40
59
|
extra_rdoc_files:
|
41
|
-
- README.
|
60
|
+
- README.md
|
42
61
|
files:
|
62
|
+
- CONTRIBUTING.md
|
63
|
+
- CONTRIBUTORS.md
|
43
64
|
- Gemfile
|
44
|
-
-
|
65
|
+
- LICENSE.md
|
66
|
+
- README.md
|
45
67
|
- Rakefile
|
46
68
|
- changelog.txt
|
47
69
|
- formatador.gemspec
|
@@ -51,29 +73,28 @@ files:
|
|
51
73
|
- tests/basic_tests.rb
|
52
74
|
- tests/table_tests.rb
|
53
75
|
- tests/tests_helper.rb
|
54
|
-
homepage:
|
55
|
-
licenses:
|
56
|
-
|
76
|
+
homepage: https://github.com/geemus/formatador
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
57
81
|
rdoc_options:
|
58
|
-
- --charset=UTF-8
|
82
|
+
- "--charset=UTF-8"
|
59
83
|
require_paths:
|
60
84
|
- lib
|
61
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
86
|
requirements:
|
64
|
-
- -
|
87
|
+
- - ">="
|
65
88
|
- !ruby/object:Gem::Version
|
66
89
|
version: '0'
|
67
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
91
|
requirements:
|
70
|
-
- -
|
92
|
+
- - ">="
|
71
93
|
- !ruby/object:Gem::Version
|
72
94
|
version: '0'
|
73
95
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
signing_key:
|
96
|
+
rubygems_version: 3.2.15
|
97
|
+
signing_key:
|
77
98
|
specification_version: 2
|
78
99
|
summary: Ruby STDOUT text formatting
|
79
100
|
test_files: []
|