From 8b0a523f774d4f2ed2b7b9431e22b21c9d4a7312 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 9 Mar 2013 09:00:50 +0100 Subject: [PATCH] Page comic listings. --- doc/changelog.txt | 5 ++++- dosage | 13 +++++++++++-- dosagelib/output.py | 7 ++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index 43f4d41e5..18b55a1e0 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -3,7 +3,10 @@ Dosage 1.13 (released xx.xx.2013) Features: - comics: Added comic strips AhoiPolloi, AxeCop, Bearmageddon, DeadWinter, HarkAVagrant, IAmArg, LoadingArtist, Nnewts, PHDComics, PokeyThePenguin, - SnowFlame and WorldOfMrToast, Zwarwald. + SnowFlame, WorldOfMrToast and Zwarwald. + +Changes: +- cmdline: Comic lists are now displayed one page at a time. Fixes: - cmdline: Catch error when piping output to another diff --git a/dosage b/dosage index 5b5fe4bcb..5ae4f83b5 100755 --- a/dosage +++ b/dosage @@ -15,6 +15,7 @@ import os import argparse import pydoc from collections import OrderedDict +from cStringIO import StringIO from dosagelib import events, scraper from dosagelib.output import out @@ -206,6 +207,12 @@ def run(options): def doList(columnList=True, verbose=False): """List available comics.""" + page = hasattr(sys.stdout, "isatty") and sys.stdout.isatty() + if page: + fd = StringIO() + else: + fd = sys.stdout + out.setStream(fd) out.info('Available comic scrapers:') out.info('Comics marked with [A] require age confirmation with the --adult option.') scrapers = sorted(getScrapers(['@@']), key=lambda s: s.getName()) @@ -214,6 +221,8 @@ def doList(columnList=True, verbose=False): else: num = doSingleList(scrapers, verbose=verbose) out.info('%d supported comics.' % num) + if page: + pydoc.pager(fd.getvalue()) return 0 @@ -223,7 +232,7 @@ def doSingleList(scrapers, verbose=False): if verbose: displayComicHelp(scraperobj) else: - print(getScraperName(scraperobj)) + out.info(getScraperName(scraperobj)) return num @@ -237,7 +246,7 @@ def doColumnList(scrapers): maxlen = max(len(name) for name in names) namesPerLine = max(int(screenWidth / (maxlen + 1)), 1) while names: - print(''.join(name.ljust(maxlen) for name in names[:namesPerLine])) + out.info(''.join(name.ljust(maxlen) for name in names[:namesPerLine])) del names[:namesPerLine] return num diff --git a/dosagelib/output.py b/dosagelib/output.py index ca5c0dc2f..44c4cc811 100644 --- a/dosagelib/output.py +++ b/dosagelib/output.py @@ -17,6 +17,10 @@ class Output(object): self.context = '' self.level = 0 self.timestamps = False + self.setStream(stream) + + def setStream(self, stream): + """Initialize context and indentation.""" self.stream = Colorizer(stream) def info(self, s, level=0): @@ -44,7 +48,8 @@ class Output(object): else: timestamp = '' with lock: - self.stream.write('%s%s> ' % (timestamp, self.context)) + if self.context or timestamp: + self.stream.write('%s%s> ' % (timestamp, self.context)) self.stream.write('%s' % s, color=color) self.stream.write(os.linesep) self.stream.flush()