Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse copying #53

Open
walles opened this issue Apr 27, 2021 · 22 comments
Open

Mouse copying #53

walles opened this issue Apr 27, 2021 · 22 comments

Comments

@walles
Copy link
Owner

walles commented Apr 27, 2021

This text is now maintained here:
https://github.com/walles/moar/blob/master/MOUSE.md

--

At least on my Mac, if I want to copy something using the mouse i need to hold alt while marking for the mark to work.

The reason is that moar requests mouse events from the terminal, and that makes the terminal not accept mark / copy any more.

less --mouse has the same problems, see comments.

Workarounds

  • Alacritty: Use use shift + mouse selection to make it work. Cred to @chrisgrieser for this tip.
  • Contour: Use shift + mouse selection to mark text. Cred to @postsolar for this tip.
  • Foot: Use use shift + mouse selection to make it work. Cred to @postsolar for this tip.
  • Hyper on macOS: Set macOptionSelectionMode: 'force' in your config file, then hold the Option Key while marking
  • iTerm: Preferences / Profiles / Default / Terminal / uncheck "Report mouse clicks & drags"
  • macOS Terminal on a laptop: Hold down the fn key while marking with the mouse
  • kitty on macOS: Holding shift or fn while marking. Cred to @PrayagS for this tip.
  • Konsole Use use shift + mouse selection. Cred to @cig0 for this tip.
  • Terminator: Use use shift + mouse selection to make it work. Cred to @felix-seifert for this tip.
  • Tilix: Use use shift + mouse selection. Cred to @Macr0Nerd for this tip.
  • Warp: Preferences / Settings / Features / Terminal / uncheck "Enable Mouse Reporting"
  • Windows: Use Shift to make a selection. If you click the wrong initial spot, you can clear the selection with Esc. Just be careful, if you hit Esc without a selection, the pager will exit. Cred to @89z for this one.

less' screen initialization sequence

Recorded using iTerm's Automatically log session input to files feature.

less is version 487 that comes with macOS 11.3 Big Sur.

All linebreaks are mine, added for readability. The ^Ms are not.

less /etc/passwd
^G<ESC>[30m<ESC>(B<ESC>[m^M
<ESC>[?1049h
<ESC>[?1h
<ESC>=^M
##

moar's screen initialization sequence

moar /etc/passwd /Users/johan/src/moar
^G<ESC>[30m<ESC>(B<ESC>[m^M
<ESC>[?1049h
<ESC>[?1006;1000h
<ESC>[?25l
<ESC>[1;1H
<ESC>[m<ESC>[2m  1 <ESC>[22m##

Analysis of less

The line starting with ^G is probably from from fish since it's the same for both less and moar.

<ESC>[?1049h switches to the Alternate Screen Buffer, search here for 1 0 4 9 for info.

Then less does [?1h, which apparently is DECCKM Cursor Keys Mode, send ESC O A for cursor up, followed by =, meaning DECKPAM - Set keypad to applications mode (ESCape instead of digits).

NOTE that this means that less version 487 that comes with macOS 11.3 Big Sur doesn't even try to enable any mouse reporting, but relies on the terminal to convert scroll wheel events into arrow keypresses.

Analysis of moar

Same as less up until the Alternate Screen Buffer is enabled.

<ESC>[?1006;1000h enables SGR Mouse Mode and the X11 xterm mouse protocol (search for 1 0 0 0).

<ESC>[?25l hides the cursor. NOTE Maybe we don't need this? It might be implicit when we enable the Alternate Screen Buffer.

<ESC>[1;1H moves the cursor to the top left corner.

Then it's the first line with its line number in faint type.

@walles
Copy link
Owner Author

walles commented Apr 27, 2021

Apparently less got its mouse support in February 2019: https://www.greenwoodsoftware.com/less/news.548.html

I should try that and see what it does to marking text.

@walles
Copy link
Owner Author

walles commented Apr 27, 2021

less --mouse has the same mark-text-with-the-mouse problems as moar does.

Yay for being able to run the latest Ubuntu in Docker!

@walles
Copy link
Owner Author

walles commented Apr 27, 2021

These are the options I can come up with around the mouse experience:

  • Do nothing. Mouse scroll works well, copying can be done by holding alt (not great) and no work is involved.
  • Do what less does. Mouse scroll might work depending on terminal settings, but at least we won't be worse than less, copying works great, not much work.
  • Implement our own marking / copying based on the click / move mouse events we get. Good experience if it can be made to work, lots of work.
Mouse scroll Mouse mark Cost
Do nothing 🟢 🤷🏾 🟢
Do what less does 🤷🏾 🟢 🟢
Make our own marking 🟢 🟢 ⚠️

@walles
Copy link
Owner Author

walles commented Apr 30, 2021

Another workaround: in iTerm2, if you disable "Report mouse clicks & drags" in the preferences, under Profiles / Terminal, copying will work well.

walles added a commit that referenced this issue May 13, 2021
Related to #53 and #55.

With this implementation we don't restore the screen on exit, but less
does. Figure out why and make -compat work even more like less.
@thepeoplesbourgeois
Copy link

thepeoplesbourgeois commented Oct 22, 2021

Just an FYI, none of these workarounds do anything in MacOS's Terminal.app

@walles
Copy link
Owner Author

walles commented Oct 22, 2021

Just added this text, does this help @thepeoplesbourgeois?

  • macOS Terminal on a laptop: Hold down the fn key while marking with the mouse

@chrisgrieser
Copy link

I am using Hyper on mac, and neither holding alt nor holding fn works here :(

@walles
Copy link
Owner Author

walles commented Feb 23, 2022

Try setting macOptionSelectionMode: 'force' in your config file and hold Option while marking, does that work?

        // choose either `'vertical'`, if you want the column mode when Option key is hold during selection (Default)
        // or `'force'`, if you want to force selection regardless of whether the terminal is in mouse events mode
        // (inside tmux or vim with mouse mode enabled for example).
        macOptionSelectionMode: 'vertical',

@chrisgrieser
Copy link

ah yes, that works, thanks a lot! ☺️

@chrisgrieser
Copy link

just to add to the list of workarounds: in Alacritty, you have to use use shift + mouse selection to make it work.

@brunoroque06
Copy link

brunoroque06 commented Aug 9, 2022

With Wezterm, on macOS, I could not find a workaround to select text, or open URLs with the mouse. I have tried the ones listed above.

I think the relevant configuration for this issue is this: https://wezfurlong.org/wezterm/config/lua/config/bypass_mouse_reporting_modifiers.html#bypass_mouse_reporting_modifiers--shift .

@walles
Copy link
Owner Author

walles commented Aug 14, 2022

@brunoroque06 the reason it didn't work for you was likely wez/wezterm#2389.

Can you find a wezterm build that isn't affected by that issue and try again?

@brunoroque06
Copy link

@walles ah nice, it works on the nightly build. Thanks.

One has to press bypass_mouse_reporting_modifiers (shift by default), and then it is possible to select text, and open URLs. Thank you.

@felix-seifert
Copy link

I also experience the issue that I cannot mark anything with my mouse on Ubuntu. I use the terminal emulator Terminator. As a workaround, I can hold the shift button to actually mark text.

@PrayagS
Copy link

PrayagS commented Apr 11, 2023

For anyone else wondering, on kitty, shift or fn seem to do the trick on macOS.

@Macr0Nerd
Copy link

shift works for Tilix

@cig0
Copy link

cig0 commented May 22, 2023

Same thing for Konsole ❤️

@BarbzYHOOL
Copy link

shift works for Tilix

yes but why do we need shift and not just click??

@walles
Copy link
Owner Author

walles commented Nov 27, 2023

shift works for Tilix

yes but why do we need shift and not just click??

Maybe you should ask the Tilix authors? They could probably shed further light on this.

Basically moar tells the terminal it wants mouse scroll events, and in most terminals (like Tilix), this has the side effect of disabling mouse copying.

Don't know why a lot of terminals disable mouse copying when reporting scroll events. In iTerm this is configurable so that you can copy without holding down any special button.

Comparing to less, less defaults to broken mouse scrolling but working copying. moar defaults to working mouse scrolling but broken copying.

@postsolar
Copy link
Contributor

In foot, it's this configuration setting which enables selection in applications that grab the mouse:

[mouse-bindings]
selection-override-modifiers=Mod1

By default it's Shift, in my example it's set to Alt

walles added a commit that referenced this issue Dec 15, 2023
Relates to #53, will make things better on some terminals.
@postsolar
Copy link
Contributor

In Contour it's Shift by default. Using moar with --mousemode mark disables scrolling (no scrolling emulation as of now).

@gclements-chwy
Copy link

One more data point. I'm on MacOS/MacBook Pro and use an external keyboard (and monitor) and the Fn key on the external keyboard and click does not work to select text. The work around is to open the laptop enough to hold down the Fn key on the laptop keyboard and click. My external keyboard is a Razer BlackWidow Tournament Stealth Edition. I haven't tried other keyboards. (Oh, and I'm using the Colemak key layout.)

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

No branches or pull requests

12 participants