-
Notifications
You must be signed in to change notification settings - Fork 64
/
Table.txt
315 lines (268 loc) · 9.66 KB
/
Table.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
*vital/Text/Table.txt* Character table library.
Maintainer: kamichidu <c.kamunagi at gmail.com>
==============================================================================
CONTENTS *Vital.Text.Table-contents*
INTRODUCTION |Vital.Text.Table-introduction|
INTERFACE |Vital.Text.Table-interface|
FUNCTIONS |Vital.Text.Table-functions|
OBJECTS |Vital.Text.Table-objects|
==============================================================================
INTRODUCTION *Vital.Text.Table-introduction*
*Vital.Text.Table* is a character table formatter. It will make a character
table such as below:
+---------+---------+---------+
| header1 | header2 | header3 | <- (A) Header Row
+---------+---------+---------+
| r1c1 | r1c2 | r1c3 | <- (B) Body Row
| r2c1 | r2c2 | r2c3 |
| r3c1 | r3c2 | r3c3 |
+---------+---------+---------+
| footer1 | footer2 | footer3 | <- (C) Footer Row
+---------+---------+---------+ <- (D) Horizontal Border
^
|
(E) Vertical Border
(A) Header Row
A table header. It is configured by
|Vital.Text.Table-Table.header()|.
(B) Body Row
A table body. It is configured by
|Vital.Text.Table-Table.rows()| or
|Vital.Text.Table-Table.add_row()|.
(C) Footer Row
A table footer. It is configured by
|Vital.Text.Table-Table.footer()|.
(D) Horizontal Border
A horizontal border. It is configured by
|Vital.Text.Table-Table.hborder()|.
(E) Vertical Border
A vertical border. It is configured by
|Vital.Text.Table-Table.vborder()|.
|Vital.Text.Table| is easy to use. You can make a character table such above
by:
>
let s:T = vital#{plugin-name}#new().import('Text.Table')
let s:table = s:T.new({
\ 'columns': [{}, {}, {}],
\ 'header': ['header1', 'header2', 'header3'],
\ 'footer': ['footer1', 'footer2', 'footer3'],
\})
call s:table.rows([
\ ['r1c1', 'r1c2', 'r1c3'],
\ ['r2c1', 'r2c2', 'r2c3'],
\ ['r3c1', 'r3c2', 'r3c3'],
\])
echo s:table.stringify()
<
And you can customize the style of table by
|Vital.Text.Table-Table.border_style()|.
==============================================================================
INTERFACE *Vital.Text.Table-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Text.Table-functions*
new([{config}]) *Vital.Text.Table.new()*
Creates a new Table object(|Vital.Text.Table-Table|).
You can configure a new Table object via {config}(|Dictionary|).
{config} takes some attributes below:
hborder (Default: 1)
Same to |Vital.Text.Table-Table.hborder()|.
vborder (Default: 1)
Same to |Vital.Text.Table-Table.vborder()|.
columns (Default: [])
Same to |Vital.Text.Table-Table.columns()|.
header (Default: [])
Same to |Vital.Text.Table-Table.header()|.
rows (Default: [])
Same to |Vital.Text.Table-Table.rows()|.
footer (Default: [])
Same to |Vital.Text.Table-Table.footer()|.
==============================================================================
OBJECTS *Vital.Text.Table-objects*
------------------------------------------------------------------------------
Table Object *Vital.Text.Table-Table*
*Vital.Text.Table-Table.hborder()*
Table.hborder()
Returns 1 If horizontal border will be drawn. Otherwise, 0.
Table.hborder({hborder})
Controls to make a table with/without horizontal border.
e.g. >
table.hborder(1)
<
*Vital.Text.Table-Table.border_style()*
Table.border_style()
Returns a border style object(|Vital.Text.Table-BorderStyle|).
Table.border_style({style})
Sets a border style object(). See |Vital.Text.Table-BorderStyle|
section for more details.
e.g. >
table.border_style({
\ 'joint': {
\ 'row': '+',
\ },
\ 'border': {
\ 'left': '<',
\ 'right': '>',
\ },
\})
<
*Vital.Text.Table-Table.vborder()*
Table.vborder()
Returns 1 If vertical border will be drawn. Otherwise, 0.
Table.vborder({vborder})
Controls to make a table with/without vertical border.
e.g. >
table.vborder(1)
<
*Vital.Text.Table-Table.columns()*
Table.columns()
Returns column configuration objects.
Table.columns({columns})
Sets column configuration objects(|Dictionary|). If its object already
has one or more rows, it will throw an exception. See
|Vital.Text.Table-ColumnConfig| section for more details.
e.g. >
table.columns([
\ {'halign': 'left', 'valign': 'top', 'width': 30},
\ {'halign': 'right', 'valign': 'center', },
\ {'halign': 'center', 'valign': 'bottom', },
\ { },
\])
<
*Vital.Text.Table-Table.add_column()*
Table.add_column({column})
Adds column configuration object. If its object already has one or
more rows, it will throw an exception. See
|Vital.Text.Table-ColumnConfig| section for more details.
e.g. >
table.add_column({'halign': 'left', 'valign': 'top', 'width': 30})
<
*Vital.Text.Table-Table.header()*
Table.header()
Returns a header row object(|Vital.Text.Table-Row|).
Table.header({headers})
Sets a header row object(|Vital.Text.Table-Row|). If given
{headers} size is greater than its columns size, it will throw an
exception.
e.g. >
table.header(['header1', 'header1', 'header1'])
<
*Vital.Text.Table-Table.rows()*
Table.rows()
Returns a row object(|Vital.Text.Table-Row|).
Table.rows({rows})
Sets a row object(|Vital.Text.Table-Row|). If given any row of {rows}
size is greater than its columns size, it will throw an exception.
e.g. >
table.rows([
\ ['row1column1', 'row1column2', 'row1column3'],
\ ['row2column1', 'row2column2', 'row2column3'],
\ ['row3column1', 'row3column2', 'row3column3'],
\])
<
*Vital.Text.Table-Table.add_row()*
Table.add_row({row})
Adds a row object(|Vital.Text.Table-Row|). If given {row} size is
greater than its columns size, it will throw an exception.
e.g. >
table.add_row(['column1', 'column2', 'column3'])
<
*Vital.Text.Table-Table.footer()*
Table.footer()
Returns a footer row object(|Vital.Text.Table-Row|).
Table.footer({footers})
Sets a footer row object(|Vital.Text.Table-Row|). If given {footer}
size is greater than its columns size, it will throw an exception.
e.g. >
table.footer(['footer1', 'footer2', 'footer3'])
<
*Vital.Text.Table-Table.stringify()*
Table.stringify([{tstyle}])
Makes a table by configuration. Returns a |List| which has each table
row strings. And it can take a table style object
(|Vital.Text.Table-TableStyle|).
e.g. >
" [
" ['+------+------+------+'],
" ['| h1 | h2 | h3 |'],
" ['+------+------+------+'],
" ['| r1c1 | r1c2 | r1c3 |'],
" ['| r2c1 | r2c2 | r2c3 |'],
" ['+------+------+------+'],
" ['| f1 | f2 | f3 |'],
" ['+------+------+------+'],
" ]
echo table.stringify()
<
------------------------------------------------------------------------------
Row Object *Vital.Text.Table-Row*
Row Object is a |List| containing |String|, |Number|, |Float| values.
------------------------------------------------------------------------------
Column Config Object *Vital.Text.Table-ColumnConfig*
ColumnConfig.halign *Vital.Text.Table-ColumnConfig.halign*
Specify a horizontal alignment for its column. "left", "right" and
"center" are supported. Default is "left".
+---------------------------+
| "left" "center" "right" |
+---------------------------+
ColumnConfig.valign *Vital.Text.Table-ColumnConfig.valign*
Specify a vertical alignment for its column. "top", "bottom" and
"center" are supported. Default is "top".
+----------+
| "top" |
| "center" |
| "bottom" |
+----------+
ColumnConfig.width *Vital.Text.Table-ColumnConfig.width*
Specify a column width for its column. It is number of characters
similar to |'columns'|. Default is depends on data(no wrapping).
<- width ->
+----------+
| |
+----------+
------------------------------------------------------------------------------
Table Style Object *Vital.Text.Table-TableStyle*
TableStyle.max_width *Vital.Text.Table-TableStyle.max_width*
Specify a table width for whole table. It is number of characters
similar to |'columns'|. Default is 0 (unlimited).
<- width ->
+---+---+---+
| | | |
+---+---+---+
------------------------------------------------------------------------------
Border Style Object *Vital.Text.Table-BorderStyle*
BorderStyle.joint *Vital.Text.Table-BorderStyle.joint*
Configures a border joint character(s). It's okay to use multi-byte
characters and multiple characters. The kinds of joint you can specify
by |Dictionary| are described below:
(A) top_left (B) top (C) top_right
(D) head_left (E) head (F) head_right
(G) left (H) row (I) right
(J) foot_left (K) foot (L) foot_right
(M) bottom_left (N) bottom (O) bottom_right
(A)------(B)------(B)------(C)
| | | |
(D)------(E)------(E)------(F)
| | | |
(G)------(H)------(H)------(I)
| | | |
(J)------(K)------(K)------(L)
| | | |
(M)------(N)------(N)------(O)
BorderStyle.border *Vital.Text.Table-BorderStyle.border*
Configures a border character(s). It's okay to use multi-byte
characters and multiple characters. The kinds of border you can
specify by |Dictionary| are described below:
(a) top (b) head (c) row
(d) foot (e) bottom (f) left
(g) column (h) right
+---(a)---+---(a)---+---(a)---+
(f) (g) (g) (h)
+---(b)---+---(b)---+---(b)---+
(f) (g) (g) (h)
+---(c)---+---(c)---+---(c)---+
(f) (g) (g) (h)
+---(d)---+---(d)---+---(d)---+
(f) (g) (g) (h)
+---(e)---+---(e)---+---(e)---+
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl