blob: 9e8acb73dff260443ba97f0b23c6382b2f98008d (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import curses
from ranger.debug import log
class UI():
def __init__(self, env, commandlist):
self.env = env
self.commandlist = commandlist
self.widgets = []
self.win = curses.initscr()
self.win.leaveok(1)
self.initialize()
self.setup()
self.resize()
def initialize(self):
curses.noecho()
curses.halfdelay(10)
curses.curs_set(0)
def setup(self):
pass
def resize(self):
self.env.termsize = self.win.getmaxyx()
def redraw(self):
self.win.redrawwin()
self.win.refresh()
self.win.redrawwin()
def add_widget(self, widg):
self.widgets.append(widg)
def feed_env(self, env):
self.env = env
def press(self, key, fm):
self.env.key_append(key)
# log(self.env.keybuffer)
try:
cmd = self.commandlist.paths[self.env.keybuffer]
except KeyError:
self.env.key_clear()
return
if cmd == self.commandlist.dummy_object:
return
cmd.execute(fm)
self.env.key_clear()
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()
def get_next_key(self):
key = self.win.getch()
curses.flushinp()
return key
|