terminal-table-unicode 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/terminal-table-unicode.rb +1 -0
- data/lib/terminal/table/cell.rb +13 -0
- data/lib/terminal/table/table.rb +29 -0
- data/lib/terminal/table/unicode.rb +7 -0
- data/lib/terminal/table/unicode/ext/string.rb +39 -0
- data/lib/terminal/table/unicode/version.rb +7 -0
- data/terminal-table-unicode.gemspec +27 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfbb9d722b0dce32d8677ae6cfb24a32c6f8edcc
|
4
|
+
data.tar.gz: e6ed0733d12e7aa0d8dd7789d43a3a1a6344cf08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66d64e24776584ccd94df3c2da6a7677a66347c62a1556c6d31fb7805d65f9b33ee602c19878393bd89e1536b2a053c87fc2b01a2c81d28caa1aeeaada6eccd0
|
7
|
+
data.tar.gz: fb76b53657778d9153fcceaa58b68a90aa4eeca3829805c1bc1977aa3ba97dd33b117457e053d22bad667a255736b0583fe1753cd4f170cbfaefb75c219e6b7f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# terminal-table-unicode
|
2
|
+
|
3
|
+
[tj/terminal-table](https://github.com/tj/terminal-table) is a great rubygems. But it has a probrem that can deal with [full-width unicode characters](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms#Fullwidth_form). terminal-table-unicode solved that.
|
4
|
+
I referred to [miaout17/hirb-unicode](https://github.com/miaout17/hirb-unicode).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'terminal-table-unicode'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install terminal-table-unicode
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'terminal-table-unicode'
|
26
|
+
rows = []
|
27
|
+
rows << ['One', 1]
|
28
|
+
rows << ['Two', 2]
|
29
|
+
rows << ['Three', 3]
|
30
|
+
rows << ['よん', 4]
|
31
|
+
table = Terminal::Table.new :rows => rows
|
32
|
+
puts table
|
33
|
+
```
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
+-------+---+
|
37
|
+
| One | 1 |
|
38
|
+
| Two | 2 |
|
39
|
+
| Three | 3 |
|
40
|
+
| よん | 4 |
|
41
|
+
+-------+---+
|
42
|
+
```
|
43
|
+
|
44
|
+
You can use with other options.
|
45
|
+
see more: [tj/terminal-table](https://github.com/tj/terminal-table)
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/terminal-table-unicode.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'terminal/table/unicode'
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'terminal/table/unicode'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Terminal
|
2
|
+
class Table
|
3
|
+
class Cell
|
4
|
+
|
5
|
+
def align(val, position, length)
|
6
|
+
# positions = { :left => :ljust, :right => :rjust, :center => :center }
|
7
|
+
positions = { :left => :mb_ljust, :right => :mb_rjust, :center => :mb_center }
|
8
|
+
val.public_send(positions[position], length)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Terminal
|
3
|
+
class Table
|
4
|
+
private
|
5
|
+
|
6
|
+
def recalc_column_widths row
|
7
|
+
return if row.is_a? Separator
|
8
|
+
i = 0
|
9
|
+
row.cells.each do |cell|
|
10
|
+
colspan = cell.colspan
|
11
|
+
cell_value = cell.value_for_column_width_recalc
|
12
|
+
colspan.downto(1) do |j|
|
13
|
+
# cell_length = cell_value.to_s.length
|
14
|
+
cell_length = cell_value.to_s.display_width
|
15
|
+
if colspan > 1
|
16
|
+
spacing_length = cell_spacing * (colspan - 1)
|
17
|
+
length_in_columns = (cell_length - spacing_length)
|
18
|
+
cell_length = (length_in_columns.to_f / colspan).ceil
|
19
|
+
end
|
20
|
+
if @column_widths[i].to_i < cell_length
|
21
|
+
@column_widths[i] = cell_length
|
22
|
+
end
|
23
|
+
i = i + 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class String
|
2
|
+
def display_width(ambiguous = 1)
|
3
|
+
#codepoints.inject(0){ |a,c|
|
4
|
+
unpack('U*').inject(0){ |a,c|
|
5
|
+
width = case Unicode::DisplayWidth.codepoint(c).to_s
|
6
|
+
when *%w[F W]
|
7
|
+
2
|
8
|
+
when *%w[N Na H]
|
9
|
+
1
|
10
|
+
when *%w[A] # TODO
|
11
|
+
ambiguous
|
12
|
+
else
|
13
|
+
1
|
14
|
+
end
|
15
|
+
a + width
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def mb_ljust(desired_width)
|
20
|
+
padding = desired_width - display_width
|
21
|
+
padding > 0 ? self + ' ' * padding : self
|
22
|
+
end
|
23
|
+
|
24
|
+
def mb_rjust(desired_width)
|
25
|
+
padding = desired_width - display_width
|
26
|
+
padding > 0 ? ' ' * padding + self : self
|
27
|
+
end
|
28
|
+
|
29
|
+
def mb_center(desired_width)
|
30
|
+
padding = desired_width - display_width
|
31
|
+
if padding > 0
|
32
|
+
right_padding = pdding / 2
|
33
|
+
left_padding = padding - right_padding
|
34
|
+
left_padding + self + right
|
35
|
+
else
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'terminal/table/unicode/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'terminal-table-unicode'
|
8
|
+
spec.version = Terminal::Table::Unicode::VERSION
|
9
|
+
spec.authors = ['rochefort']
|
10
|
+
spec.email = ['terasawan@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple, feature rich ascii table generation library with full-width unicode characters'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/rochefort/terminal-table-unicode'
|
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_dependency 'terminal-table', '~> 1.5'
|
23
|
+
spec.add_dependency 'unicode-display_width', '~> 0.1.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal-table-unicode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rochefort
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: terminal-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: unicode-display_width
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Simple, feature rich ascii table generation library with full-width unicode
|
70
|
+
characters
|
71
|
+
email:
|
72
|
+
- terasawan@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/terminal-table-unicode.rb
|
85
|
+
- lib/terminal/table/cell.rb
|
86
|
+
- lib/terminal/table/table.rb
|
87
|
+
- lib/terminal/table/unicode.rb
|
88
|
+
- lib/terminal/table/unicode/ext/string.rb
|
89
|
+
- lib/terminal/table/unicode/version.rb
|
90
|
+
- terminal-table-unicode.gemspec
|
91
|
+
homepage: https://github.com/rochefort/terminal-table-unicode
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.5
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Simple, feature rich ascii table generation library with full-width unicode
|
115
|
+
characters
|
116
|
+
test_files: []
|