Skip to content

Commit

Permalink
Merge Python-3-style prints in examples. Close #140.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrose committed Oct 24, 2018
2 parents 4e51546 + 9e35146 commit d58e312
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
58 changes: 29 additions & 29 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ Coding with Blessings looks like this...
t = Terminal()
print t.bold('Hi there!')
print t.bold_red_on_bright_green('It hurts my eyes!')
print(t.bold('Hi there!'))
print(t.bold_red_on_bright_green('It hurts my eyes!'))
with t.location(0, t.height - 1):
print 'This is at the bottom.'
print('This is at the bottom.')
Or, for byte-level control, you can drop down and play with raw terminal
capabilities:

.. code:: python
print '{t.bold}All your {t.red}bold and red base{t.normal}'.format(t=t)
print t.wingo(2)
print('{t.bold}All your {t.red}bold and red base{t.normal}'.format(t=t))
print(t.wingo(2))
`Full API Reference <https://blessings.readthedocs.io/>`_

Expand Down Expand Up @@ -70,14 +70,14 @@ of the screen:
normal = tigetstr('sgr0')
else:
sc = cup = rc = underline = normal = ''
print sc # Save cursor position.
print(sc) # Save cursor position.
if cup:
# tigetnum('lines') doesn't always update promptly, hence this:
height = struct.unpack('hhhh', ioctl(0, TIOCGWINSZ, '\000' * 8))[0]
print tparm(cup, height - 1, 0) # Move cursor to bottom.
print 'This is {under}underlined{normal}!'.format(under=underline,
normal=normal)
print rc # Restore cursor position.
print(tparm(cup, height - 1, 0)) # Move cursor to bottom.
print('This is {under}underlined{normal}!'.format(under=underline,
normal=normal))
print(rc) # Restore cursor position.
That was long and full of incomprehensible trash! Let's try it again, this time
with Blessings:
Expand All @@ -88,7 +88,7 @@ with Blessings:
term = Terminal()
with term.location(0, term.height - 1):
print 'This is', term.underline('pretty!')
print('This is', term.underline('pretty!'))
Much better.

Expand All @@ -111,22 +111,22 @@ available as attributes on a ``Terminal``. For example...
from blessings import Terminal
term = Terminal()
print 'I am ' + term.bold + 'bold' + term.normal + '!'
print('I am ' + term.bold + 'bold' + term.normal + '!')
Though they are strings at heart, you can also use them as callable wrappers so
you don't have to say ``normal`` afterward:

.. code:: python
print 'I am', term.bold('bold') + '!'
print('I am', term.bold('bold') + '!')
Or, if you want fine-grained control while maintaining some semblance of
brevity, you can combine it with Python's string formatting, which makes
attributes easy to access:

.. code:: python
print 'All your {t.red}base {t.underline}are belong to us{t.normal}'.format(t=term)
print('All your {t.red}base {t.underline}are belong to us{t.normal}'.format(t=term))
Simple capabilities of interest include...

Expand Down Expand Up @@ -171,16 +171,16 @@ attributes:
from blessings import Terminal
term = Terminal()
print term.red + term.on_green + 'Red on green? Ick!' + term.normal
print term.bright_red + term.on_bright_blue + 'This is even worse!' + term.normal
print(term.red + term.on_green + 'Red on green? Ick!' + term.normal)
print(term.bright_red + term.on_bright_blue + 'This is even worse!' + term.normal)
You can also call them as wrappers, which sets everything back to normal at the
end:

.. code:: python
print term.red_on_green('Red on green? Ick!')
print term.yellow('I can barely see it.')
print(term.red_on_green('Red on green? Ick!'))
print(term.yellow('I can barely see it.'))
The available colors are...

Expand Down Expand Up @@ -227,14 +227,14 @@ all together:
from blessings import Terminal
term = Terminal()
print term.bold_underline_green_on_yellow + 'Woo' + term.normal
print(term.bold_underline_green_on_yellow + 'Woo' + term.normal)
Or you can use your newly coined attribute as a wrapper, which implicitly sets
everything back to normal afterward:

.. code:: python
print term.bold_underline_green_on_yellow('Woo')
print(term.bold_underline_green_on_yellow('Woo'))
This compound notation comes in handy if you want to allow users to customize
the formatting of your app: just have them pass in a format specifier like
Expand Down Expand Up @@ -265,16 +265,16 @@ screen. ``Terminal`` provides a context manager for doing this concisely:
term = Terminal()
with term.location(0, term.height - 1):
print 'Here is the bottom.'
print 'This is back where I came from.'
print('Here is the bottom.')
print('This is back where I came from.')
Parameters to ``location()`` are ``x`` and then ``y``, but you can also pass
just one of them, leaving the other alone. For example...

.. code:: python
with term.location(y=10):
print 'We changed just the row.'
print('We changed just the row.')
If you're doing a series of ``move`` calls (see below) and want to return the
cursor to its original position afterward, call ``location()`` with no
Expand All @@ -283,8 +283,8 @@ arguments, and it will do only the position restoring:
.. code:: python
with term.location():
print term.move(1, 1) + 'Hi'
print term.move(9, 9) + 'Mom'
print(term.move(1, 1) + 'Hi')
print(term.move(9, 9) + 'Mom')
Note that, since ``location()`` uses the terminal's built-in
position-remembering machinery, you can't usefully nest multiple calls. Use
Expand All @@ -302,7 +302,7 @@ this:
from blessings import Terminal
term = Terminal()
print term.move(10, 1) + 'Hi, mom!'
print(term.move(10, 1) + 'Hi, mom!')
``move``
Position the cursor elsewhere. Parameters are y coordinate, then x
Expand Down Expand Up @@ -339,7 +339,7 @@ For example...

.. code:: python
print term.move_up + 'Howdy!'
print(term.move_up + 'Howdy!')
Height And Width
----------------
Expand Down Expand Up @@ -427,8 +427,8 @@ and just stick to content, since you're apparently headed into a pipe:
term = Terminal()
if term.does_styling:
with term.location(0, term.height - 1):
print 'Progress: [=======> ]'
print term.bold('Important stuff')
print('Progress: [=======> ]')
print(term.bold('Important stuff'))
Shopping List
=============
Expand Down
4 changes: 2 additions & 2 deletions blessings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ def location(self, x=None, y=None):
term = Terminal()
with term.location(2, 5):
print 'Hello, world!'
print('Hello, world!')
for x in xrange(10):
print 'I can do it %i times!' % x
print('I can do it %i times!' % x)
Specify ``x`` to move to a certain column, ``y`` to move to a certain
row, both, or neither. If you specify neither, only the saving and
Expand Down

0 comments on commit d58e312

Please sign in to comment.