-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp_manager.py
32 lines (25 loc) · 971 Bytes
/
app_manager.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
from command_executor import setup_executor
from command_executor import execute_command
class AppManager(object):
def __init__(self):
self.current_app = None
setup_executor(app_manager=self)
def in_app(self):
return self.current_app is not None
def quit_app(self):
# TODO(Bieber): Use decorator to check that you're in an app
self.current_app = None
def handle_line(self, line):
if self.in_app():
func = self.current_app.get('handle_line')
func and func(line)
elif line and line[0] == ':':
# TODO(Bieber): These commands should be treated like any other app
execute_command(line[1:])
def start_app(self, handle_line=None, handle_start=None):
self.current_app = {
'handle_line': handle_line,
'handle_start': handle_start,
}
func = self.current_app.get('handle_start')
func and func()