summary refs log tree commit diff stats
path: root/code/ui.py
blob: 7d8fd828ee7094ec3d4db99816c656cf9b28d745 (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
import curses
class UI():
	def __init__(self, options):
		self.scr = curses.initscr()
		self.scr.leaveok(1)
		curses.noecho()
		curses.halfdelay(3)

		self.options = options
		self.directories = None
		self.pwd = None
		self.cf = None
		self.termsize = None
		self.rows = 0
		self.cols = 0

	def feed(self, directories, pwd, cf, termsize):
		self.directories = directories
		self.pwd = pwd
		self.cf = cf
		self.termsize = termsize
		self.cols = termsize.x
		self.rows = termsize.y

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

	def draw(self):
		import time
		self.scr.erase()
		for i in range(1, len(self.pwd)):
			self.scr.addstr(i, 0, self.pwd[i])
		self.scr.refresh()

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