1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-25 00:37:31 +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('-+'),
@ -208,17 +230,22 @@ def _normalize_rows(table: str) -> List[str]:
continue
# 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[0] = _snake_case(result[0])
return result
def _parse_pretty(table: List[str]) -> List[Dict[str, str]]:
return sparse_table_parse(table)
def parse(
data: str,
raw: bool = False,
@ -246,6 +273,6 @@ def parse(
data = _remove_ansi(data)
data = _strip(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)