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:
@ -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)
|
||||
|
@ -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('-+')
|
||||
)):
|
||||
@ -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('─┘'),
|
||||
@ -204,7 +229,15 @@ def _snake_case(line: str) -> str:
|
||||
def _fixup_separators(line: str) -> str:
|
||||
"""Normalize separators, and remove first and last separators"""
|
||||
# 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
|
||||
if line[0] == '|':
|
||||
|
Reference in New Issue
Block a user