space separation for tags + tag color

main
Fabien Benureau 11 years ago
parent 523fe888a3
commit c692f23054

@ -20,6 +20,7 @@ error = red
normal = grey normal = grey
citekey = purple citekey = purple
filepath = cyan filepath = cyan
tag = blue
def dye(s, color=end, bold=False): def dye(s, color=end, bold=False):
assert color[0] == '\033' assert color[0] == '\033'

@ -17,25 +17,33 @@ The different use cases are :
display all papers with the tag 'math', 'romance' but not 'war' display all papers with the tag 'math', 'romance' but not 'war'
""" """
import re
from ..repo import Repository, InvalidReference from ..repo import Repository, InvalidReference
from ..configs import config from ..configs import config
from ..uis import get_ui from ..uis import get_ui
from .. import pretty from .. import pretty
from .. import color
def parser(subparsers): def parser(subparsers):
parser = subparsers.add_parser('tag', help="add, remove and show tags") parser = subparsers.add_parser('tag', help="add, remove and show tags")
parser.add_argument('citekeyOrTag', nargs='?', default = None, parser.add_argument('citekeyOrTag', nargs='?', default = None,
help='citekey or tag.') help='citekey or tag.')
parser.add_argument('tags', nargs='?', default = None, parser.add_argument('tags', nargs='*', default = None,
help='If the previous argument was a citekey, then ' help='If the previous argument was a citekey, then '
'then a list of tags separated by a +.') 'then a list of tags separated by a +.')
# TODO find a way to display clear help for multiple command semantics, # TODO find a way to display clear help for multiple command semantics,
# indistinguisable for argparse. (fabien, 201306) # indistinguisable for argparse. (fabien, 201306)
return parser return parser
def _parse_tags(list_tags):
"""Transform 'math-ai network -search' in ['+math', '-ai', '+network', '-search']"""
tags = []
for s in list_tags:
tags += _parse_tag_seq(s)
return tags
import re def _parse_tag_seq(s):
def _parse_tags(s):
"""Transform 'math-ai' in ['+math', '-ai']""" """Transform 'math-ai' in ['+math', '-ai']"""
tags = [] tags = []
if s[0] not in ['+', '-']: if s[0] not in ['+', '-']:
@ -76,12 +84,14 @@ def command(args):
if citekeyOrTag is None: if citekeyOrTag is None:
for tag in rp.get_tags(): for tag in rp.get_tags():
ui.print_(tag) ui.print_(color.dye(' '.join(rp.get_tags()),
color=color.blue))
else: else:
if rp.databroker.exists(citekeyOrTag): if rp.databroker.exists(citekeyOrTag):
p = rp.pull_paper(citekeyOrTag) p = rp.pull_paper(citekeyOrTag)
if tags is None: if tags == []:
ui.print_(' '.join(p.tags)) ui.print_(color.dye(' '.join(p.tags),
color=color.blue))
else: else:
add_tags, remove_tags = _tag_groups(_parse_tags(tags)) add_tags, remove_tags = _tag_groups(_parse_tags(tags))
for tag in add_tags: for tag in add_tags:
@ -91,7 +101,9 @@ def command(args):
rp.push_paper(p, overwrite=True) rp.push_paper(p, overwrite=True)
else: else:
# case where we want to find papers with specific tags # case where we want to find papers with specific tags
included, excluded = _tag_groups(_parse_tags(citekeyOrTag)) all_tags = [citekeyOrTag]
all_tags += tags
included, excluded = _tag_groups(_parse_tags(all_tags))
papers_list = [] papers_list = []
for n, p in enumerate(rp.all_papers()): for n, p in enumerate(rp.all_papers()):
if (p.tags.issuperset(included) and if (p.tags.issuperset(included) and

@ -61,5 +61,5 @@ def paper_oneliner(p, n = 0, citekey_only = False):
citekey=color.dye(p.citekey, color.purple), citekey=color.dye(p.citekey, color.purple),
descr=bibdesc, descr=bibdesc,
tags=color.dye(' '.join(p.tags), tags=color.dye(' '.join(p.tags),
color.purple, bold=True), color.tag, bold=False),
)).encode('utf-8') )).encode('utf-8')
Loading…
Cancel
Save