|
|
@ -1,4 +1,3 @@ |
|
|
|
|
|
|
|
|
|
|
|
import click |
|
|
|
import click |
|
|
|
import pyperclip |
|
|
|
import pyperclip |
|
|
|
|
|
|
|
|
|
|
@ -13,25 +12,25 @@ def split_table(text): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cell_lengths(table): |
|
|
|
def get_cell_lengths(table): |
|
|
|
tmp = { } |
|
|
|
tmp = {} |
|
|
|
|
|
|
|
|
|
|
|
for row in table: |
|
|
|
for row in table: |
|
|
|
for i, cell in enumerate(row): |
|
|
|
for i, cell in enumerate(row): |
|
|
|
if i not in tmp: |
|
|
|
if i not in tmp: |
|
|
|
tmp[i] = [] |
|
|
|
tmp[i] = [] |
|
|
|
tmp[i].append(len(cell)) |
|
|
|
tmp[i].append(len(cell)) |
|
|
|
|
|
|
|
|
|
|
|
return {k: max(v) for k, v in tmp.items()} |
|
|
|
return {k: max(v) for k, v in tmp.items()} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_table(table, lengths): |
|
|
|
def build_table(table, lengths): |
|
|
|
text_rows = [_build_row(row, lengths) for row in table] |
|
|
|
text_rows = [_build_row(row, lengths) for row in table] |
|
|
|
header, *rest = text_rows |
|
|
|
header, *rest = text_rows |
|
|
|
sep_items = [ |
|
|
|
sep_items = ["-" * lengths[k] for k in sorted(lengths.keys())] |
|
|
|
"-" * lengths[k] for k in sorted(lengths.keys()) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
separator = _build_line(sep_items) |
|
|
|
separator = _build_line(sep_items) |
|
|
|
lines = [header, separator] + rest |
|
|
|
lines = [header, separator] + rest |
|
|
|
return "\r\n".join(lines) |
|
|
|
return "\r\n".join(lines) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _build_row(row, lengths): |
|
|
|
def _build_row(row, lengths): |
|
|
|
items = [] |
|
|
|
items = [] |
|
|
@ -40,12 +39,12 @@ def _build_row(row, lengths): |
|
|
|
items.append(cell.ljust(length)) |
|
|
|
items.append(cell.ljust(length)) |
|
|
|
return _build_line(items) |
|
|
|
return _build_line(items) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _build_line(items): |
|
|
|
def _build_line(items): |
|
|
|
tmp = " | ".join(items) |
|
|
|
tmp = " | ".join(items) |
|
|
|
return f"| {tmp} |" |
|
|
|
return f"| {tmp} |" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command() |
|
|
|
@click.command() |
|
|
|
def cli(): |
|
|
|
def cli(): |
|
|
|
xls = pyperclip.paste() |
|
|
|
xls = pyperclip.paste() |
|
|
@ -54,4 +53,3 @@ def cli(): |
|
|
|
result = build_table(table, lengths) |
|
|
|
result = build_table(table, lengths) |
|
|
|
print("copied to clipboard") |
|
|
|
print("copied to clipboard") |
|
|
|
pyperclip.copy(result) |
|
|
|
pyperclip.copy(result) |
|
|
|
|
|
|
|
|
|
|
|