diff --git a/papers/color.py b/papers/color.py index 758b094..c62d704 100644 --- a/papers/color.py +++ b/papers/color.py @@ -46,7 +46,7 @@ def colored(s, color=None, bold=False): color_code = COLORS[color] except KeyError: if bold: - color_code = CODE + color_code = BOLD else: color_code = '' if color_code != '': @@ -54,3 +54,7 @@ def colored(s, color=None, bold=False): else: end_code = '' return color_code + s + end_code + + +def not_colored(s, **kwargs): + return s diff --git a/papers/commands/list_cmd.py b/papers/commands/list_cmd.py index 27286f7..50cff68 100644 --- a/papers/commands/list_cmd.py +++ b/papers/commands/list_cmd.py @@ -1,8 +1,4 @@ -import subprocess -import tempfile - from .. import pretty -from ..color import colored from .. import repo @@ -15,14 +11,10 @@ def command(config, ui): rp = repo.Repository.from_directory() articles = [] for n, p in enumerate(rp.all_papers()): - bibdesc = pretty.bib_oneliner(p.bibentry) + bibdesc = pretty.bib_oneliner(p.bibentry, color=ui.color) articles.append((u'{num:d}: [{citekey}] {descr}'.format( num=int(n), - citekey=colored(rp.citekeys[n], 'purple'), + citekey=ui.colored(rp.citekeys[n], 'purple'), descr=bibdesc, )).encode('utf-8')) - - with tempfile.NamedTemporaryFile(suffix=".tmp", delete=True) as tmpf: - tmpf.write('\n'.join(articles)) - tmpf.flush() - subprocess.call(['less', '-XRF', tmpf.name]) + ui.print_('\n'.join(articles)) diff --git a/papers/pretty.py b/papers/pretty.py index 9775980..a094a05 100644 --- a/papers/pretty.py +++ b/papers/pretty.py @@ -1,6 +1,6 @@ # display formatting -from color import colored +from color import colored, not_colored from pybtex.bibtex.utils import bibtex_purify @@ -26,7 +26,11 @@ def short_authors(bibentry): return '' -def bib_oneliner(bibentry): +def bib_oneliner(bibentry, color=True): + if color: + col_func = colored + else: + col_func = not_colored authors = short_authors(bibentry) title = bibtex_purify(bibentry.fields['title']) year = bibtex_purify(bibentry.fields.get('year', '')) @@ -36,9 +40,9 @@ def bib_oneliner(bibentry): field = 'booktitle' journal = bibtex_purify(bibentry.fields.get(field, '')) return u'{authors} \"{title}\" {journal} ({year})'.format( - authors=colored(authors, 'cyan'), + authors=col_func(authors, 'cyan'), title=title, - journal=colored(journal, 'yellow'), + journal=col_func(journal, 'yellow'), year=year, )