moar icon indicating copy to clipboard operation
moar copied to clipboard

Mouse copying

Open walles opened this issue 3 years ago β€’ 22 comments

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 avatar Apr 27 '21 16:04 walles

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 avatar Apr 27 '21 16:04 walles

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 avatar Apr 27 '21 16:04 walles

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 avatar Apr 27 '21 16:04 walles

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

walles avatar Apr 30 '21 06:04 walles

I figured it out for Windows.

You can 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.

89z avatar Sep 03 '21 15:09 89z

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

thepeoplesbourgeois avatar Oct 22 '21 01:10 thepeoplesbourgeois

Just added this text, does this help @thepeoplesbourgeois?

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

walles avatar Oct 22 '21 04:10 walles

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

chrisgrieser avatar Feb 23 '22 13:02 chrisgrieser

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',

walles avatar Feb 23 '22 18:02 walles

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

chrisgrieser avatar Feb 23 '22 22:02 chrisgrieser

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

chrisgrieser avatar Feb 24 '22 18:02 chrisgrieser

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 .

brunoroque06 avatar Aug 09 '22 16:08 brunoroque06

@brunoroque06 the reason it didn't work for you was likely https://github.com/wez/wezterm/issues/2389.

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

walles avatar Aug 14 '22 10:08 walles

@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.

brunoroque06 avatar Aug 14 '22 13:08 brunoroque06

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.

felix-seifert avatar Jan 12 '23 14:01 felix-seifert

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

PrayagS avatar Apr 11 '23 11:04 PrayagS

shift works for Tilix

Macr0Nerd avatar May 04 '23 08:05 Macr0Nerd

Same thing for Konsole :heart:

cig0 avatar May 22 '23 13:05 cig0

shift works for Tilix

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

BarbzYHOOL avatar Nov 26 '23 00:11 BarbzYHOOL

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.

walles avatar Nov 27 '23 17:11 walles

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

postsolar avatar Dec 11 '23 22:12 postsolar

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

postsolar avatar Dec 18 '23 16:12 postsolar