-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshell.py
41 lines (30 loc) · 1007 Bytes
/
shell.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
from Getch import getch
from ui import PyTermUI
class Shell(object):
def __init__(self,config):
self.config = config
self.pyTermUI = PyTermUI(self.config)
def listener(self):
may_i_continue = True
string_query = ''
print self.pyTermUI.preText(),
while may_i_continue:
char_data = getch()
pressedKey = ord(char_data)
#print str(pressedKey)
if pressedKey == 12:
os.system('clear')
print self.pyTermUI.preText() + "%s" % string_query + " ",
elif pressedKey == 127:
string_query = string_query[:-1]
print self.pyTermUI.preText() + "%s" % string_query + " ",
print self.pyTermUI.preText() + "%s" % string_query,
elif not pressedKey == 3:
string_query += char_data
print self.pyTermUI.preText() + "%s" % string_query,
elif pressedKey == 3:
return "{{BREAKAPPLICATION}}"
commands = string_query.split()
self.pyTermUI.check(commands)
may_i_continue = False if pressedKey == 13 or pressedKey == 3 else True
return string_query