diff -Nru fabulous-0.3.0+dfsg1/debian/changelog fabulous-0.4.0+dfsg1/debian/changelog --- fabulous-0.3.0+dfsg1/debian/changelog 2020-10-22 10:06:47.000000000 +0000 +++ fabulous-0.4.0+dfsg1/debian/changelog 2021-09-02 06:09:04.000000000 +0000 @@ -1,3 +1,12 @@ +fabulous (0.4.0+dfsg1-1) unstable; urgency=medium + + * New upstream release + * Remove fonts-noto from depends, add fonts-noto-core to recommends + (Closes: #983247) + * Update standards version to 4.6.1 + + -- Jonathan Carter Thu, 02 Sep 2021 08:09:04 +0200 + fabulous (0.3.0+dfsg1-8) unstable; urgency=low [ Debian Janitor ] diff -Nru fabulous-0.3.0+dfsg1/debian/control fabulous-0.4.0+dfsg1/debian/control --- fabulous-0.3.0+dfsg1/debian/control 2020-10-22 10:06:47.000000000 +0000 +++ fabulous-0.4.0+dfsg1/debian/control 2021-09-02 06:09:02.000000000 +0000 @@ -12,7 +12,7 @@ python3-setuptools, python3-sphinx, python3-sphinxcontrib.programoutput -Standards-Version: 4.5.0 +Standards-Version: 4.6.1 Rules-Requires-Root: no Homepage: https://jart.github.io/fabulous/ Vcs-Git: https://salsa.debian.org/python-team/packages/fabulous.git @@ -23,12 +23,12 @@ Breaks: python-fabulous, python-fabulous-doc, python3-fabulous-doc Replaces: python-fabulous, python-fabulous-doc, python3-fabulous-doc Architecture: any -Depends: fonts-noto, - python3-pil, +Depends: python3-pil, ${misc:Depends}, ${python3:Depends}, ${shlibs:Depends}, ${sphinxdoc:Depends} +Recommends: fonts-noto-core Description: Python module to make your terminal output fabulous Fabulous is a Python library designed to make the output of terminal applications look fabulous. Fabulous allows you to print colors, images, and diff -Nru fabulous-0.3.0+dfsg1/docs/index.rst fabulous-0.4.0+dfsg1/docs/index.rst --- fabulous-0.3.0+dfsg1/docs/index.rst 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/docs/index.rst 2021-07-01 13:02:10.000000000 +0000 @@ -10,7 +10,7 @@ .. toctree:: :maxdepth: 2 -:Version: 0.3.0 +:Version: 0.4.0 :Founder: Justine Alexandra Roberts Tunney :Copyright: Copyright 2016 The Fabulous Authors. All rights reserved. :License: Apache 2.0 / OFL @@ -40,9 +40,9 @@ Fabulous can also be installed manually from the source archive:: - wget https://github.com/jart/fabulous/releases/download/0.3.0/fabulous-0.3.0.tar.gz - tar -xvzf fabulous-0.3.0.tar.gz - cd fabulous-0.3.0 + wget https://github.com/jart/fabulous/releases/download/0.4.0/fabulous-0.4.0.tar.gz + tar -xvzf fabulous-0.4.0.tar.gz + cd fabulous-0.4.0 sudo python setup.py install Once installed, run the demo:: diff -Nru fabulous-0.3.0+dfsg1/fabulous/color.py fabulous-0.4.0+dfsg1/fabulous/color.py --- fabulous-0.3.0+dfsg1/fabulous/color.py 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/fabulous/color.py 2021-07-01 13:02:10.000000000 +0000 @@ -20,7 +20,7 @@ The color module provides an object-oriented abstraction for stylized text inside the terminal. This includes things like bold text, blinking text, - 4-bit ANSI colors and 8-bit xterm256 colors. + 4-bit ANSI colors, 8-bit xterm256 colors, and 24-bit "truecolor" colors. """ @@ -74,6 +74,10 @@ >>> len(bold("hello ", red("world"))) 11 + If you have the wcwidth module installed, it will be used for computing lengths:: + + + """ sep = "" fmt = "%s" @@ -87,8 +91,21 @@ def __repr__(self): return repr(unicode(self)) - def __len__(self): - return sum([len(item) for item in self.items]) + + if sys.version_info[0] > 2: + def __len__(self): + try: + import wcwidth + # We use: + # * wcwidth.wcswidth(item) to find the length of strs + # * len(str(item)) to find the length of a bytes object + # * len(item) for everything else. + return sum([ wcwidth.wcswidth(item) if isinstance(item, str) else len(str(item)) if isinstance(item, bytes) else len(item) for item in self.items ]) + except ModuleNotFoundError: + return sum([len(str(item)) if isinstance(item, bytes) else len(item) for item in self.items]) + else: + def __len__(self): + return sum([len(item) for item in self.items]) def __add__(self, cs): if not isinstance(cs, (basestring, ColorString)): @@ -107,6 +124,28 @@ """A more readable way to say ``unicode(color).encode('utf8')`` """ return unicode(self).encode('utf8') + def join(self, iterable): + """ + This works just like `str.join()`, but for ColorStrings! + + For example: + + >>> from fabulous.color import * + >>> l = [ + ... fg256("green", "napster good"), + ... fg256("red", "fire bad"), + ... ] + >>> print(plain(" ").join(l)) + + """ + ret = None + for x in iterable: + if ret is None: + ret = x + else: + ret += self + ret += x + return ret class ColorString256(ColorString): @@ -125,6 +164,20 @@ return self.fmt % ( self.color, self.sep.join([unicode(s) for s in self.items])) +class ColorStringTrue(ColorString): + r"""Base class for 24-bit "truecolor" stylized string-like objects. + + See the :class:`.fgtrue`, :class:`.bgtrue`, :class:`.highlighttrue`, and + :class:`.complementtrue` classes for more information. + + """ + def __init__(self, color, *items): + self.color = parse_color(color) + self.items = items + + def __str__(self): + return self.fmt % ( + self.color[0], self.color[1], self.color[2], self.sep.join([unicode(s) for s in self.items])) class plain(ColorString): r"""Plain text wrapper @@ -763,6 +816,32 @@ fmt = esc(38, 5, "%d") + "%s" + esc(39) +class fgtrue(ColorStringTrue): + r"""24-bit "truecolor" foreground color wrapper + + This class creates a string-like object that has a 24-bit color. The + color is specified as a CSS color code. + + These colors are, in theory, the most dependable of all... presuming your + terminal supports them, of course. + + Example usage:: + + from fabulous import fgtrue, plain + print fgtrue('#F00', 'i am red!') + print fgtrue('#FF0000', 'i am red!') + print fgtrue('magenta', 'i am', ' magenta!') + print plain('hello ', fgtrue('magenta', 'world')) + + The ANSI escape codes look as follows:: + + >>> str(fgtrue('red', 'hello')) + '\x1b[38;2;255;0;0mhello\x1b[39m' + + """ + fmt = esc(38, 2, "%d", "%d", "%d") + "%s" + esc(39) + + class bg256(ColorString256): r"""xterm256 background color wrapper @@ -795,6 +874,32 @@ fmt = esc(48, 5, "%d") + "%s" + esc(49) +class bgtrue(ColorStringTrue): + r"""24-bit "truecolor" background color wrapper + + This class creates a string-like object that has a 24-bit color. The + color is specified as a CSS color code. + + These colors are, in theory, the most dependable of all... presuming your + terminal supports them, of course. + + Example usage:: + + from fabulous import bgtrue, plain + print bgtrue('#F00', 'i have a red background!') + print bgtrue('#FF0000', 'i have a red background!') + print bgtrue('magenta', 'i have a', ' magenta background!') + print plain('hello ', bgtrue('magenta', 'world')) + + The ANSI escape codes look as follows:: + + >>> str(bgtrue('red', 'hello')) + '\x1b[48;2;255;0;0mhello\x1b[49m' + + """ + fmt = esc(48, 2, "%d", "%d", "%d") + "%s" + esc(49) + + class highlight256(ColorString256): r"""Highlighted 8-bit color text @@ -805,6 +910,16 @@ fmt = esc(1, 38, 5, "%d", 7) + "%s" + esc(27, 39, 22) +class highlighttrue(ColorStringTrue): + r"""Highlighted 24-bit "truecolor" color text + + This is equivalent to composing :class:`.bold`, :class:`.flip`, and + :class:`.fgtrue`. + + """ + fmt = esc(1, 38, 2, "%d", "%d", "%d", 7) + "%s" + esc(27, 39, 22) + + class complement256(ColorString256): r"""Highlighted 8-bit color text @@ -829,6 +944,31 @@ self.sep.join([unicode(s) for s in self.items])) +class complementtrue(ColorStringTrue): + r"""Highlighted 24-bit "truecolor" color text + + This class composes :class:`.bold`, :class:`.flip`, and + :class:`.bgtrue`. Then it invokes :meth:`complement` to supply the polar + opposite :class:`fgtrue` color. + + This looks kind of hideous at the moment. We're planning on finding a + better formula for complementary colors in the future. + + """ + fmt = esc(1, 38, 2, "%d", "%d", "%d", 48, 2, "%d", "%d", "%d") + "%s" + esc(49, 39, 22) + + def __init__(self, color, *items): + self.bg = parse_color(color) + self.fg = complement(color) + self.items = items + + def __str__(self): + return self.fmt % ( + self.fg[0], self.fg[1], self.fg[2], + self.bg[0], self.bg[1], self.bg[2], + self.sep.join([unicode(s) for s in self.items])) + + def h1(title, line=OVERLINE): """Prints bold text with line beneath it spanning width of terminal """ diff -Nru fabulous-0.3.0+dfsg1/fabulous/image.py fabulous-0.4.0+dfsg1/fabulous/image.py --- fabulous-0.3.0+dfsg1/fabulous/image.py 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/fabulous/image.py 2021-07-01 13:02:10.000000000 +0000 @@ -112,7 +112,7 @@ (iw, ih) = self.size if width is None: width = min(iw, utils.term.width) - elif isinstance(width, basestring): + elif (sys.version_info >= (3, 0) and isinstance(width, str)) or (sys.version_info < (3, 0) and isinstance(width, basestring)): percents = dict([(pct, '%s%%' % (pct)) for pct in range(101)]) width = percents[width] height = int(float(ih) * (float(width) / float(iw))) diff -Nru fabulous-0.3.0+dfsg1/fabulous/__init__.py fabulous-0.4.0+dfsg1/fabulous/__init__.py --- fabulous-0.3.0+dfsg1/fabulous/__init__.py 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/fabulous/__init__.py 2021-07-01 13:02:10.000000000 +0000 @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION = (0, 3, 0, 'final', 0) -__version__ = '0.3.0' +VERSION = (0, 4, 0, 'final', 0) +__version__ = '0.4.0' diff -Nru fabulous-0.3.0+dfsg1/fabulous/text.py fabulous-0.4.0+dfsg1/fabulous/text.py --- fabulous-0.3.0+dfsg1/fabulous/text.py 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/fabulous/text.py 2021-07-01 13:02:10.000000000 +0000 @@ -175,6 +175,13 @@ return fonts[name] raise FontNotFound("Can't find %r :'( Try adding it to ~/.fonts" % name) +font_roots = [ + '/usr/share/fonts/truetype', # where ubuntu puts fonts + '/usr/share/fonts', # where fedora puts fonts + os.path.expanduser('~/.local/share/fonts'), # custom user fonts + os.path.expanduser('~/.fonts'), # custom user fonts + os.path.abspath(os.path.join(os.path.dirname(__file__), 'fonts')), +] @utils.memoize def get_font_files(): @@ -193,14 +200,8 @@ True """ - roots = [ - '/usr/share/fonts/truetype', # where ubuntu puts fonts - '/usr/share/fonts', # where fedora puts fonts - os.path.expanduser('~/.fonts'), # custom user fonts - os.path.abspath(os.path.join(os.path.dirname(__file__), 'fonts')), - ] result = {} - for root in roots: + for root in font_roots: for path, dirs, names in os.walk(root): for name in names: if name.endswith(('.ttf', '.otf')): diff -Nru fabulous-0.3.0+dfsg1/python-fabulous.spec fabulous-0.4.0+dfsg1/python-fabulous.spec --- fabulous-0.3.0+dfsg1/python-fabulous.spec 2016-07-12 14:20:21.000000000 +0000 +++ fabulous-0.4.0+dfsg1/python-fabulous.spec 2021-07-01 13:02:10.000000000 +0000 @@ -1,14 +1,14 @@ %global modname fabulous Name: python-fabulous -Version: 0.3.0 +Version: 0.4.0 Release: 2%{?dist} Summary: Makes your terminal output totally fabulous Group: Development/Languages License: Apache 2.0 / OFL URL: https://jart.github.io/fabulous -Source0: https://github.com/jart/fabulous/releases/download/0.3.0/fabulous-0.3.0.tar.gz +Source0: https://github.com/jart/fabulous/releases/download/0.4.0/fabulous-0.4.0.tar.gz BuildArch: noarch