table_tennis 0.0.4 → 0.0.5
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/README.md +16 -1
- data/lib/table_tennis/stage/format.rb +23 -6
- data/lib/table_tennis/stage/render.rb +5 -0
- data/lib/table_tennis/table_data.rb +2 -1
- data/lib/table_tennis/theme.rb +9 -0
- data/lib/table_tennis/util/strings.rb +6 -0
- data/lib/table_tennis/version.rb +1 -1
- data/screenshots/link.png +0 -0
- data/table_tennis.gemspec +2 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '009a0c9bbb140d308d55441602f96a534e51d989259c70b2e3cc2661213252cb'
|
4
|
+
data.tar.gz: 6422661f90e1e6e15ddb67c0fff92d6d1c1f3d3454e95a57ae79652d83b981ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af82ae82579222df273e5244c2dde9137547cce527b4c5e4b900feeb7129beb7d9b5d9ea80ae849f62ac79befd14c38be0f8e8c311a651f8dc63660b1953190a
|
7
|
+
data.tar.gz: 7eae197b20fe45f0b65f9987097e38233dac3ea113fcabbfd27011340a18910f9c8d701a3352cb482819f266391e98a0daaeec0857e966982e6d6ffcf2aa2121
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ gem "table_tennis"
|
|
29
29
|
- auto-layout to fit your terminal window
|
30
30
|
- auto-format floats and dates
|
31
31
|
- auto-color numeric columns
|
32
|
+
- auto-link markdown links
|
32
33
|
- titles, row numbers, zebra stripes...
|
33
34
|
|
34
35
|
### Themes
|
@@ -45,7 +46,7 @@ Construct your table with an array of rows. Rows are hashes, ActiveRecord object
|
|
45
46
|
puts TableTennis.new([{a: "hello", b: "world"}, {a: "foo", b: "bar"}])
|
46
47
|
puts TableTennis.new(Recipe.all.to_a) # activerecord
|
47
48
|
puts TableTennis.new(array_of_structs) # these use to_h
|
48
|
-
puts TableTennis.new([[1,2],[3,4]])
|
49
|
+
puts TableTennis.new([[1,2],[3,4]]) # array of arrays
|
49
50
|
puts TableTennis.new(authors[0]) # single hash
|
50
51
|
```
|
51
52
|
|
@@ -114,6 +115,16 @@ puts TableTennis.new(rows, row_numbers: true, zebra: true)
|
|
114
115
|
| - | - | - |
|
115
116
|
|  |  |  |
|
116
117
|
|
118
|
+
### Links
|
119
|
+
|
120
|
+
Modern terminals support **hyperlinks** in the text stream. If your table includes markdown-style links, TableTennis will use [OSC 8](https://github.com/Alhadis/OSC8-Adoption) to render them. For example:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
puts TableTennis.new([{site: "[search](https://google.com)"}])
|
124
|
+
```
|
125
|
+
|
126
|
+

|
127
|
+
|
117
128
|
### Advanced Usage
|
118
129
|
|
119
130
|
TableTennis can be configured a few different ways:
|
@@ -152,6 +163,10 @@ We love CSV tools and use them all the time! Here are a few that we rely on:
|
|
152
163
|
|
153
164
|
### Changelog
|
154
165
|
|
166
|
+
#### 0.0.5 (April '25)
|
167
|
+
|
168
|
+
- Support for markdown style links in the cells
|
169
|
+
|
155
170
|
#### 0.0.4 (April '25)
|
156
171
|
|
157
172
|
- Separators can be turned off with `separators: false`.
|
@@ -16,14 +16,23 @@ module TableTennis
|
|
16
16
|
fn || :fn_default
|
17
17
|
end
|
18
18
|
|
19
|
-
rows.each do |row|
|
20
|
-
row.each_index do
|
21
|
-
value = row[
|
19
|
+
rows.each.with_index do |row, r|
|
20
|
+
row.each_index do |c|
|
21
|
+
value = row[c]
|
22
22
|
# Try to format using the column fn. This can return nil. For
|
23
23
|
# example, a float column and value is nil, not a float, etc.
|
24
|
-
|
24
|
+
str = send(fns[c], value)
|
25
|
+
|
25
26
|
# If the column formatter failed, use the default formatter
|
26
|
-
|
27
|
+
str ||= fn_default(value) || config.placeholder
|
28
|
+
|
29
|
+
# look for markdown-style links
|
30
|
+
if (link = detect_link(str))
|
31
|
+
str, data.links[[r, c]] = link
|
32
|
+
end
|
33
|
+
|
34
|
+
# done
|
35
|
+
row[c] = str
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
@@ -61,7 +70,7 @@ module TableTennis
|
|
61
70
|
# default formatting. cleanup whitespace
|
62
71
|
def fn_default(value)
|
63
72
|
return if value.nil?
|
64
|
-
str =
|
73
|
+
str = value.is_a?(String) ? value : value.to_s
|
65
74
|
str = str.strip.gsub("\n", "\\n").gsub("\r", "\\r") if str.match?(/\s/)
|
66
75
|
return if str.empty?
|
67
76
|
str
|
@@ -91,6 +100,14 @@ module TableTennis
|
|
91
100
|
x
|
92
101
|
end
|
93
102
|
|
103
|
+
def detect_link(str)
|
104
|
+
# fail fast, for speed
|
105
|
+
return unless str.length >= 6 && str[0] == "["
|
106
|
+
if str =~ /^\[([^\]]+)\]\(([^\)]+)\)$/
|
107
|
+
[$1, $2]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
94
111
|
# str to_xxx that are resistant to commas
|
95
112
|
def to_f(str) = str.delete(",").to_f
|
96
113
|
def to_i(str) = str.delete(",").to_i
|
@@ -83,6 +83,11 @@ module TableTennis
|
|
83
83
|
# add ansi codes for search
|
84
84
|
value = value.gsub(search) { paint(_1, :search) } if search
|
85
85
|
|
86
|
+
# add ansi codes for links
|
87
|
+
if config.color && (link = data.links[[r, c]])
|
88
|
+
value = theme.link(value, link)
|
89
|
+
end
|
90
|
+
|
86
91
|
# pad and paint
|
87
92
|
if whitespace > 0
|
88
93
|
spaces = " " * whitespace
|
@@ -21,7 +21,7 @@ module TableTennis
|
|
21
21
|
prepend MemoWise
|
22
22
|
include Util::Inspectable
|
23
23
|
|
24
|
-
attr_accessor :config, :input_rows, :styles
|
24
|
+
attr_accessor :config, :input_rows, :links, :styles
|
25
25
|
|
26
26
|
def initialize(rows:, config: nil)
|
27
27
|
@config, @input_rows = config, rows
|
@@ -38,6 +38,7 @@ module TableTennis
|
|
38
38
|
raise ArgumentError, "input_rows must be an array of hash-like objects, not #{input_rows.class}"
|
39
39
|
end
|
40
40
|
|
41
|
+
@links = {}
|
41
42
|
@styles = {}
|
42
43
|
end
|
43
44
|
|
data/lib/table_tennis/theme.rb
CHANGED
@@ -5,6 +5,9 @@ module TableTennis
|
|
5
5
|
prepend MemoWise
|
6
6
|
|
7
7
|
RESET = Paint::NOTHING
|
8
|
+
OSC_8 = "\e]8;;"
|
9
|
+
ST = "\e\\"
|
10
|
+
|
8
11
|
NHEADER_COLORS = 6
|
9
12
|
THEMES = {
|
10
13
|
dark: {
|
@@ -95,6 +98,12 @@ module TableTennis
|
|
95
98
|
end
|
96
99
|
memo_wise :paint
|
97
100
|
|
101
|
+
# use osc 8 to create a terminal hyperlink. underline too
|
102
|
+
def link(str, link)
|
103
|
+
linked = "#{OSC_8}#{link}#{ST}#{str}#{OSC_8}#{ST}"
|
104
|
+
Paint[linked, :underline]
|
105
|
+
end
|
106
|
+
|
98
107
|
# for debugging, mostly
|
99
108
|
def self.info
|
100
109
|
sample = if !Config.detect_color?
|
@@ -22,6 +22,12 @@ module TableTennis
|
|
22
22
|
simple?(text) ? text.length : Unicode::DisplayWidth.of(text)
|
23
23
|
end
|
24
24
|
|
25
|
+
def hyperlink(value)
|
26
|
+
if value =~ /^\[([^\]]*)\]\(([^\)]*)\)$/
|
27
|
+
[$1, $2]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
# truncate a string based on the display width of the grapheme clusters.
|
26
32
|
# Should handle emojis and international characters
|
27
33
|
def truncate(text, stop)
|
data/lib/table_tennis/version.rb
CHANGED
Binary file
|
data/table_tennis.gemspec
CHANGED
@@ -7,10 +7,11 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.email = "amd@gurge.com"
|
8
8
|
|
9
9
|
s.summary = "Stylish tables in your terminal."
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://github.com/gurgeous/table_tennis"
|
11
11
|
s.license = "MIT"
|
12
12
|
s.required_ruby_version = ">= 3.0.0"
|
13
13
|
s.metadata = {
|
14
|
+
"homepage_uri" => s.homepage,
|
14
15
|
"rubygems_mfa_required" => "true",
|
15
16
|
"source_code_uri" => s.homepage,
|
16
17
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_tennis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Doppelt
|
@@ -116,16 +116,18 @@ files:
|
|
116
116
|
- screenshots/droids.png
|
117
117
|
- screenshots/hope.png
|
118
118
|
- screenshots/light.png
|
119
|
+
- screenshots/link.png
|
119
120
|
- screenshots/row_numbers.png
|
120
121
|
- screenshots/scales.png
|
121
122
|
- screenshots/themes.png
|
122
123
|
- table_tennis.gemspec
|
123
|
-
homepage:
|
124
|
+
homepage: https://github.com/gurgeous/table_tennis
|
124
125
|
licenses:
|
125
126
|
- MIT
|
126
127
|
metadata:
|
128
|
+
homepage_uri: https://github.com/gurgeous/table_tennis
|
127
129
|
rubygems_mfa_required: 'true'
|
128
|
-
source_code_uri:
|
130
|
+
source_code_uri: https://github.com/gurgeous/table_tennis
|
129
131
|
rdoc_options: []
|
130
132
|
require_paths:
|
131
133
|
- lib
|