1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add more pretty table separators

This commit is contained in:
Kelly Brazil
2022-03-22 17:47:19 -07:00
parent e5b478218c
commit f3aa797d96
2 changed files with 69 additions and 9 deletions

View File

@ -171,12 +171,34 @@ def _is_separator(line: str) -> bool:
strip_line.startswith('╒═') and strip_line.endswith('═╕'), strip_line.startswith('╒═') and strip_line.endswith('═╕'),
strip_line.startswith('╞═') and strip_line.endswith('═╡'), strip_line.startswith('╞═') and strip_line.endswith('═╡'),
strip_line.startswith('╘═') and strip_line.endswith('═╛'), strip_line.startswith('╘═') and strip_line.endswith('═╛'),
strip_line.startswith('┏━') and strip_line.endswith('━┓'),
strip_line.startswith('┣━') and strip_line.endswith('━┫'),
strip_line.startswith('┗━') and strip_line.endswith('━┛'),
strip_line.startswith('┡━') and strip_line.endswith('━┩'),
strip_line.startswith('┢━') and strip_line.endswith('━┪'),
strip_line.startswith('┟─') and strip_line.endswith('─┧'),
strip_line.startswith('┞─') and strip_line.endswith('─┦'),
strip_line.startswith('┠─') and strip_line.endswith('─┨'),
strip_line.startswith('┝━') and strip_line.endswith('━┥'),
strip_line.startswith('┍━') and strip_line.endswith('━┑'),
strip_line.startswith('┕━') and strip_line.endswith('━┙'),
strip_line.startswith('┎─') and strip_line.endswith('─┒'),
strip_line.startswith('┖─') and strip_line.endswith('─┚'),
strip_line.startswith('╓─') and strip_line.endswith('─╖'),
strip_line.startswith('╟─') and strip_line.endswith('─╢'),
strip_line.startswith('╙─') and strip_line.endswith('─╜'),
strip_line.startswith('╔═') and strip_line.endswith('═╗'),
strip_line.startswith('╠═') and strip_line.endswith('═╣'),
strip_line.startswith('╚═') and strip_line.endswith('═╝'),
strip_line.startswith('┌─') and strip_line.endswith('─┐'), strip_line.startswith('┌─') and strip_line.endswith('─┐'),
strip_line.startswith('├─') and strip_line.endswith('─┤'), strip_line.startswith('├─') and strip_line.endswith('─┤'),
strip_line.startswith('└─') and strip_line.endswith('─┘'), strip_line.startswith('└─') and strip_line.endswith('─┘'),
strip_line.startswith('') and strip_line.endswith(''), strip_line.startswith('') and strip_line.endswith(''),
strip_line.startswith('┡━') and strip_line.endswith('━┩'),
strip_line.startswith('──') and strip_line.endswith('──'), strip_line.startswith('──') and strip_line.endswith('──'),
strip_line.startswith('┄┄') and strip_line.endswith('┄┄'),
strip_line.startswith('┅┅') and strip_line.endswith('┅┅'),
strip_line.startswith('┈┈') and strip_line.endswith('┈┈'),
strip_line.startswith('┉┉') and strip_line.endswith('┉┉'),
strip_line.startswith('══') and strip_line.endswith('══'), strip_line.startswith('══') and strip_line.endswith('══'),
strip_line.startswith('+=') and strip_line.endswith('=+'), strip_line.startswith('+=') and strip_line.endswith('=+'),
strip_line.startswith('+-') and strip_line.endswith('-+'), strip_line.startswith('+-') and strip_line.endswith('-+'),
@ -208,17 +230,22 @@ def _normalize_rows(table: str) -> List[str]:
continue continue
# data row - remove column separators # data row - remove column separators
line = line.replace('', ' ').replace('|', ' ').replace('', ' ') line = line.replace('|', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')\
.replace('', ' ')
result.append(line) result.append(line)
result[0] = _snake_case(result[0]) result[0] = _snake_case(result[0])
return result return result
def _parse_pretty(table: List[str]) -> List[Dict[str, str]]:
return sparse_table_parse(table)
def parse( def parse(
data: str, data: str,
raw: bool = False, raw: bool = False,
@ -246,6 +273,6 @@ def parse(
data = _remove_ansi(data) data = _remove_ansi(data)
data = _strip(data) data = _strip(data)
data_list = _normalize_rows(data) data_list = _normalize_rows(data)
raw_output = _parse_pretty(data_list) raw_output = sparse_table_parse(data_list)
return raw_output if raw else _process(raw_output) return raw_output if raw else _process(raw_output)

View File

@ -163,6 +163,14 @@ def _table_sniff(string: str) -> str:
line.startswith('╞═') and line.endswith('═╡'), line.startswith('╞═') and line.endswith('═╡'),
line.startswith('├─') and line.endswith('─┤'), line.startswith('├─') and line.endswith('─┤'),
line.startswith('┡━') and line.endswith('━┩'), line.startswith('┡━') and line.endswith('━┩'),
line.startswith('┣━') and line.endswith('━┫'),
line.startswith('┢━') and line.endswith('━┪'),
line.startswith('┟─') and line.endswith('─┧'),
line.startswith('┞─') and line.endswith('─┦'),
line.startswith('┠─') and line.endswith('─┨'),
line.startswith('┝━') and line.endswith('━┥'),
line.startswith('╟─') and line.endswith('─╢'),
line.startswith('╠═') and line.endswith('═╣'),
line.startswith('+=') and line.endswith('=+'), line.startswith('+=') and line.endswith('=+'),
line.startswith('+-') and line.endswith('-+') line.startswith('+-') and line.endswith('-+')
)): )):
@ -185,7 +193,24 @@ def _is_separator(line: str) -> bool:
strip_line.startswith('╞═') and strip_line.endswith('═╡'), strip_line.startswith('╞═') and strip_line.endswith('═╡'),
strip_line.startswith('╘═') and strip_line.endswith('═╛'), strip_line.startswith('╘═') and strip_line.endswith('═╛'),
strip_line.startswith('┏━') and strip_line.endswith('━┓'), strip_line.startswith('┏━') and strip_line.endswith('━┓'),
strip_line.startswith('┣━') and strip_line.endswith('━┫'),
strip_line.startswith('┗━') and strip_line.endswith('━┛'),
strip_line.startswith('┡━') and strip_line.endswith('━┩'), strip_line.startswith('┡━') and strip_line.endswith('━┩'),
strip_line.startswith('┢━') and strip_line.endswith('━┪'),
strip_line.startswith('┟─') and strip_line.endswith('─┧'),
strip_line.startswith('┞─') and strip_line.endswith('─┦'),
strip_line.startswith('┠─') and strip_line.endswith('─┨'),
strip_line.startswith('┝━') and strip_line.endswith('━┥'),
strip_line.startswith('┍━') and strip_line.endswith('━┑'),
strip_line.startswith('┕━') and strip_line.endswith('━┙'),
strip_line.startswith('┎─') and strip_line.endswith('─┒'),
strip_line.startswith('┖─') and strip_line.endswith('─┚'),
strip_line.startswith('╓─') and strip_line.endswith('─╖'),
strip_line.startswith('╟─') and strip_line.endswith('─╢'),
strip_line.startswith('╙─') and strip_line.endswith('─╜'),
strip_line.startswith('╔═') and strip_line.endswith('═╗'),
strip_line.startswith('╠═') and strip_line.endswith('═╣'),
strip_line.startswith('╚═') and strip_line.endswith('═╝'),
strip_line.startswith('┌─') and strip_line.endswith('─┐'), strip_line.startswith('┌─') and strip_line.endswith('─┐'),
strip_line.startswith('├─') and strip_line.endswith('─┤'), strip_line.startswith('├─') and strip_line.endswith('─┤'),
strip_line.startswith('└─') and strip_line.endswith('─┘'), strip_line.startswith('└─') and strip_line.endswith('─┘'),
@ -204,7 +229,15 @@ def _snake_case(line: str) -> str:
def _fixup_separators(line: str) -> str: def _fixup_separators(line: str) -> str:
"""Normalize separators, and remove first and last separators""" """Normalize separators, and remove first and last separators"""
# normalize separator # normalize separator
line = line.replace('', '|').replace('', '|') line = line.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')\
.replace('', '|')
# remove first separator if it is the first char in the line # remove first separator if it is the first char in the line
if line[0] == '|': if line[0] == '|':