formatador 0.2.5 → 0.3.0
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 +5 -13
- data/{README.rdoc → README.md} +95 -67
- data/Rakefile +1 -7
- data/changelog.txt +25 -0
- data/formatador.gemspec +7 -6
- data/lib/formatador.rb +3 -3
- data/lib/formatador/table.rb +9 -2
- data/tests/table_tests.rb +20 -1
- data/tests/tests_helper.rb +12 -0
- metadata +32 -19
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MGRkYmM5ZGM0OTliYjI4NjEwY2M3NDZmYWI2NWYwOTZjM2ZkOWExMw==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 371ea2974db0d03751e1a559433313ef4f7e7c2c46cabba41f004dba91632065
|
4
|
+
data.tar.gz: 05ee97c7103cb73f5a6ee26e135a828f2c8d738937409a933c379f66b0f2cd76
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MmU0ZjEwZTVhOTdlZWU3ZGYyOTE5YTc3YTA4Y2MxNDM3MDQyYmY0ZjMzNmY3
|
11
|
-
YTIxNDY1MDMwM2ZiOGI1MzQ3ODJiYWRlZmNiMzIyOWFmNzBiZDY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzcyNzFhYTk2ODI2YjUzZTlhZTAxNWI0MTYzZmJlNGY2MjU2Y2M5MTAxY2Fl
|
14
|
-
OTViZGRlMWVlODgwMWNmOWExNTZlYWY5YzFhNjc4Yzg3Y2IxZDQ5YjJjN2Iw
|
15
|
-
OWUyYjI5ZjAyNDg3Mzk0YmVlMDA5MmU0ZDU3ZmMxOTUyYzRjNjI=
|
6
|
+
metadata.gz: dbec7dda7093e08b69ff2372fbbff210cc7d6bde6f2d03e6ca5bf4ed03ff0e75ed7791c4a53812f7f1804c11ed801fbad3acadc71dd48a769977f42cde522ddc
|
7
|
+
data.tar.gz: 54c7902a6d39b65d929c02f9f66c490f27753c3aec04d27c3921b33f8d3a49bc9524965d52eaac0fdd14a7892f0797d38f0e5c758d6c55dd026d465517160e4b
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,101 +1,129 @@
|
|
1
|
-
|
1
|
+
# formatador
|
2
2
|
|
3
3
|
STDOUT text formatting
|
4
4
|
|
5
|
-
|
5
|
+
[](http://travis-ci.org/geemus/formatador)
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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"])
|
74
99
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
100
|
+
#=> +------+------------+
|
101
|
+
# | name | meal.drink |
|
102
|
+
# +------+------------+
|
103
|
+
# | Joe | water |
|
104
|
+
# +------+------------+
|
105
|
+
# | Bill | soda |
|
106
|
+
# +------+------------+
|
107
|
+
```
|
82
108
|
|
83
|
-
|
109
|
+
## Indentation
|
84
110
|
|
85
111
|
By initializing a formatador object you can keep track of indentation:
|
86
112
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
+
```
|
93
121
|
|
94
|
-
|
122
|
+
## Copyright
|
95
123
|
|
96
124
|
(The MIT License)
|
97
125
|
|
98
|
-
Copyright (c)
|
126
|
+
Copyright (c) 2015 [geemus (Wesley Beary)](http://github.com/geemus)
|
99
127
|
|
100
128
|
Permission is hereby granted, free of charge, to any person obtaining
|
101
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}"
|
@@ -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,28 @@
|
|
1
|
+
v0.3.0 06/17/21
|
2
|
+
===============
|
3
|
+
|
4
|
+
add travis badge to readme
|
5
|
+
change readme to md
|
6
|
+
fix markdown readme
|
7
|
+
fix travis badge
|
8
|
+
monkey-patch StringIO to try and fix jruby build
|
9
|
+
override tty? for jruby build
|
10
|
+
fix copyright statement
|
11
|
+
use unicode.width instead of string.length
|
12
|
+
remove unicode from requirements, use only if loaded
|
13
|
+
display datum who's value is a FalseClass
|
14
|
+
more colors with syntax-specific code/length limitations
|
15
|
+
better code visualization in readme
|
16
|
+
update readme
|
17
|
+
remove broken rubinius build from CI
|
18
|
+
fix length method to detect multibyte char width
|
19
|
+
fix test for table with multi byte chars
|
20
|
+
support multibyte characters
|
21
|
+
update CI to 2.2.7, 2.3.4, and 2.4.1
|
22
|
+
drop rubyforge_project from gemspec and rakefile
|
23
|
+
change github reference to https
|
24
|
+
change readme.rdoc to readme.md in gemspec
|
25
|
+
|
1
26
|
v0.2.5 05/23/14
|
2
27
|
===============
|
3
28
|
|
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 = '0.3.0'
|
17
|
+
s.date = '2021-06-17'
|
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
|
@@ -64,7 +65,7 @@ Gem::Specification.new do |s|
|
|
64
65
|
CONTRIBUTORS.md
|
65
66
|
Gemfile
|
66
67
|
LICENSE.md
|
67
|
-
README.
|
68
|
+
README.md
|
68
69
|
Rakefile
|
69
70
|
changelog.txt
|
70
71
|
formatador.gemspec
|
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 = '0.3.0'
|
7
7
|
|
8
8
|
STYLES = {
|
9
9
|
:"\/" => "0",
|
@@ -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)
|
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/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 => 2}])").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,41 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatador
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus (Wesley Beary)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
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
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: shindo
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description: STDOUT text formatting
|
@@ -43,13 +57,13 @@ email: geemus@gmail.com
|
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
45
59
|
extra_rdoc_files:
|
46
|
-
- README.
|
60
|
+
- README.md
|
47
61
|
files:
|
48
62
|
- CONTRIBUTING.md
|
49
63
|
- CONTRIBUTORS.md
|
50
64
|
- Gemfile
|
51
65
|
- LICENSE.md
|
52
|
-
- README.
|
66
|
+
- README.md
|
53
67
|
- Rakefile
|
54
68
|
- changelog.txt
|
55
69
|
- formatador.gemspec
|
@@ -59,29 +73,28 @@ files:
|
|
59
73
|
- tests/basic_tests.rb
|
60
74
|
- tests/table_tests.rb
|
61
75
|
- tests/tests_helper.rb
|
62
|
-
homepage:
|
63
|
-
licenses:
|
76
|
+
homepage: https://github.com/geemus/formatador
|
77
|
+
licenses:
|
78
|
+
- MIT
|
64
79
|
metadata: {}
|
65
|
-
post_install_message:
|
80
|
+
post_install_message:
|
66
81
|
rdoc_options:
|
67
|
-
- --charset=UTF-8
|
82
|
+
- "--charset=UTF-8"
|
68
83
|
require_paths:
|
69
84
|
- lib
|
70
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
86
|
requirements:
|
72
|
-
- -
|
87
|
+
- - ">="
|
73
88
|
- !ruby/object:Gem::Version
|
74
89
|
version: '0'
|
75
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
91
|
requirements:
|
77
|
-
- -
|
92
|
+
- - ">="
|
78
93
|
- !ruby/object:Gem::Version
|
79
94
|
version: '0'
|
80
95
|
requirements: []
|
81
|
-
|
82
|
-
|
83
|
-
signing_key:
|
96
|
+
rubygems_version: 3.2.15
|
97
|
+
signing_key:
|
84
98
|
specification_version: 2
|
85
99
|
summary: Ruby STDOUT text formatting
|
86
100
|
test_files: []
|
87
|
-
has_rdoc:
|