-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenus.lua
More file actions
109 lines (83 loc) · 1.73 KB
/
menus.lua
File metadata and controls
109 lines (83 loc) · 1.73 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function DisplayLockboxItem(box, key)
local value, str, Menu
Term:clear()
ui:title_bar("~B~wContents of '"..box.name..":"..key.."'")
Menu=terminal.TERMMENU(Term, 1, 2, Term:width() -2, 4)
Menu:add("to clipboard", "clipboard")
Menu:add("display as qrcode", "qrcode")
Menu:add("view in editor", "view")
Menu:add("delete item", "delete")
Term:move(0,8)
item=box:get(key)
Term:puts(item.value)
str=Menu:run()
if strutil.strlen(str) > 0
then
if str=="clipboard" then ToClipboard(value)
elseif str=="qrcode" then DisplayQRCode(value)
elseif str=="delete" then
box:remove(key)
box:save()
end
end
end
function DisplayLockbox(Menu, name)
local box, key, value, str
box=lockboxes:find(name)
if box:load() ~= true
then
ui:error("incorrect password.")
box.password=nil
return false
end
while true
do
Term:clear()
Menu:clear()
ui:title_bar("~B~wLockbox: '"..box.name.."'")
Menu:add("Add new item", "add")
Menu:add("Add new item with editor", "add-editor")
for key,value in pairs(box.items)
do
Menu:add(key)
end
str=Menu:run()
if strutil.strlen(str) > 0
then
if str=="add" then ui:new_item(box)
elseif str=="add-editor" then ui:new_item_editor(box)
else
DisplayLockboxItem(box, str)
end
else break
end
end
return true
end
function MainMenuRefresh(Menu)
local item
Menu:clear()
Menu:add("New Lockbox", "new")
item=lockboxes:first()
while item ~= nil
do
Menu:add(item.name, item.name)
item=lockboxes:next()
end
end
function MainScreen()
local Menu, item
Mode="menu"
Term:clear()
Term:move(0,0)
Menu=terminal.TERMMENU(Term, 1,2,Term:width() -2, Term:height() -4)
while true
do
MainMenuRefresh(Menu)
item=Menu:run()
if strutil.strlen(item) == 0 then break
elseif item=="new" then NewLockbox()
else DisplayLockbox(Menu, item)
end
end
end