views:

2240

answers:

4

How can I setup GNU screen to allow the mouse's scrollwheel to scroll around in the scrollback buffer? I tried to Google about this, but most hits where on how to allow applications inside screen to use the scrollwheel.

+4  A: 

In screen, you must first enter "scrollback mode" to be able to scroll around in the scrollback buffer: key combo Ctrl-a [Esc], or Ctrl-a Ctrl-[. Then you can scroll around the history using Up and Down keys (or Ctrl-b, Ctrl-f to move a page).

In that mode, your mousewheel should also work, if it works in other apps. You end "scrollback mode" with [Esc].

As for scrolling the scrollback buffer without first entering scrollback mode, that is probably not possible without modifying screen. I have never heard of a way to access the scrollback buffer, apart from scrollback mode.

sleske
Yes, I know about scrollback mode. I was hoping that I would not have to manually enter scrollback mode in order to use the mouse. Thanks.
JesperE
+7  A: 

I believe you can just add a line like this to your ~/.screenrc:

termcapinfo xterm* ti@:te@

Where "xterm*" is a glob match of your current TERM. To confirm it works, ^A^D to detach from your screen, then "screen -d -r" to reattach, then ls a few times, and try to scroll back. It works for me.

Pistos
It's too bad you came late, because I'm pretty sure this is the answer the OP was looking for.
IanGreenleaf
I followed Pistos's suggestion, and it partially works. As he describes, I can enter some commands (to produce enough output to scroll the screen), and then use the mouse-wheel to scroll back through the preceding lines.In fact, I'm using screen via Konsole in KDE (tabbed xterm, basically), and the scrollbar for the Konsole window works the same way.But there's a problem: If you switch between screen's windows (^A-n, ^A-p), your scrollback buffer gets messed up. The contents of any windows you switch into will just get 'tucked' up into your scrollback buffer. That really diminishes it.
Ryan B. Lynch
The behaviour you describe indeed happens, even for me. It's something I live with; I just alternate between scroll wheel and Copy Mode.
Pistos
But this scrolls around in the command history. I want to scroll through the output buffer.
JesperE
That's not the behaviour I experience, JesperE.
Pistos
This works for me ssh'ing into ubuntu from Mac OS X using iTerm. Thanks!
Nate Murray
+1  A: 

This guy's post describes how to do it pretty perfectly, it worked for me on ubuntu's shell and it sounds like users have also had success in KDE.

http://www.staldal.nu/tech/2009/01/11/how-to-use-mousewheel-in-gnu-screen/comment-page-1/#comment-512

Still looking for an OS X solution..

Jon z
+2  A: 

The excellent article that Jon Z is referring to is no longer available, but I was able to fish the text-only version of it from the Google cache. I'm saving it here in case Google drops that as well in the future. Original post was by Mikael Ståldal so credit where credit is due.

--

How to use mousewheel in GNU Screen

GNU Screen has support for scrollback, but by default you have to use awkward keys to use it. I would like to be able to use Shift-PageUp, Shift-PageDown and the mousewheel to scroll, just like you can do in xterm.

It was not easy to configure Screen for this, and it involves cooperation with the terminal emulator. But I finally managed to achieve a solution which works pretty well. Add this to your ~/.Xresources file (you need to log out for this to take effect):

XTerm*saveLines: 0
XTerm*vt100.translations: #override \n\
  Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  <Btn4Down>: string(0x1b) string("[5S") \n\
  Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  <Btn5Down>: string(0x1b) string("[5T") \n\
  Shift <KeyPress> Prior: string(0x1b) string("[25S") \n\
  Shift <KeyPress> Next: string(0x1b) string("[25T") \n

Then add this to your ~/.screenrc file:

defscrollback 1000

# Scroll up
bindkey -d "^[[5S" eval copy "stuff 5\025"
bindkey -m "^[[5S" stuff 5\025

# Scroll down
bindkey -d "^[[5T" eval copy "stuff 5\004"
bindkey -m "^[[5T" stuff 5\004

# Scroll up more
bindkey -d "^[[25S" eval copy "stuff \025"
bindkey -m "^[[25S" stuff \025

# Scroll down more
bindkey -d "^[[25T" eval copy "stuff \004"
bindkey -m "^[[25T" stuff \004

This works in xterm. I’m not sure if it works in other terminal emulators.

Note that this disables the normal scrolling support in xterm, you will only be able to scroll when using Screen. You might want to start xterm like this to always use Screen:

xterm -e screen
Tommi R.