An ASCII text table renderer.
Project description
def table_string(table_columns: List[dict], table_dict: List[dict], header: bool=True, footer: bool=True) -> str:
# analyse table_dict for lengths?
table_width = 1
return_string = ""
for table_column in table_columns:
table_width += table_column["width"] + 1
if header:
# return_string += f"{'=' * table_width}\n"
for i, table_column in enumerate(table_columns):
if i == 0:
return_string += f" {table_column['name']}{' ' * (table_column['width'] - len(table_column['name']) - 1)}"
return_string += "|\n"
for table_column in table_columns:
return_string += f"┼{'-' * table_column['width']}"
return_string += "|\n"
for table_column in table_columns:
return_string += f"|{' ' * table_column['width']}"
return_string += "|\n"
for table_column in table_columns:
return_string += f"|{' ' * table_column['width']}"
return_string += "|\n"
for table_column in table_columns:
return_string += f"|{' ' * table_column['width']}"
return_string += "|\n"
# return_string += f"{'=' * table_width}\n"
for table_row in table_dict:
for table_cell in table_row.items():
pass
return return_string
test_columns = [
{
"width": 40,
"name": "Projects"
},
{
"width": 20,
"name": "Epochs"
},
{
"width": 20,
"name": "Collections"
},
]
print(table_string(test_columns, test_columns))
"""
┏━━━━━━━━┳━━━━━━━┓
┃ item ┃ qty ┃
┣━━━━━━━━╋━━━━━━━┫
┃ spam ┃ 42 ┃
┣━━━━━━━━╋━━━━━━━┫
┃ eggs ┃ 451 ┃
┣━━━━━━━━╋━━━━━━━┫
┃ bacon ┃ 0 ┃
┗━━━━━━━━┻━━━━━━━┛
╔════════════════╗
║ item ┃ qty ║
╠════════════════╣
║ spam ┃ 42 ║
║━━━━━━━━╋━━━━━━━║
║ eggs ┃ 451 ║
║━━━━━━━━╋━━━━━━━║
║ bacon ┃ 0 ║
╚════════════════╝
╔════════════════╗
║ item ┃ qty ║
╠════════════════╣
║ spam ┃ 42 ║
╠════════════════╣
║ eggs ┃ 451 ║
╠════════════════╣
║ bacon ┃ 0 ║
╚════════════════╝
┏━━━━━━━━┯━━━━━━━┓
┃ item │ qty ┃
┠────────┼───────┨
┃ spam │ 42 ┃
┠────────┼───────┨
┃ eggs │ 451 ┃
┠────────┼───────┨
┃ bacon │ 0 ┃
┗━━━━━━━━┷━━━━━━━┛
┏━━━━━━━━┳━━━━━━━┓
┃ item ┃ qty ┃
┣━━━━━━━━╇━━━━━━━┫
┃ spam │ 42 ┃
┠────────┼───────┨
┃ eggs │ 451 ┃
┠────────┼───────┨
┃ bacon │ 0 ┃
┗━━━━━━━━┷━━━━━━━┛
╔════════════════════════════════════════════╤═════╤═════╤═════╤═════╗
║ asdasdasd asdasdasd │ asd │ asd │ asd │ sdf ║
╠════════════════════════════════════════════╪═════╪═════╪═════╪═════╣
║ asd │ asd │ asd │ asd │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╚════════════════════════════════════════════╧═════╧═════╧═════╧═════╝
╔════════════════════════════════════════════════════════════════════╗
║ PROJECT: Some Project ║
╟────────────────────────────────────────────────────────────────────╢
║ And here is the project descript, whatever it might be. It might ║
║ even be several lines. ║
╠════════════════════════════════════════════╤═════╤═════╤═════╤═════╣
║ EPOCHS │ asd │ asd │ asd │ sdf ║
╠════════════════════════════════════════════╪═════╪═════╪═════╪═════╣
║ asd │ asd │ asd │ asd │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╚════════════════════════════════════════════╧═════╧═════╧═════╧═════╝
╔════════════════════════════════════════════════════════════════════╗
║ PROJECT: Some Project ║
╟────────────────────────────────────────────────────────────────────╢
║ And here is the project descript, whatever it might be. It might ║
║ even be several lines. ║
╠════════════════════════════════════════════╤═════╤═════╤═════╤═════╣
║ EPOCHS │ asd │ asd │ asd │ sdf ║
╠════════════════════════════════════════════╪═════╪═════╪═════╪═════╣
║ asd │ asd │ asd │ asd │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ sdf │ sdf │ sdf │ sdf │ sdf ║
╚════════════════════════════════════════════╧═════╧═════╧═════╧═════╝
╔════════════════════════════════════════════════════════════════════╗
║ PROJECT: Some Project ║
╟────────────────────────────────────────────────────────────────────╢
║ And here is the project descript, whatever it might be. ║
╠════════════════════════════════════════════╤═════╤═════╤═════╤═════╣
║ EPOCHS │ asd │ asd │ asd │ sdf ║
╠════════════════════════════════════════════╪═════╪═════╪═════╪═════╣
║ Getting started │ asd │ asd │ asd │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ Moving forward │ sdf │ sdf │ sdf │ sdf ║
╟────────────────────────────────────────────┼─────┼─────┼─────┼─────╢
║ Cleaning up │ sdf │ sdf │ sdf │ sdf ║
╚════════════════════════════════════════════╧═════╧═════╧═════╧═════╝
╔════════════════════════════════════════════╤═══════╤═══════╤═══════╤════════╗
║ asdasdasd │ asd │ asd │ asd │ asd ║
╟────────────────────────────────────────────┼───────┼───────┼───────┼────────╢
║ asd │ asd │ asd │ asd │ asd ║
║ sdf │ asd │ asd │ asd │ asd ║
║ sdf │ asd │ asd │ asd │ asd ║
╚════════════════════════════════════════════╧═══════╧═══════╧═══════╧════════╝
┌────────────────────────────────────────────┬─────┬─────┬─────┬─────┐
│ asdasdasd │ asd │ asd │ asd │ sdf │
├────────────────────────────────────────────┼─────┼─────┼─────┼─────┤
│ asd │ asd │ asd │ asd │ sdf │
│ sdf │ sdf │ sdf │ sdf │ sdf │
│ sdf │ sdf │ sdf │ sdf │ sdf │
└────────────────────────────────────────────┴─────┴─────┴─────┴─────┘
┌────────────────────────────────────────────┬─────┬─────┬─────┬─────┐
│ asdasdasd asdasdasd │ asd │ asd │ asd │ sdf │
╞════════════════════════════════════════════╪═════╪═════╪═════╪═════╡
│ asd │ asd │ asd │ asd │ sdf │
│ sdf │ sdf │ sdf │ sdf │ sdf │
│ sdf │ sdf │ sdf │ sdf │ sdf │
└────────────────────────────────────────────┴─────┴─────┴─────┴─────┘
"""
"""
│ ┃ ║
─ ━ ═
┌ ┏ ╔ ┍ ┎ ╒ ╓ * 4
├ ┣ ╠ ┠ ┝ ╟ ╞
┤ ┫ ╣ ┨ ┥ ╢ ╡
┼ ╋ ╬ ╂ ┿ ╀ ╁ ╇ ╈ ╫ ╪
"""
x = [
"thin",
"thick",
"thin"
"┿"
]
"""
│ ║
─ ═
┌ ╔ ╒ ╓ * 4
├ ╠ ╟ ╞
┤ ╣ ╢ ╡
┼ ╬ ╫ ╪
"""
"""
only thin for inner column... yes!
│ ┃ ║
─ ━ ═
┌ ┏ ╔ ┍ ┎ ╒ ╓ * 4
├ ┣ ╠ ┠ ┝ ╟ ╞ ║ ┃
┤ ┫ ╣ ┨ ┥ ╢ ╡ ║
┼ ┿ ╪
"""
"""
only thin for inner column...
same same outer border...
yes yes!!!
│ ┃ ║
─ ━ ═
┌ ┏ ╔ * 4
├ ┣ ╠ ┠ ┝ ╟ ╞ ║ ┃
┤ ┫ ╣ ┨ ┥ ╢ ╡ ║ ┃
┼ ┿ ╪
"""
"""
only thin for inner column...
same same outer border...
yes yes!!!
(sorted by outer first)
│ ┃ ║
─ ━ ═
┌ ┏ ╔ * 4
├ ┝ ╞ ┠ ┠ ┃ ╟ ║ ╠
┤ ┥ ╡ ┨ ┫ ┃ ╢ ║ ╣
┼ ┿ ╪
manageable...
"""
left_side_matrix = {
"thin": {
"thin": "├",
"thick": "┝",
"double": "╞"
},
"thick": {
"thin": "┠",
"thick": "┣",
"double": "┃"
},
"double": {
"thin": "╟",
"thick": "║",
"double": "╠"
}
}
right_side_matrix = {
"thin": {
"thin": "┤",
"thick": "┥",
"double": "╡"
},
"thick": {
"thin": "┨",
"thick": "┫",
"double": "┃"
},
"double": {
"thin": "╢",
"thick": "║",
"double": "╣"
}
}
# A - is this an outer_border
# 1 - determine border type
# 2 - populate edge characters (in array [a])
# 2 - populate line (in array [b]) with line type
# 3 - calculate intersections (in an array of arrays [c])
# 5 - populate intersection (in array [b])
# 6 - generate string
# B - is this a line row (should really only be between frames, me thinks...) (maybe each table row is a frame?)
# 1 - determine line type
# 2 - populate edge characters (in array [a])
# 3 - populate line (in array [b]) with line type
# 4 - calculate intersections (in an array of arrays [c])
# 5 - populate intersection (in array [b])
# 6 - generate string
# C - is this a text line
# 1 - populate edge characters (in array [a])
# 2 - generate string
# how much of this should be done above? ie: should the print just have complete frames? just handling the edge character?
# (more specifically, handling the line rows above?)
row_index = 0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tablestring-0.0.4.tar.gz
(10.4 kB
view details)
Built Distribution
File details
Details for the file tablestring-0.0.4.tar.gz
.
File metadata
- Download URL: tablestring-0.0.4.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e174db424f1662558f2ec8a6e9f4596ce5c96356410612a8fc0a4a69c1b9b33f |
|
MD5 | c860b7001023f808d868522a9ba8ab09 |
|
BLAKE2b-256 | 00054022ad245dea48d78fb7581c93dde597d1a867047c0dde5b8d4a769765b0 |
File details
Details for the file tablestring-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: tablestring-0.0.4-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af0899387ecc7ecee838b29f04b23bdee2c3ed3f06ea76c73b77907784fc5e8 |
|
MD5 | 607aaedcde1bc1b1b2a6b38bfe45c8f9 |
|
BLAKE2b-256 | 61baaefc525645429442e8c38e9414072ee2e9d8eb850ed536583985104e8e91 |