Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jquast/blessed
Browse files Browse the repository at this point in the history
  • Loading branch information
jquast committed Apr 28, 2014
2 parents 3c510ac + 50b0fec commit 96d670a
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 102 deletions.
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
.. image:: https://secure.travis-ci.org/jquast/blessed.png
.. image:: http://img.shields.io/travis/jquast/blessed.svg
:target: https://travis-ci.org/jquast/blessed
:alt: travis continous integration
:alt: Travis Continous Integration

.. image:: http://coveralls.io/repos/jquast/blessed/badge.png
.. image:: http://img.shields.io/coveralls/jquast/blessed/badge.svg
:target: http://coveralls.io/r/jquast/blessed
:alt: coveralls code coveraage
:alt: Coveralls Code Coveraage

.. image:: https://pypip.in/v/blessed/badge.png
.. image:: http://img.shields.io/pypi/v/blessed/badge.svg
:target: https://pypi.python.org/pypi/blessed/
:alt: Latest Version

.. image:: https://pypip.in/license/blessed/badge.png
.. image:: https://pypip.in/license/blessed/badge.svg
:target: https://pypi.python.org/pypi/blessed/
:alt: License

.. image:: https://pypip.in/d/blessed/badge.png
.. image:: http://img.shields.io/pypi/dm/blessed/badge.svg
:target: https://pypi.python.org/pypi/blessed/
:alt: Downloads

Expand Down Expand Up @@ -674,6 +674,8 @@ Version History
that it may be overridden by custom terminal implementers.
* enhancement: allow ``inkey()`` and ``kbhit()`` to return early when
interrupted by signal by passing argument ``_intr_continue=False``.
* enhancement: allow ``hpa`` and ``vpa`` (move_x, move_y) to work on tmux(1)
or screen(1) by forcibly emulating their support by a proxy.
* bugfix: if ``locale.getpreferredencoding()`` returns empty string or an
encoding that is not a valid codec for ``codecs.getincrementaldecoder``,
fallback to ascii and emit a warning.
Expand Down
28 changes: 24 additions & 4 deletions bin/on_resize.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#!/usr/bin/env python
"""
This is an example application for the 'blessed' Terminal library for python.
Window size changes are caught by the 'on_resize' function using a traditional
signal handler. Meanwhile, blocking keyboard input is displayed to stdout.
If a resize event is discovered, an empty string is returned by term.inkey()
when _intr_continue is False, as it is here.
"""
import signal
from blessed import Terminal

term = Terminal()


def on_resize(sig, action):
print('height={t.height}, width={t.width}'.format(t=term))
# Its generally not a good idea to put blocking functions (such as print)
# within a signal handler -- if another SIGWINCH is recieved while this
# function blocks, an error will occur. In most programs, you'll want to
# set some kind of 'dirty' flag, perhaps by a Semaphore or global variable.
print('height={t.height}, width={t.width}\r'.format(t=term))

signal.signal(signal.SIGWINCH, on_resize)

with term.cbreak():
while True:
print(repr(term.inkey(_intr_continue=False)))
# note that, a terminal driver actually writes '\r\n' when '\n' is found, but
# in raw mode, we are allowed to write directly to the terminal without the
# interference of such driver -- so we must write \r\n ourselves; as python
# will append '\n' to our print statements, we simply end our statements with
# \r.
with term.raw():
print("press 'X' to stop.\r")
inp = None
while inp != 'X':
inp = term.inkey(_intr_continue=False)
print(repr(inp) + u'\r')
40 changes: 40 additions & 0 deletions bin/progress_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
"""
This is an example application for the 'blessed' Terminal library for python.
This isn't a real progress bar, just a sample "animated prompt" of sorts
that demonstrates the separate move_x() and move_y() functions, made
mainly to test the `hpa' compatibility for 'screen' terminal type which
fails to provide one, but blessed recognizes that it actually does, and
provides a proxy.
"""
from __future__ import print_function
from blessed import Terminal
import sys


def main():
term = Terminal()
assert term.hpa(1) != u'', (
'Terminal does not support hpa (Horizontal position absolute)')

col, offset = 1, 1
with term.cbreak():
inp = None
print("press 'X' to stop.")
sys.stderr.write(term.move(term.height, 0) + u'[')
sys.stderr.write(term.move_x(term.width) + u']' + term.move_x(1))
while inp != 'X':
if col >= (term.width - 2):
offset = -1
elif col <= 1:
offset = 1
sys.stderr.write(term.move_x(col) + u'.' if offset == -1 else '=')
col += offset
sys.stderr.write(term.move_x(col) + u'|\b')
sys.stderr.flush()
inp = term.inkey(0.04)
print()

if __name__ == '__main__':
main()
Loading

0 comments on commit 96d670a

Please sign in to comment.