-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEvent viewer.lua
67 lines (56 loc) · 2.16 KB
/
Event viewer.lua
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
sim = require 'sim'
function sysCall_info()
return {autoStart = false, menu = 'Developer tools\nEvent viewer'}
end
function sysCall_init()
cbor = require 'org.conman.cbor'
cbor.NULL_VALUE = setmetatable({}, {__tostring = function() return 'null' end})
cbor.SIMPLE[22] = function(pos) return cbor.NULL_VALUE, pos, 'null' end
simUI = require 'simUI'
ui = simUI.create [[<ui title="Event viewer" position="-400,100" size="640,220" placement="relative" closeable="true" resizable="true" on-close="onClose">
<group layout="hbox">
<checkbox id="${ui_chkFilter}" text="" on-change="onFilterChanged" />
<label text="Filter:" />
<edit id="${ui_txtFilter}" value="e.event ~= 'logMsg' and e.event ~= 'msgDispatchTime'" enabled="false" on-change="onFilterChanged" />
</group>
<text-browser id="${ui_txtLog}" type="plain" word-wrap="false" read-only="false" style="QTextBrowser { font-family: Courier New; }" />
</ui>]]
onFilterChanged()
sep = ''
end
function sysCall_addOnScriptSuspend()
return {cmd = 'cleanup'}
end
function sysCall_event(event)
local txt = ''
for _, e in ipairs(cbor.decode(tostring(event))) do
if testFilter(e) then
local s = _S.tableToString(e, {indent = true}, 99)
txt = txt .. sep .. s .. ','
sep = '\n\n'
end
end
simUI.appendText(ui, ui_txtLog, txt)
end
function sysCall_nonSimulation()
if leaveNow then return {cmd = 'cleanup'} end
end
function sysCall_sensing()
if leaveNow then return {cmd = 'cleanup'} end
end
function testFilter(e)
if not filterEnabled then return true end
if not filterFunc then return false end
local ok, ret = pcall(filterFunc(), e)
if not ok then return false end
return ret
end
function onFilterChanged()
filterEnabled = simUI.getCheckboxValue(ui, ui_chkFilter) > 0
simUI.setEnabled(ui, ui_txtFilter, filterEnabled)
filterFunc = loadstring('return function(e) return ' .. simUI.getEditValue(ui, ui_txtFilter) .. ' end')
simUI.setStyleSheet(ui, ui_txtFilter, filterFunc and '' or 'border: 1px solid red')
end
function onClose()
leaveNow = true
end