blob: 5257e95eb35d96045628fa0bb7774460d6dd3c4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/usr/bin/env python
"""
This is an example application for the 'blessings' 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 blessings recognizes that it actually does, and
provides a proxy.
"""
from __future__ import print_function
import sys
from blessings import Terminal
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()
|