-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowRet.lua
More file actions
68 lines (66 loc) · 2.23 KB
/
showRet.lua
File metadata and controls
68 lines (66 loc) · 2.23 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
local showRetId = win.Uuid"1B80D345-12C0-4F31-BF63-D9EC13B8F830"
local toBrowse = {["table"]=true, ["function"]=true, ["thread"]=true}
local function showRet (ret, skipSingleChoice)
if type(ret)~="table" then
error("bad argument #1 to sh.showRet (table expected, got "..type(ret)..")")
end
ret.n = ret.n or #ret
if ret.n==0 then
local msg = ret.cmdline and ret.cmdline.."\n\1\nNo values returned" or "No values"
far.Message(msg, _filename:match"[^\\]+$")
return
end
if ret.n==1 and toBrowse[type(ret[1])] then
if skipSingleChoice then -- skip list displaying (dump value immediately)
sh.browse(ret[1], ret.cmdline)
return
else
mf.postmacro(Keys,"Enter")
end
end
local Items = far.MakeMenuItems(unpack(ret, 1, ret.n))
local Props = {
Title = "",
Bottom = "Enter, Ctrl+Ins",
Id = showRetId,
HelpTopic = sh.sharedUtils.HelpTopic"ShowRet",
}
local BrKeys = "CtrlIns"
if ret.cmdline then
Props.Title = ret.cmdline
Props.Bottom = Props.Bottom..", Ctrl+E (recall)"
BrKeys = BrKeys.." CtrlE"
end
repeat
local choosen,pos = far.Menu(Props, Items, BrKeys)
if choosen then
Props.SelectIndex = pos
if choosen.BreakKey=="CtrlIns" then
if pos~=0 then
local arg = Items[pos].arg
local str = (type(arg)=="table" and sh.dump or tostring)(arg)
if not far.CopyToClipboard(str) then
far.CopyToClipboard(arg)
end
end
elseif choosen.BreakKey=="CtrlE" then
choosen = false
sh.ExecDlg(ret.cmdline, ret.options)
elseif toBrowse[type(choosen.arg)] then
sh.browse(choosen.arg, "value "..tostring(pos))
end
end
until not choosen
end
if _cmdline then
print "Utility to browse arrays"
print "Export: sh.showRet(ret)"
print "- ret: table, array of values, with optional hash part:"
print " .n: number of values (to be able to keep nils)"
print " .cmdline: string used to get ret values (for title and ability to recall)"
print " .options: table, providing execution options"
print "Used internally for browsing values returned by functions calls"
print "Note: there is standalone utility for this purpose - see ret.lua"
return
end
return showRet -- export