在 GNU 屏幕中使用滚轮

发布于 2024-07-09 18:41:50 字数 77 浏览 8 评论 0原文

如何设置 GNU 屏幕以允许鼠标滚轮在回滚缓冲区中滚动? 我尝试用谷歌搜索这个问题,但大多数点击都是关于如何允许屏幕内的应用程序使用滚轮。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

昨迟人 2024-07-16 18:41:50

我相信您可以将这样的行添加到您的 ~/.screenrc 中:

termcapinfo xterm* ti@:te@

其中“xterm*”是当前术语的全局匹配。 要确认其有效,请按 ^A^D 从屏幕上分离,然后按 screen -d -r 重新连接,然后按 ls 几次,然后尝试向后滚动。 这个对我有用。


这是什么魔法? 好吧,让我们查阅一下手册页。

screen(1) 说:

termcapinfo term terminal-tweaks [window-tweaks]
  [..]
  The first argument specifies which terminal(s) should be affected by this
  definition. You can specify multiple terminal names by separating them with
  `|'s. Use `*' to match all terminals and `vt*' to match all terminals that
  begin with "vt".
  [..]
  Some examples:

      termcap xterm*  LP:hs@

  Informs screen that all terminals that begin with `xterm' have firm
  auto-margins that allow the last position on the screen to be updated (LP),
  but they don't really have a status line (no 'hs' -  append  `@'  to turn
  entries off).  Note that we assume `LP' for all terminal names that start
  with "vt", but only if you don't specify a termcap command for that terminal.

来自 termcap(5)

String capabilities
    [..]
    te   End program that uses cursor motion
    ti   Begin program that uses cursor motion

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.


What is this magic? Well, let's consult the manual pages.

screen(1) says:

termcapinfo term terminal-tweaks [window-tweaks]
  [..]
  The first argument specifies which terminal(s) should be affected by this
  definition. You can specify multiple terminal names by separating them with
  `|'s. Use `*' to match all terminals and `vt*' to match all terminals that
  begin with "vt".
  [..]
  Some examples:

      termcap xterm*  LP:hs@

  Informs screen that all terminals that begin with `xterm' have firm
  auto-margins that allow the last position on the screen to be updated (LP),
  but they don't really have a status line (no 'hs' -  append  `@'  to turn
  entries off).  Note that we assume `LP' for all terminal names that start
  with "vt", but only if you don't specify a termcap command for that terminal.

From termcap(5):

String capabilities
    [..]
    te   End program that uses cursor motion
    ti   Begin program that uses cursor motion
毅然前行 2024-07-16 18:41:50

在屏幕中,您必须首先进入“回滚模式”(或“复制模式”)才能在回滚缓冲区中滚动:组合键 Ctrl-a Esc,或 Ctrl-a Ctrl-[。 然后,您可以使用向上和向下键(或 Ctrl-bCtrl-f 滚动历史记录移动一页)。

在该模式下,您的鼠标滚轮也应该可以工作(如果它在其他应用程序中有效)。
您可以使用 Esc 结束“回滚模式”。

至于在不首先进入回滚模式的情况下滚动回滚缓冲区,如果不修改屏幕,这可能是不可能的。 除了回滚模式之外,我从未听说过访问回滚缓冲区的方法。

In screen, you must first enter "scrollback mode" (or "copy 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.

半﹌身腐败 2024-07-16 18:41:50

Jon Z 提到的这篇优秀文章已不再可用,但我能够从 Google 缓存中获取它的纯文本版本。 我将其保存在这里,以防 Google 将来也放弃它。 最初的帖子是由 Mikael Ståldal 撰写的,所以应得的归功于。

--

如何在 GNU Screen 中使用鼠标滚轮

GNU Screen 支持回滚,但默认情况下您必须使用笨拙的按键才能使用它。 我希望能够使用 Shift-PageUp、Shift-PageDown 和鼠标滚轮进行滚动,就像在 xterm 中一样。

为此配置Screen并不容易,并且涉及到与终端仿真器的配合。 但我最终设法实现了一个效果很好的解决方案。 将其添加到您的 ~/.Xresources 文件中(您需要注销才能生效):

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

然后将其添加到您的 ~/.screenrc 文件中:

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

这在 xterm 中有效。 我不确定它是否适用于其他终端模拟器。

请注意,这会禁用 xterm 中的正常滚动支持,您将只能在使用 Screen 时滚动。 您可能希望像这样启动 xterm 以始终使用 Screen:

xterm -e screen

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
芸娘子的小脾气 2024-07-16 18:41:50

并在 GNU Screen 内的 VIM 中使用滚轮:

[.vimrc]

set mouse=a             " hold shift to copy xterm
set ttymouse=xterm2     " necessary for gnu screen & mouse

And to use the scrollwheel in a VIM inside GNU Screen:

[.vimrc]

set mouse=a             " hold shift to copy xterm
set ttymouse=xterm2     " necessary for gnu screen & mouse
山人契 2024-07-16 18:41:50

对于 OS X(雪豹),以下内容对我有用:

http ://slaptijack.com/system-administration/mac-os-x-terminal-and-gnu-screen-scrollback/

简而言之,它涉及将以下内容添加到远程主机上的 ~/.screenrc (你正在运行屏幕):

defscrollback 5000
termcapinfo xterm* ti@:te@

For OS X (Snow Leopard), the following worked for me:

http://slaptijack.com/system-administration/mac-os-x-terminal-and-gnu-screen-scrollback/

Briefly, it involves adding the following to ~/.screenrc on the remote host (the one you're running screen on):

defscrollback 5000
termcapinfo xterm* ti@:te@
画离情绘悲伤 2024-07-16 18:41:50

以下内容在 Cygwin 和 Putty 中都对我有用:
编辑.screenrc并添加

terminfo xterm* ti=:te=

The following worked for me in both Cygwin and Putty:
Edit .screenrc and add

terminfo xterm* ti=:te=
皇甫轩 2024-07-16 18:41:50

在运行屏幕之前将 TERM 变量设置为 vt100 而不是 xterm 也可以。
我已经使用它很长时间了,效果非常好。

将其添加到您的 .bashrc 中:

# make scrollbar / wheel scrolling work when running screen in gnome-terminal (or other)
if [ "$TERM" = "xterm" ]; then
  export TERM=vt100
fi

--

作为参考,我的 .screenrc 有此内容(据我所知不需要):

# Extend the vt100 desciption by some sequences.
termcap  vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC
terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC

Setting TERM variable to vt100 instead of xterm before running screen also works.
I've been using this for a long time, works like a charm.

Add this to your .bashrc:

# make scrollbar / wheel scrolling work when running screen in gnome-terminal (or other)
if [ "$TERM" = "xterm" ]; then
  export TERM=vt100
fi

--

For reference, my .screenrc has this (not needed for this AFAIK):

# Extend the vt100 desciption by some sequences.
termcap  vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC
terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC
幸福丶如此 2024-07-16 18:41:50

Ctrl+a,然后按 [

您终端的标题栏现在应显示“复制模式”。

现在箭头键和鼠标滚轮应该按预期工作。

要恢复正常,请按 Esc 或按 Enter 几次。

Press Ctrl+a followed by [

The title bar of your terminal should now say Copy mode.

Now the arrow keys and the mouse wheel should work as expected.

To return to normal press Esc or press Enter a couple of times.

唠甜嗑 2024-07-16 18:41:50

使用“Ubuntu 16.04.2 LTS”时的解决方案如下:

a). 按照之前的答案指定更新$HOME/.screenrc

termcapinfo xterm* ti@:te@

b)。 使用“设置”-“首选应用程序”,通过在下拉列表中选择“X 终端”将默认终端更改为 xterm。

一些多余的注释

  • 其他终端都没有,包括安装“lxterminal”,
    为我工作,即使我将 termcapinfo 行更改为“*”
    而不是“xterm*”。

  • 通过单击屏幕左上角的菜单按钮,您可以
    可以使用右下角第三个图标打开“设置”对话框
    角。

The solution when using "Ubuntu 16.04.2 LTS" is as follows:

a). Update $HOME/.screenrc as previous answers have specified:

termcapinfo xterm* ti@:te@

b). Use "Settings"."Preferred Applications" to alter the default terminal to xterm, by selecting the "X Terminal" one in the drop-down list.

Some superfluous notes

  • None of the other terminals, including installing "lxterminal",
    worked for me, even when I altered the termcapinfo line to "*"
    instead of "xterm*".

  • By clicking the menu button in the top-left corner of the screen, you
    can get the Settings dialog using the 3rd icon from the bottom right
    corner.

请帮我爱他 2024-07-16 18:41:50

如果上述答案不适合您,请确保您的 .screenrc 中没有设置标题alwayslastline选项。 如果你有它们,这将不起作用:

termcapinfo xterm* ti@:te@

如果你需要此信息,你可以尝试在终端的标题中设置它(使用 termcapinfo

If the answers above don't work for you, make sure you don't have a caption or the alwayslastline option set in your .screenrc. If you have them, this will not work:

termcapinfo xterm* ti@:te@

If you need this information, you can try setting it in the title of your terminal (with termcapinfo)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文