-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.py
64 lines (54 loc) · 1.57 KB
/
prompt.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
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
import curses
import menu
import logging as log
import branch
class Prompt(menu.Menu):
def __init__(self, layout):
super(Prompt, self).__init__(layout)
self.options = ['Do you want to delete this branch?',' Yes',' No']
self.write_options()
def write_options(self):
self.append_storage(self.options)
def create_delete_copy(self, name):
front = 'Do you want to delete '
back = '?'
crop_length = curses.COLS - len(front) - len(back)
name = name[0:crop_length]
return front + name + back
def generate_option_events(self, data):
option_callbacks = [
(self.noop, None),
(self.wrapper, data),
(self.close, None)
]
return option_callbacks
def open(self, name):
self.selected_index = 1
self.set_storage([
self.create_delete_copy(name),
' Yes',
' No'
])
self.draw()
self.update()
self.storage_event = []
self.append_storage_event(self.generate_option_events(name))
def close(self, *args):
self.win.clear()
self.update()
return 'close'
def eat_key(self, c):
if c == ord('j'):
self.select('DOWN')
pass
elif c == ord('k'):
self.select('UP')
pass
elif c == 10:
result = self.select_event()
return result
def wrapper(self, data):
branch.delete_branch(data)
return 'deleted'
def noop(self, *args):
return None