|
| 1 | +Usage |
| 2 | +--------- |
| 3 | + |
| 4 | +Convert lists to ASCII tables |
| 5 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 | + |
| 7 | +.. code:: py |
| 8 | +
|
| 9 | + from table2ascii import table2ascii |
| 10 | +
|
| 11 | + output = table2ascii( |
| 12 | + header=["#", "G", "H", "R", "S"], |
| 13 | + body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], |
| 14 | + footer=["SUM", "130", "140", "135", "130"], |
| 15 | + ) |
| 16 | +
|
| 17 | + print(output) |
| 18 | +
|
| 19 | + """ |
| 20 | + ╔═════════════════════════════╗ |
| 21 | + ║ # G H R S ║ |
| 22 | + ╟─────────────────────────────╢ |
| 23 | + ║ 1 30 40 35 30 ║ |
| 24 | + ║ 2 30 40 35 30 ║ |
| 25 | + ╟─────────────────────────────╢ |
| 26 | + ║ SUM 130 140 135 130 ║ |
| 27 | + ╚═════════════════════════════╝ |
| 28 | + """ |
| 29 | +
|
| 30 | +Set first or last column headings |
| 31 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 32 | + |
| 33 | +.. code:: py |
| 34 | +
|
| 35 | + from table2ascii import table2ascii |
| 36 | +
|
| 37 | + output = table2ascii( |
| 38 | + body=[["Assignment", "30", "40", "35", "30"], ["Bonus", "10", "20", "5", "10"]], |
| 39 | + first_col_heading=True, |
| 40 | + ) |
| 41 | +
|
| 42 | + print(output) |
| 43 | +
|
| 44 | + """ |
| 45 | + ╔════════════╦═══════════════════╗ |
| 46 | + ║ Assignment ║ 30 40 35 30 ║ |
| 47 | + ║ Bonus ║ 10 20 5 10 ║ |
| 48 | + ╚════════════╩═══════════════════╝ |
| 49 | + """ |
| 50 | +
|
| 51 | +Set column widths and alignments |
| 52 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 53 | + |
| 54 | +.. code:: py |
| 55 | +
|
| 56 | + from table2ascii import table2ascii, Alignment |
| 57 | +
|
| 58 | + output = table2ascii( |
| 59 | + header=["#", "G", "H", "R", "S"], |
| 60 | + body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], |
| 61 | + first_col_heading=True, |
| 62 | + column_widths=[5] * 5, # [5, 5, 5, 5, 5] |
| 63 | + alignments=[Alignment.LEFT] + [Alignment.RIGHT] * 4, # First is left, remaining 4 are right |
| 64 | + ) |
| 65 | +
|
| 66 | + print(output) |
| 67 | +
|
| 68 | + """ |
| 69 | + ╔═════╦═══════════════════════╗ |
| 70 | + ║ # ║ G H R S ║ |
| 71 | + ╟─────╫───────────────────────╢ |
| 72 | + ║ 1 ║ 30 40 35 30 ║ |
| 73 | + ║ 2 ║ 30 40 35 30 ║ |
| 74 | + ╚═════╩═══════════════════════╝ |
| 75 | + """ |
| 76 | +
|
| 77 | +Use a preset style |
| 78 | +~~~~~~~~~~~~~~~~~~ |
| 79 | + |
| 80 | +.. code:: py |
| 81 | +
|
| 82 | + from table2ascii import table2ascii, PresetStyle |
| 83 | +
|
| 84 | + output = table2ascii( |
| 85 | + header=["First", "Second", "Third", "Fourth"], |
| 86 | + body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], |
| 87 | + column_widths=[10] * 4, |
| 88 | + style=PresetStyle.ascii_box |
| 89 | + ) |
| 90 | +
|
| 91 | + print(output) |
| 92 | +
|
| 93 | + """ |
| 94 | + +----------+----------+----------+----------+ |
| 95 | + | First | Second | Third | Fourth | |
| 96 | + +----------+----------+----------+----------+ |
| 97 | + | 10 | 30 | 40 | 35 | |
| 98 | + +----------+----------+----------+----------+ |
| 99 | + | 20 | 10 | 20 | 5 | |
| 100 | + +----------+----------+----------+----------+ |
| 101 | + """ |
| 102 | +
|
| 103 | +Define a custom style |
| 104 | +~~~~~~~~~~~~~~~~~~~~~ |
| 105 | + |
| 106 | +Check |
| 107 | +```TableStyle`` <https://github.com/DenverCoder1/table2ascii/blob/main/table2ascii/table_style.py>`__ |
| 108 | +for more info and |
| 109 | +```PresetStyle`` <https://github.com/DenverCoder1/table2ascii/blob/main/table2ascii/preset_style.py>`__ |
| 110 | +for examples. |
| 111 | + |
| 112 | +.. code:: py |
| 113 | +
|
| 114 | + from table2ascii import table2ascii, TableStyle |
| 115 | +
|
| 116 | + my_style = TableStyle.from_string("*-..*||:+-+:+ *''*") |
| 117 | +
|
| 118 | + output = table2ascii( |
| 119 | + header=["First", "Second", "Third"], |
| 120 | + body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]], |
| 121 | + style=my_style |
| 122 | + ) |
| 123 | +
|
| 124 | + print(output) |
| 125 | +
|
| 126 | + """ |
| 127 | + *-------.--------.-------* |
| 128 | + | First : Second : Third | |
| 129 | + +-------:--------:-------+ |
| 130 | + | 10 : 30 : 40 | |
| 131 | + | 20 : 10 : 20 | |
| 132 | + | 30 : 20 : 30 | |
| 133 | + *-------'--------'-------* |
| 134 | + """ |
0 commit comments