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