-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
47 lines (35 loc) · 1011 Bytes
/
demo.py
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
42
43
44
45
46
47
'''
Created on Sep 25, 2013
Demo script for the AsyncConsole. A thread in the background runs in a cycle printing
the current time while the user can still type in the input prompt.
@author: pedro
'''
import curses
import threading
import time
from asyncconsole import AsyncConsole
class MyThread(threading.Thread):
stop = False
interval = 30.0
console = None
def __init__(self):
super(MyThread, self).__init__()
def run(self):
while not self.stop:
self.console.addline(time.strftime("%H:%M:%S", time.gmtime()))
time.sleep(self.interval)
def main(stdscr):
console = AsyncConsole(stdscr)
t = MyThread()
t.console=console
t.interval=10.0
t.start()
try:
while console.readline():
if console.input_string == 'quit':
break
console.addline(console.input_string)
finally:
t.stop = True
if __name__ == '__main__':
curses.wrapper(main)