-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathdemo.go
506 lines (486 loc) · 30.9 KB
/
demo.go
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
package main
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/text"
)
func main() {
//==========================================================================
// Initialization
//==========================================================================
t := table.NewWriter()
// you can also instantiate the object directly
tTemp := table.Table{}
tTemp.Render() // just to avoid the compile error of not using the object
//==========================================================================
//==========================================================================
// Append a few rows and render to console
//==========================================================================
// a row need not be just strings
t.AppendRow(table.Row{1, "Arya", "Stark", 3000})
// all rows need not have the same number of columns
t.AppendRow(table.Row{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"})
// table.Row is just a shorthand for []interface{}
t.AppendRow([]interface{}{300, "Tyrion", "Lannister", 5000})
// time to take a peek
t.SetCaption("Simple Table with 3 Rows.\n")
fmt.Println(t.Render())
//+-----+--------+-----------+------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//+-----+--------+-----------+------+-----------------------------+
//Simple Table with 3 Rows.
//==========================================================================
//==========================================================================
// Can you index the columns?
//==========================================================================
t.SetAutoIndex(true)
t.SetCaption("Table with Auto-Indexing.\n")
fmt.Println(t.Render())
//+---+-----+--------+-----------+------+-----------------------------+
//| | A | B | C | D | E |
//+---+-----+--------+-----------+------+-----------------------------+
//| 1 | 1 | Arya | Stark | 3000 | |
//| 2 | 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 3 | 300 | Tyrion | Lannister | 5000 | |
//+---+-----+--------+-----------+------+-----------------------------+
//Table with Auto-Indexing.
t.SetAutoIndex(false)
//==========================================================================
//==========================================================================
// A table needs to have a Header & Footer (for this demo at least!)
//==========================================================================
// start with a header
t.AppendHeader(table.Row{"#", "First Name", "Last Name", "Salary"})
// time to take a peek
t.SetCaption("Table with 3 Rows & and a Header.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with 3 Rows & and a Header.
//
// and then add a footer
t.AppendFooter(table.Row{"", "", "Total", 10000})
// time to take a peek
t.SetCaption("Table with 3 Rows, a Header & a Footer.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with 3 Rows, a Header & a Footer.
//==========================================================================
//==========================================================================
// Alignment?
//==========================================================================
// did you notice that the numeric columns were auto-aligned? when you don't
// specify alignment, all the columns default to text.AlignDefault - numbers
// go right and everything else left. but what if you want the first name to
// go right too? and the last column to be "justified"?
t.SetAlign([]text.Align{text.AlignDefault, text.AlignRight, text.AlignDefault, text.AlignDefault, text.AlignJustify})
// to show AlignJustify in action, lets add one more row
t.AppendRow(table.Row{4, "Faceless", "Man", 0, "Needs a\tname."})
// time to take a peek:
t.SetCaption("Table with Custom Alignment for 2 columns.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//| 4 | Faceless | Man | 0 | Needs a name. |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with Custom Alignment for 2 columns.
//==========================================================================
//==========================================================================
// Vertical Alignment?
//==========================================================================
// horizontal alignment is fine... what about vertical? lets add a row with
// a column having multiple lines; and then play with VAlign
t.AppendRow(table.Row{13, "Winter\nIs\nComing", "Valar\nMorghulis", 0, "You\n know\n nothing,\n Jon\n Snow!"})
// first without any custom VAlign
t.SetCaption("Table with a Multi-line Row.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//| 4 | Faceless | Man | 0 | Needs a name. |
//| 13 | Winter | Valar | 0 | You |
//| | Is | Morghulis | | know |
//| | Coming | | | nothing, |
//| | | | | Jon |
//| | | | | Snow! |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with a Multi-line Row.
//
// time to VAlign the columns... and ignore the last column in the process
t.SetVAlign([]text.VAlign{text.VAlignDefault, text.VAlignMiddle, text.VAlignBottom, text.VAlignMiddle})
t.SetCaption("Table with a Multi-line Row with VAlign.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//| 4 | Faceless | Man | 0 | Needs a name. |
//| 13 | | | | You |
//| | Winter | | | know |
//| | Is | | 0 | nothing, |
//| | Coming | Valar | | Jon |
//| | | Morghulis | | Snow! |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with a Multi-line Row with VAlign.
//
// changed your mind about AlignJustify?
t.SetAlign([]text.Align{text.AlignDefault, text.AlignRight, text.AlignDefault, text.AlignDefault, text.AlignCenter})
t.SetCaption("Table with a Multi-line Row with VAlign and changed Align.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//| 4 | Faceless | Man | 0 | Needs a name. |
//| 13 | | | | You |
//| | Winter | | | know |
//| | Is | | 0 | nothing, |
//| | Coming | Valar | | Jon |
//| | | Morghulis | | Snow! |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Table with a Multi-line Row with VAlign and changed Align.
//==========================================================================
//==========================================================================
// Time to begin anew. Too much on the screen for a demo!
//==========================================================================
t = table.NewWriter()
t.AppendHeader(table.Row{"#", "First Name", "Last Name", "Salary"})
t.AppendRow(table.Row{1, "Arya", "Stark", 3000})
t.AppendRow(table.Row{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"})
t.AppendRow([]interface{}{300, "Tyrion", "Lannister", 5000})
t.AppendFooter(table.Row{"", "", "Total", 10000})
t.SetCaption("Starting afresh with a Simple Table again.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+-----------------------------+
//| # | FIRST NAME | LAST NAME | SALARY | |
//+-----+------------+-----------+--------+-----------------------------+
//| 1 | Arya | Stark | 3000 | |
//| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//| 300 | Tyrion | Lannister | 5000 | |
//+-----+------------+-----------+--------+-----------------------------+
//| | | TOTAL | 10000 | |
//+-----+------------+-----------+--------+-----------------------------+
//Starting afresh with a Simple Table again.
//==========================================================================
//==========================================================================
// How about limiting the length of every Row?
//==========================================================================
t.SetAllowedRowLength(50)
t.SetCaption("Table with an Allowed Row Length of 50.\n")
fmt.Println(t.Render())
//+-----+------------+-----------+--------+------- ~
//| # | FIRST NAME | LAST NAME | SALARY | ~
//+-----+------------+-----------+--------+------- ~
//| 1 | Arya | Stark | 3000 | ~
//| 20 | Jon | Snow | 2000 | You kn ~
//| 300 | Tyrion | Lannister | 5000 | ~
//+-----+------------+-----------+--------+------- ~
//| | | TOTAL | 10000 | ~
//+-----+------------+-----------+--------+------- ~
t.SetStyle(table.StyleDouble)
t.SetCaption("Table with an Allowed Row Length of 50 in 'StyleDouble'.\n")
fmt.Println(t.Render())
//╔═════╦════════════╦═══════════╦════════╦═══════ ≈
//║ # ║ FIRST NAME ║ LAST NAME ║ SALARY ║ ≈
//╠═════╬════════════╬═══════════╬════════╬═══════ ≈
//║ 1 ║ Arya ║ Stark ║ 3000 ║ ≈
//║ 20 ║ Jon ║ Snow ║ 2000 ║ You kn ≈
//║ 300 ║ Tyrion ║ Lannister ║ 5000 ║ ≈
//╠═════╬════════════╬═══════════╬════════╬═══════ ≈
//║ ║ ║ TOTAL ║ 10000 ║ ≈
//╚═════╩════════════╩═══════════╩════════╩═══════ ≈
//Table with an Allowed Row Length of 50 in 'StyleDouble'.
//==========================================================================
//==========================================================================
// But I want to see all the data!
//==========================================================================
t.SetAllowedColumnLengths([]int{0, 6, 9, 6, 10})
t.SetCaption("Table on a diet.\n")
t.SetStyle(table.StyleRounded)
fmt.Println(t.Render())
//╭─────┬────────┬───────────┬────────┬────────────╮
//│ # │ FIRST │ LAST NAME │ SALARY │ │
//│ │ NAME │ │ │ │
//├─────┼────────┼───────────┼────────┼────────────┤
//│ 1 │ Arya │ Stark │ 3000 │ │
//│ 20 │ Jon │ Snow │ 2000 │ You know n │
//│ │ │ │ │ othing, Jo │
//│ │ │ │ │ n Snow! │
//│ 300 │ Tyrion │ Lannister │ 5000 │ │
//├─────┼────────┼───────────┼────────┼────────────┤
//│ │ │ TOTAL │ 10000 │ │
//╰─────┴────────┴───────────┴────────┴────────────╯
//Table on a diet.
t.SetAllowedRowLength(0)
t.SetAllowedColumnLengths([]int{0, 0, 0, 0, 0})
//==========================================================================
//==========================================================================
// ASCII is too simple for me.
//==========================================================================
t.SetStyle(table.StyleLight)
t.SetCaption("Table using the style 'StyleLight'.\n")
fmt.Println(t.Render())
//┌─────┬────────────┬───────────┬────────┬─────────────────────────────┐
//│ # │ FIRST NAME │ LAST NAME │ SALARY │ │
//├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
//│ 1 │ Arya │ Stark │ 3000 │ │
//│ 20 │ Jon │ Snow │ 2000 │ You know nothing, Jon Snow! │
//│ 300 │ Tyrion │ Lannister │ 5000 │ │
//├─────┼────────────┼───────────┼────────┼─────────────────────────────┤
//│ │ │ TOTAL │ 10000 │ │
//└─────┴────────────┴───────────┴────────┴─────────────────────────────┘
//Table using the style 'StyleLight'.
t.SetStyle(table.StyleDouble)
t.SetCaption("Table using the style '%s'.\n", t.Style().Name)
fmt.Println(t.Render())
//╔═════╦════════════╦═══════════╦════════╦═════════════════════════════╗
//║ # ║ FIRST NAME ║ LAST NAME ║ SALARY ║ ║
//╠═════╬════════════╬═══════════╬════════╬═════════════════════════════╣
//║ 1 ║ Arya ║ Stark ║ 3000 ║ ║
//║ 20 ║ Jon ║ Snow ║ 2000 ║ You know nothing, Jon Snow! ║
//║ 300 ║ Tyrion ║ Lannister ║ 5000 ║ ║
//╠═════╬════════════╬═══════════╬════════╬═════════════════════════════╣
//║ ║ ║ TOTAL ║ 10000 ║ ║
//╚═════╩════════════╩═══════════╩════════╩═════════════════════════════╝
//Table using the style 'StyleDouble'.
//==========================================================================
//==========================================================================
// I don't like any of the ready-made styles.
//==========================================================================
funkyStyle := table.Style{
BoxBottomLeft: "\\",
BoxBottomRight: "/",
BoxBottomSeparator: "v",
BoxLeft: "[",
BoxLeftSeparator: "{",
BoxMiddleHorizontal: "-",
BoxMiddleSeparator: "+",
BoxMiddleVertical: "|",
BoxPaddingLeft: "<",
BoxPaddingRight: ">",
BoxRight: "]",
BoxRightSeparator: "}",
BoxTopLeft: "(",
BoxTopRight: ")",
BoxTopSeparator: "^",
BoxUnfinishedRow: " ~~~",
FormatFooter: text.FormatLower,
FormatHeader: text.FormatLower,
FormatRows: text.FormatUpper,
Name: "funkyStyle",
}
t.SetStyle(funkyStyle)
t.SetCaption("Table using the style 'funkyStyle'.\n")
fmt.Println(t.Render())
//(-----^------------^-----------^--------^-----------------------------)
//[< #>|<first name>|<last name>|<salary>|< >]
//{-----+------------+-----------+--------+-----------------------------}
//[< 1>|<ARYA >|<STARK >|< 3000>|< >]
//[< 20>|<JON >|<SNOW >|< 2000>|<YOU KNOW NOTHING, JON SNOW!>]
//[<300>|<TYRION >|<LANNISTER>|< 5000>|< >]
//{-----+------------+-----------+--------+-----------------------------}
//[< >|< >|<total >|< 10000>|< >]
//\-----v------------v-----------v--------v-----------------------------/
//Table using the style 'funkyStyle'.
//==========================================================================
//==========================================================================
// I need some color in my life!
//==========================================================================
t.SetStyle(table.StyleBold)
colorBOnW := text.Colors{color.BgWhite, color.FgBlack}
t.SetColorsHeader([]text.Colors{colorBOnW, colorBOnW, colorBOnW, colorBOnW, colorBOnW})
t.SetColors([]text.Colors{{color.FgYellow}, {color.FgHiRed}, {color.FgHiRed}, {color.FgGreen}, {color.FgCyan}})
t.SetColorsFooter([]text.Colors{{}, {}, colorBOnW, colorBOnW})
t.SetCaption("Table with Colors.\n")
fmt.Println(t.Render())
//┏━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
//┃ # ┃ FIRST NAME ┃ LAST NAME ┃ SALARY ┃ ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ 1 ┃ Arya ┃ Stark ┃ 3000 ┃ ┃
//┃ 20 ┃ Jon ┃ Snow ┃ 2000 ┃ You know nothing, Jon Snow! ┃
//┃ 300 ┃ Tyrion ┃ Lannister ┃ 5000 ┃ ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ ┃ ┃ TOTAL ┃ 10000 ┃ ┃
//┗━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
//Table with Colors.
//
// "Table with Colors"??? where? i don't see any! well, you have to trust me
// on this... the colors show on a terminal that supports it. to prove it,
// lets print the same table line-by-line using "%#v" to see the escape
// sequences ...
t.SetCaption("Table with Colors in Raw Mode.\n")
for _, line := range strings.Split(t.Render(), "\n") {
if line != "" {
fmt.Printf("%#v\n", line)
}
}
fmt.Println()
//"┏━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
//"┃\x1b[47;30m # \x1b[0m┃\x1b[47;30m FIRST NAME \x1b[0m┃\x1b[47;30m LAST NAME \x1b[0m┃\x1b[47;30m SALARY \x1b[0m┃\x1b[47;30m \x1b[0m┃"
//"┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"
//"┃\x1b[33m 1 \x1b[0m┃\x1b[91m Arya \x1b[0m┃\x1b[91m Stark \x1b[0m┃\x1b[32m 3000 \x1b[0m┃\x1b[36m \x1b[0m┃"
//"┃\x1b[33m 20 \x1b[0m┃\x1b[91m Jon \x1b[0m┃\x1b[91m Snow \x1b[0m┃\x1b[32m 2000 \x1b[0m┃\x1b[36m You know nothing, Jon Snow! \x1b[0m┃"
//"┃\x1b[33m 300 \x1b[0m┃\x1b[91m Tyrion \x1b[0m┃\x1b[91m Lannister \x1b[0m┃\x1b[32m 5000 \x1b[0m┃\x1b[36m \x1b[0m┃"
//"┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"
//"┃ ┃ ┃\x1b[47;30m TOTAL \x1b[0m┃\x1b[47;30m 10000 \x1b[0m┃ ┃"
//"┗━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
//"Table with Colors in Raw Mode."
//""
t.SetColorsHeader([]text.Colors{}) // disable colors on the header
t.SetColors([]text.Colors{}) // disable colors on the body
t.SetColorsFooter([]text.Colors{}) // disable colors on the footer
//==========================================================================
//==========================================================================
// I don't like borders!
//==========================================================================
t.ShowBorder(false)
t.SetCaption("Table without Borders.\n")
fmt.Println(t.Render())
// # ┃ FIRST NAME ┃ LAST NAME ┃ SALARY ┃
//━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1 ┃ Arya ┃ Stark ┃ 3000 ┃
// 20 ┃ Jon ┃ Snow ┃ 2000 ┃ You know nothing, Jon Snow!
// 300 ┃ Tyrion ┃ Lannister ┃ 5000 ┃
//━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ┃ ┃ TOTAL ┃ 10000 ┃
//Table without Borders.
//==========================================================================
//==========================================================================
// I like walls and borders everywhere!
//==========================================================================
t.ShowBorder(true)
t.ShowSeparators(true)
t.SetCaption("Table with Borders Everywhere!\n")
fmt.Println(t.Render())
//┏━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
//┃ # ┃ FIRST NAME ┃ LAST NAME ┃ SALARY ┃ ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ 1 ┃ Arya ┃ Stark ┃ 3000 ┃ ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ 20 ┃ Jon ┃ Snow ┃ 2000 ┃ You know nothing, Jon Snow! ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ 300 ┃ Tyrion ┃ Lannister ┃ 5000 ┃ ┃
//┣━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
//┃ ┃ ┃ TOTAL ┃ 10000 ┃ ┃
//┗━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
//Table with Borders Everywhere!
//==========================================================================
//==========================================================================
// I want CSV.
//==========================================================================
t.SetCaption("")
for _, line := range strings.Split(t.RenderCSV(), "\n") {
fmt.Printf("[CSV] %s\n", line)
}
fmt.Println()
//[CSV] #,First Name,Last Name,Salary,
//[CSV] 1,Arya,Stark,3000,
//[CSV] 20,Jon,Snow,2000,"You know nothing\, Jon Snow!"
//[CSV] 300,Tyrion,Lannister,5000,
//[CSV] ,,Total,10000,
//==========================================================================
//==========================================================================
// Nope. I want a HTML Table.
//==========================================================================
for _, line := range strings.Split(t.RenderHTML(), "\n") {
fmt.Printf("[HTML] %s\n", line)
}
fmt.Println()
//[HTML] <table class="go-pretty-table">
//[HTML] <thead>
//[HTML] <tr>
//[HTML] <th align="right">#</th>
//[HTML] <th>First Name</th>
//[HTML] <th>Last Name</th>
//[HTML] <th align="right">Salary</th>
//[HTML] <th> </th>
//[HTML] </tr>
//[HTML] </thead>
//[HTML] <tbody>
//[HTML] <tr>
//[HTML] <td align="right">1</td>
//[HTML] <td>Arya</td>
//[HTML] <td>Stark</td>
//[HTML] <td align="right">3000</td>
//[HTML] <td> </td>
//[HTML] </tr>
//[HTML] <tr>
//[HTML] <td align="right">20</td>
//[HTML] <td>Jon</td>
//[HTML] <td>Snow</td>
//[HTML] <td align="right">2000</td>
//[HTML] <td>You know nothing, Jon Snow!</td>
//[HTML] </tr>
//[HTML] <tr>
//[HTML] <td align="right">300</td>
//[HTML] <td>Tyrion</td>
//[HTML] <td>Lannister</td>
//[HTML] <td align="right">5000</td>
//[HTML] <td> </td>
//[HTML] </tr>
//[HTML] </tbody>
//[HTML] <tfoot>
//[HTML] <tr>
//[HTML] <td align="right"> </td>
//[HTML] <td> </td>
//[HTML] <td>Total</td>
//[HTML] <td align="right">10000</td>
//[HTML] <td> </td>
//[HTML] </tr>
//[HTML] </tfoot>
//[HTML] </table>
//==========================================================================
//==========================================================================
// Nope. I want a Markdown Table now.
//==========================================================================
for _, line := range strings.Split(t.RenderMarkdown(), "\n") {
fmt.Printf("[Markdown] %s\n", line)
}
fmt.Println()
//[Markdown] | # | First Name | Last Name | Salary | |
//[Markdown] | ---:| --- | --- | ---:| --- |
//[Markdown] | 1 | Arya | Stark | 3000 | |
//[Markdown] | 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
//[Markdown] | 300 | Tyrion | Lannister | 5000 | |
//[Markdown] | | | Total | 10000 | |
//==========================================================================
//==========================================================================
// That's it for today! New features will always find a place in this demo!
//==========================================================================
}