...
 
Commits (3)
__pycache__/
*.py[cod]
*$py.class
build/
*.egg
*.egg-info/
.eggs
.tox/
.cache/
src/twc/_version.py
tags
.tags
......@@ -27,25 +27,10 @@ import mgcomm.env
from twc.locale import _
_defaults = OrderedDict((
('keys', OrderedDict((
('nav-down', 'j'),
('nav-up', 'k'),
('nav-right', 'l'),
('nav-left', 'h'),
('refresh', 'r'),
('sync', 'S'),
('quit', 'q'),
('task-modify', 'enter'),
('task-edit', 'e'),
))),
))
@attr.s
class Block:
name = attr.ib()
fmt = attr.ib('<m class=highlight>{id: >4}</m> {description}')
fmt = attr.ib('{description}')
filter = attr.ib(None)
sort = attr.ib(None)
height = attr.ib('100%')
......@@ -76,7 +61,10 @@ class Config:
def set_color(self, name, fg='', bg=''):
'''Defines a color pair (foreground and background) with a given name.
It can be later used e.g. in blocks's format strings.'''
self.colors[name] = (fg.strip(), bg.strip())
focus_name = '{}-focus'.format(name)
color_pair = (fg.strip(), bg.strip())
self.colors[name] = color_pair
self.colors.setdefault(focus_name, color_pair)
def set(self, key, value):
'''Changes a setting'''
......@@ -88,13 +76,22 @@ class Config:
@colors.default
def _default_colors(self):
return {
colors = {
# name : (fg, bg)
'header': ('light blue', ''),
'text': ('white', ''),
'highlight': ('yellow', ''),
'comment': ('light gray', ''),
'info': ('light blue', ''),
'warning': ('dark red', ''),
}
# pre-compute default focus for all default markups
default_focus = ('standout', '')
focus = [ ('{}-focus'.format(c), default_focus) for c in colors ]
colors.update(focus)
return colors
@settings.default
def _default_settings(self):
return {
......@@ -106,7 +103,7 @@ def _create_default_blocks(cfg):
cfg.add_block('default',
name='Next tasks',
filter='status:pending',
fmt = '{id: >4} <m class=highlight>{priority:<2}</m>{description} <m class=highlight>{tags:>}</m>',
fmt = '<m class=comment>{id: >4}</m> <m class=warning>{priority:<2}</m>{description} <m class=info>{tags:>}</m>',
sort='priority-,id+',
height='70%')
......
......@@ -22,6 +22,12 @@ import shlex
def process_filter(f):
if not f:
return []
# TODO: search for limit:<l>. It should be extracted and applied after sort.
# Also remember about different forms of limit:
# - (limit:blah)
# ... and limit:blah
# etc...
# (mgoral, 2019-04-12)
return shlex.split(f)
......
......@@ -33,6 +33,8 @@ def _dim(dimstr, realdim):
class Task(urwid.Text):
_selectable = True
def __init__(self, screen, data, fmt):
# TODO: how can term be used? (mgl, 2019-04-11)
data['tags'] = ':'.join(data.setdefault('tags', []))
......@@ -52,12 +54,19 @@ class Task(urwid.Text):
class BlockView(urwid.BoxAdapter):
def __init__(self, screen, tw, block):
def __init__(self, screen, cfg, tw, block):
self.block = block
self.tasks = twutils.filter_tasks(block.filter, tw)
textboxes = [Task(screen, t, self.block.fmt) for t in self.tasks]
focus_map = { c : '{}-focus'.format(c)
for c in cfg.colors if not c.endswith('-focus') }
focus_map[None] = 'text-focus'
textboxes = [urwid.AttrMap(Task(screen, t, self.block.fmt),
None, focus_map)
for t in self.tasks]
lw = urwid.ListBox(urwid.SimpleFocusListWalker(textboxes))
lb = urwid.LineBox(lw, title=self.block.name)
height = _dim(self.block.height, screen.get_cols_rows()[1])
......@@ -65,8 +74,8 @@ class BlockView(urwid.BoxAdapter):
class AgendaView(urwid.ListBox):
def __init__(self, screen, tw, agenda):
blocks = [BlockView(screen, tw, block) for block in agenda.blocks]
def __init__(self, screen, cfg, tw, agenda):
blocks = [BlockView(screen, cfg, tw, block) for block in agenda.blocks]
super().__init__(blocks)
......@@ -75,5 +84,5 @@ class MainWindow(urwid.Frame):
def __init__(self, screen, cfg, tw):
name = next(iter(cfg.agendas))
agenda = cfg.agendas[name]
self.view = AgendaView(screen, tw, agenda)
self.view = AgendaView(screen, cfg, tw, agenda)
super().__init__(self.view)
import functools
import pytest
import twc.markup as markup
@pytest.mark.parametrize('fmt,expected', [
('', []),
('foo bar', ['foo bar']),
('foo <m class=highlight>bar baz</m> blah',
['foo ', ('highlight', 'bar baz'), ' blah']),
('foo <m class="highlight">bar baz</m> blah',
['foo ', ('highlight', 'bar baz'), ' blah']),
])
def test_markup(fmt,expected):
p = markup.Parser()
p.feed(fmt)
assert p.markup == expected