plterm icon indicating copy to clipboard operation
plterm copied to clipboard

Add xterm mouse support

Open faithanalog opened this issue 4 years ago • 4 comments

This adds xterm mouse support to input().

Mouse support must be explicitly enabled/disabled with setmousemode. Once enabled, mouse data is returned from input() as additional return values button, x, y, motion, mods, and the keycode returned is virtual code keys.mouse.

example (included in readme):

term = require 'plterm'

local getkey = term.input()
local oldmode = term.savemode()
term.setrawmode()
term.setmousemode(term.mousemode.click)

local key, btn, x, y, motion, mods = getkey()

-- term.savemode() can't save mouse mode due to stty limitations
term.setmousemode(term.mousemode.off)
term.restoremode(oldmode)

if key == term.keys.mouse then
	print("button clicked: " .. tostring(btn))
	print("x: " .. tostring(x) .. " y: " .. tostring(y))
	print("was moving: " .. tostring(motion))
	print("modifier mask: " .. tostring(mods))
else
	print("not a mouse event.")
	print("key: " .. term.keyname(key))
end

unfortunately savemode() cannot save the mouse mode because xterm does not have a sequence to query the mouse mode. this is why i use setmousemode() to disable it

faithanalog avatar Feb 26 '21 09:02 faithanalog

Thanks for the PR. I'll look into it as soon as I can, and come back to you.

philanc avatar Feb 26 '21 20:02 philanc

Any day now?

Nomarian avatar Dec 28 '23 08:12 Nomarian

Thanks for the wake-up call.

I think that the proposed addition is xterm-specific. I haven't found enough information about mouse support in rxvt, urxvt and vte-based terminal emulators and I don't have enough free time at the moment to test the PR with these terminal emulators.

I will stay at the moment with the support of basic, common ANSI escape sequences which are available in most (all?) terminals. It doesn't include mouse support.

If you are interested in mouse support for xterm only, please use faithanalog'plterm version at https://github.com/faithanalog/plterm/tree/master

--Phil

philanc avatar Dec 28 '23 21:12 philanc

Well, I can try and see where it works, If it works in a lot of terminals (linux) would you merge?

Nomarian avatar Dec 29 '23 02:12 Nomarian