add --card-flat-wrap option

This commit is contained in:
Johann Dreo 2023-08-10 21:17:21 +02:00
commit 0cf2a1bccf

18
twf.py Normal file → Executable file
View file

@ -1,8 +1,11 @@
#!/usr/bin/env python3
import os import os
import re import re
import sys import sys
import json import json
import argparse import argparse
import textwrap
import subprocess import subprocess
import rich import rich
@ -44,8 +47,9 @@ class Sectioner(Widget):
class task: class task:
class Card(Tasker): class Card(Tasker):
def __init__(self, show_only, order = None, touched = []): def __init__(self, show_only, order = None, touched = [], wrap_width = 25):
super().__init__(show_only, order, group = None, touched = touched) super().__init__(show_only, order, group = None, touched = touched)
self.wrap_width = wrap_width
def __call__(self, task): def __call__(self, task):
if not self.show_only: if not self.show_only:
@ -60,6 +64,8 @@ class task:
desc = task["description"] desc = task["description"]
title = sid title = sid
desc = "\n".join(textwrap.wrap(desc.strip(), self.wrap_width))
if sid in touched: if sid in touched:
title = "*"+title+"*" title = "*"+title+"*"
@ -81,7 +87,7 @@ class task:
# FIXME Columns does not fit. # FIXME Columns does not fit.
# cols = Columns(segments) # cols = Columns(segments)
cols = rich.console.Group(*segments, fit = True) cols = rich.console.Group(*segments, fit = True)
grp = rich.console.Group(desc.strip(), cols, fit = True) grp = rich.console.Group(desc, cols, fit = True)
panel = rich.panel.Panel(grp, title = title, panel = rich.panel.Panel(grp, title = title,
title_align="left", expand = False, padding = (0,1)) title_align="left", expand = False, padding = (0,1))
@ -218,7 +224,7 @@ if __name__ == "__main__":
formatter_class=argparse.ArgumentDefaultsHelpFormatter, formatter_class=argparse.ArgumentDefaultsHelpFormatter,
) )
parser.add_argument("-s", "--show", metavar="columns", type=str, default="id,urgency,description,tags", nargs=1, parser.add_argument("-s", "--show", metavar="columns", type=str, default="id,description,tags", nargs=1,
help="Ordered list of columns to show.") help="Ordered list of columns to show.")
config = parser.add_argument_group('configuration options') config = parser.add_argument_group('configuration options')
@ -227,6 +233,10 @@ if __name__ == "__main__":
config.add_argument("--list-separator", metavar="CHARACTER", type=str, default=",", nargs=1, config.add_argument("--list-separator", metavar="CHARACTER", type=str, default=",", nargs=1,
help="Separator used for lists that are passed as options arguments.") help="Separator used for lists that are passed as options arguments.")
layouts = parser.add_argument_group('layout options')
layouts.add_argument('--card-flat-wrap', metavar="NB", type=int, default=25,
help="Number of character at which to wrap the description of Flat Cards.")
# Capture whatever remains. # Capture whatever remains.
parser.add_argument('cmd', nargs="*") parser.add_argument('cmd', nargs="*")
@ -248,7 +258,7 @@ if __name__ == "__main__":
else: else:
show_only = showed show_only = showed
tasker = task.Card(show_only, touched) tasker = task.Card(show_only, touched, wrap_width = asked.card_flat_wrap)
stacker = stack.Flat(tasker) stacker = stack.Flat(tasker)
group_by_status = group.Status() group_by_status = group.Status()
sort_on_values = sort.OnValues(["pending","started","completed"]) sort_on_values = sort.OnValues(["pending","started","completed"])