summaryrefslogtreecommitdiff
path: root/xmake/core/ui/program.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-10-08 22:52:53 +0800
committerruki <[email protected]>2020-10-08 22:52:53 +0800
commitfc6a4d35adae0f854b8026c59ae6e1097f503e81 (patch)
tree4c3864e552e8804e26129ca641cfaafc2d175f6c /xmake/core/ui/program.lua
parenta0b8b710f6b502071d80b1626d344981b70f0ba2 (diff)
support mouse events for ui
Diffstat (limited to 'xmake/core/ui/program.lua')
-rw-r--r--xmake/core/ui/program.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua
index 86b017a2a..c5a73c474 100644
--- a/xmake/core/ui/program.lua
+++ b/xmake/core/ui/program.lua
@@ -44,6 +44,11 @@ function program:init(name, argv)
-- disable newline
curses.nl(false)
+ -- init mouse support
+ if curses.KEY_MOUSE then
+ curses.mousemask(curses.ALL_MOUSE_EVENTS)
+ end
+
-- to filter characters being output to the screen
-- this will filter all characters where a chtype or chstr is used
curses.map_output(true)
@@ -135,6 +140,11 @@ function program:event()
-- get input key
local key_code, key_name, key_meta = self:_input_key()
if key_code then
+ if curses.KEY_MOUSE and key_code == curses.KEY_MOUSE then
+ local code, x, y = curses.getmouse()
+ local name = self:_mouse_map()[code]
+ return event.mouse{code, x, y, name}
+ end
return event.keyboard{key_code, key_name, key_meta}
end
end
@@ -333,6 +343,21 @@ function program:_key_map()
return self._KEYMAP
end
+-- get mouse map
+function program:_mouse_map()
+ if not self._MOUSEMAP then
+ -- must be defined dynamically since it depends
+ -- on curses implementation
+ self._MOUSEMAP = {}
+ for n, v in pairs(curses) do
+ if (n:match('MOUSE') and n ~= 'KEY_MOUSE') or n:match('BUTTON') then
+ self._MOUSEMAP[v] = n
+ end
+ end
+ end
+ return self._MOUSEMAP
+end
+
-- get input key
function program:_input_key()