use Rich for showing cards

This commit is contained in:
Johann Dreo 2023-07-29 17:43:22 +02:00
commit 2ce763fdd2
2 changed files with 29 additions and 53 deletions

View file

@ -9,3 +9,4 @@
9,"TODO","fix add","'add' should prompt for columns content.","","","2023-07-29T15:47:01.948986" 9,"TODO","fix add","'add' should prompt for columns content.","","","2023-07-29T15:47:01.948986"
10,"TODO","fix delete","'delete' print the kanban not updated","","","2023-07-29T15:47:54.063379" 10,"TODO","fix delete","'delete' print the kanban not updated","","","2023-07-29T15:47:54.063379"
11,"TODO","fix quotes","After 'add', empty columns got remaining quotes.","","","2023-07-29T15:48:48.804824" 11,"TODO","fix quotes","After 'add', empty columns got remaining quotes.","","","2023-07-29T15:48:48.804824"
12,"TODO","test","","UX,data,git,core,code,meta,shit,fuck","","2023-07-29T17:32:18.081371"

1 ID STATUS TITLE DETAILS TAGS DEADLINE TOUCHED
9 9 TODO fix add 'add' should prompt for columns content. 2023-07-29T15:47:01.948986
10 10 TODO fix delete 'delete' print the kanban not updated 2023-07-29T15:47:54.063379
11 11 TODO fix quotes After 'add', empty columns got remaining quotes. 2023-07-29T15:48:48.804824
12 12 TODO test UX,data,git,core,code,meta,shit,fuck 2023-07-29T17:32:18.081371

View file

@ -13,6 +13,7 @@ import rich.console as richconsole
from rich.table import Table from rich.table import Table
from rich.text import Text from rich.text import Text
from rich.panel import Panel from rich.panel import Panel
from rich.columns import Columns
from rich import box from rich import box
@ -229,13 +230,31 @@ def show(context, tid):
df = context.obj['data'] df = context.obj['data']
row = df.loc[tid] row = df.loc[tid]
t_label = ["", "", ""] console = richconsole.Console()
t_top = ["", "", "", "", ""]
t_body = ["", " ", ""]
t_sep = ["", "", ""]
t_bottom = ["", "", ""]
width = len(datetime.datetime.now().isoformat()) table = Table(box = None, show_header = False)
table.add_column("Task")
def add_row_text(table, key, icon = ''):
if context.obj[key] in context.obj['show_keys']:
if str(row[context.obj[key]]) != "nan": # FIXME WTF?
table.add_row(icon + row[context.obj[key]])
else:
return
def add_row_list(table, key = context.obj['tags_key'], icon = ''):
if context.obj[key] in context.obj['show_keys']:
if str(row[context.obj[key]]) != "nan": # FIXME WTF?
tags = [icon+t for t in row[context.obj[key]].split(',')]
columns = Columns(tags, expand = False)
table.add_row(columns)
else:
return
add_row_text(table, 'details_key')
add_row_list(table, 'tags_key', '🏷 ')
add_row_text(table, 'deadline_key', '🗓')
add_row_text(table, 'touched_key', ':calendar-text:')
# Label content. # Label content.
l = [] l = []
@ -243,55 +262,11 @@ def show(context, tid):
l.append(str(tid)) l.append(str(tid))
if context.obj['title_key'] in context.obj['show_keys']: if context.obj['title_key'] in context.obj['show_keys']:
l.append(row[context.obj['title_key']]) l.append(row[context.obj['title_key']])
lbl = ":".join(l) label = ": ".join(l)
label = textwrap.shorten(lbl, width=width, placeholder="")
# Label format. panel = Panel.fit(table, title = label, title_align="left")
card = t_label[0] + t_label[1]*len(label) + t_label[2] + "\n" console.print(panel)
card += t_body[0] + label + t_body[2] + "\n"
card += t_top[0] + t_top[1]*len(label) + t_top[2] + t_top[3]*(width-len(label)-1) + t_top[4] + "\n"
if context.obj['details_key'] in context.obj['show_keys']:
if str(row[context.obj['details_key']]) != "nan": # FIXME WTF?
d = row[context.obj['details_key']]
else:
d = ''
details = textwrap.wrap(d, width)
for line in details:
card += t_body[0] + line + t_body[1]*(width-len(line)) + t_body[2] + "\n"
if context.obj['tags_key'] in context.obj['show_keys']:
card += t_sep[0] + t_sep[1]*width + t_sep[2] + "\n"
if str(row[context.obj['tags_key']]) != "nan": # FIXME WTF?
t = row[context.obj['tags_key']]
else:
t = ''
tags = textwrap.wrap(t, width)
for line in tags:
card += t_body[0] + line + t_body[1]*(width-len(line)) + t_body[2] + "\n"
if context.obj['deadline_key'] in context.obj['show_keys']:
card += t_sep[0] + t_sep[1]*width + t_sep[2] + "\n"
if str(row[context.obj['deadline_key']]) != "nan": # FIXME WTF?
t = row[context.obj['deadline_key']]
else:
t = ''
deadline = textwrap.wrap(t, width)
for line in deadline:
card += t_body[0] + line + t_body[1]*(width-len(line)) + t_body[2] + "\n"
if context.obj['touched_key'] in context.obj['show_keys']:
card += t_sep[0] + t_sep[1]*width + t_sep[2] + "\n"
if str(row[context.obj['touched_key']]) != "nan": # FIXME WTF?
t = row[context.obj['touched_key']]
else:
t = ''
touched = textwrap.wrap(t, width)
for line in touched:
card += t_body[0] + line + t_body[1]*(width-len(line)) + t_body[2] + "\n"
card += t_bottom[0] + t_bottom[1]*width + t_bottom[2] # No newline.
print(card)
@cli.command() @cli.command()