summary refs log tree commit diff stats
path: root/code/ui.py
blob: d9c1de4e356e608945a9372c8c26459a8fa750c5 (plain) (blame)
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
48
import curses, debug
class UI():
	def __init__(self, env):
		self.env = env

		self.widgets = []
		self.win = curses.initscr()
		self.win.leaveok(1)
		curses.noecho()
		curses.halfdelay(3)

		self.setup()
		self.resize()

	def setup(self):
		pass

	def resize(self):
		self.env.termsize = self.win.getmaxyx()

	def add_widget(self, widg):
		self.widgets.append(widg)

	def feed_env(self, env):
		self.env = env

	def exit(self):
		curses.nocbreak()
		curses.echo()
		curses.endwin()

	def draw(self):
		self.win.erase()
		for widg in self.widgets:
			widg.feed_env(self.env)
			widg.draw()
		self.win.refresh()

#		for i in range(1, len(self.env.pwd)):
#			f = self.env.pwd.files[i]
#			self.win.addstr(i, 0, f.path)
#			if f.infostring: self.win.addstr(i, 50, f.infostring)

	def get_next_key(self):
		key = self.win.getch()
		curses.flushinp()
		return key