Skip to content

Add xterm mouse support#2

Open
faithanalog wants to merge 1 commit intophilanc:masterfrom
faithanalog:master
Open

Add xterm mouse support#2
faithanalog wants to merge 1 commit intophilanc:masterfrom
faithanalog:master

Conversation

@faithanalog
Copy link

@faithanalog faithanalog commented Feb 26, 2021

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

@philanc
Copy link
Owner

philanc commented Feb 26, 2021

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

@Nomarian
Copy link

Nomarian commented Dec 28, 2023

Any day now?

@philanc
Copy link
Owner

philanc commented Dec 28, 2023

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

@Nomarian
Copy link

Nomarian commented Dec 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants