-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
34 lines (29 loc) · 866 Bytes
/
controller.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
import curses
from keymap import KeyMap
from action import ActionContext
class Controller:
def __init__(self, configFile=None):
self.__stdscr = None
def start(self):
try:
self.__stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
self.__stdscr.keypad(1)
except:
self.end()
def end(self):
self.__stdscr.keypad(0)
curses.nocbreak()
curses.echo()
curses.endwin()
def main(self, view, model):
km = KeyMap()
ac = ActionContext(km, model, self.__stdscr)
while model.checkProgramExecution():
view.update(self.__stdscr)
c = self.__stdscr.getch()
model.echoCommand(str(c))
km.addCommand(ch(c))
demands = km.translate()
ac.do(demands)