You are not logged in.

#1 2011-10-29 16:44:38

rlblaster
Member
Registered: 2007-12-28
Posts: 12

urxvt patch: VTE like clear screen behavior

I've switched to urxvt last week. I come from the VTE world (gnome-terminal, xfce-terminal and such, the latter in my case). VTE has a nice feature to which I've accustomed myself. This is the way how it handles the clear screen function (ctrl-L).

In VTE when you press ctrl-L, the screen cursor position gets to top row and the lines get scrolled just before the visible portion of the window. This means that the scrollback remains intact so you can scroll back and see it later. If you press ctrl-L again when you are at top you get a bunch of empty lines - you can use this to mark the scrollback with empty portions when you are scrolling back large amounts of texts.  This is handy for example when you want to quickly glance at an output from a command but you want to differentiate from different outputs - I press ctr-L several times before I execute the command and then I can just quickly scroll back - I immediately spot where the command began because it has a large black spot before it. smile

The way urxvt works in this case that it just positions the cursor to the top row and then just erases everything below that point. This means you lose valuable lines from the scrollback. Example: type "seq 1000", press ctr-L. Now you won't see the last lines of the command's output!

Now it is possible that I have a misconfigured urxvt and I'd be interested in the config option which I have misconfigured.

Here's a patch for urxvt which adds proper clear screen function and also adds the VTE-like functionality:

*** src/command.C	2011-10-29 18:06:07.000000000 +0200
--- src/command.C.patched	2011-10-29 18:05:28.000000000 +0200
*************** rxvt_term::process_csi_seq ()
*** 2932,2937 ****
--- 2932,2948 ----
  
        case CSI_CUP:		/* 8.3.21: (1,1) CURSOR POSITION */
        case CSI_HVP:		/* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
+         if (nargs == 1 && current_screen == 0)
+           {
+             // This is usually followed with clear screen so add some extra
+             // lines to avoid deleting the lines already on screen. If we are
+             // already at the top, add an extra screen height of lines.
+             int extra_lines = nrow-1;
+             if (screen.cur.row == 0)
+               extra_lines += nrow;
+             for (int i = 0; i < extra_lines; ++i)
+               scr_add_lines (L"\r\n", 2);
+           }
          scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
          break;
  

Last edited by rlblaster (2011-10-29 19:07:32)

Offline

#2 2011-11-09 20:07:08

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: urxvt patch: VTE like clear screen behavior

Have you considered sending this patch upstream?

Offline

#3 2011-11-09 20:28:48

rlblaster
Member
Registered: 2007-12-28
Posts: 12

Re: urxvt patch: VTE like clear screen behavior

As far as I know they don't accept new features just bugfixes. Even the patch itself is a hack (there might be cases when it won't work as expected) so no. smile

Last edited by rlblaster (2011-11-09 20:29:26)

Offline

#4 2012-01-06 13:21:59

avx
Member
Registered: 2011-07-05
Posts: 71

Re: urxvt patch: VTE like clear screen behavior

Nice patch, but it breaks my prompt and all my working sad

See here, please: https://bugs.gentoo.org/show_bug.cgi?id=397829

Offline

#5 2012-01-06 17:29:58

rlblaster
Member
Registered: 2007-12-28
Posts: 12

Re: urxvt patch: VTE like clear screen behavior

I can't reproduce this. I'm not very familiar with zsh but you seem to be missing the closing ' from the PS1 line in the bug report. Could please paste the exact line?

By the way, I'm suspecting that you might be applying some other patches which might somehow confuse my patch (or my patch confuses another patch). Would it be possible to try urxvt with my patch only? Also, could you please upload your patched src/command.C somewhere so that I can check the "confusion"? smile

Offline

#6 2012-01-07 00:29:13

avx
Member
Registered: 2011-07-05
Posts: 71

Re: urxvt patch: VTE like clear screen behavior

Yes, forgot the closing ', C&P error, for reference

PS1=$'%{\e[s\e[H\e[30;42;1m%}[%~][%M] %{\e[K\e[256C\e[8D\e[30;42;1m%} [%D{%H:%M}]%(?,%{\e[32;32m%}█,%{\e[31;41;1m█)%}%{\e[u\e[1A%}\n%{\e[0;32m%}> %{\e[0m%}'

Downloaded the dist-tarball, patched it with your patch, used my prompt and the problem arises again, so no other/custom patches to blame imho.

For your understanding - in the case you don't see it - my PS1 always repaints the first line, thus clearing the cursor-position, moving it up, drawing stuff and then putting the cursor back down to where it belongs. Always worked, still works in xterm and works without your patch.

Patched command.C is here: http://pastebin.ca/2100597

Thanks for your quick response smile

Offline

#7 2012-01-07 08:42:14

rlblaster
Member
Registered: 2007-12-28
Posts: 12

Re: urxvt patch: VTE like clear screen behavior

Now I see what's happening! Your prompt uses '\e[H' which is used as move to home. I assumed that '\e[H' is usually followed with clear screen. This means if you use it to just move the cursor to home it won't work. I don't really see how could I fix this nicely but here's a workaround for your prompt: use '\e[1;1H'. In other words:

PS1=$'%{\e[s\e[1;1H\e[30;42;1m%}[%~][%M] %{\e[K\e[256C\e[8D\e[30;42;1m%} [%D{%H:%M}]%(?,%{\e[32;32m%}\u2588,%{\e[31;41;1m\u2588)%}%{\e[u\e[1A%}\n%{\e[0;32m%}> %{\e[0m%}'

By the way the feature of adding extra blank lines if your cursor is already at top won't work in your prompt because your cursor is always at least on row 1. You could change the patch from

             if (screen.cur.row == 0)

to

             if (screen.cur.row <= 1)

to have this feature.

Offline

#8 2012-01-07 14:59:55

avx
Member
Registered: 2011-07-05
Posts: 71

Re: urxvt patch: VTE like clear screen behavior

Thank you, that seems to work.

For those interested, this patch is now accessible via USE=buffer-on-clear in Gentoo, see link to the bug above.

Offline

#9 2012-04-30 15:15:15

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

Re: urxvt patch: VTE like clear screen behavior

First off, thanks for the patch, been using it for a while. smile

I'm not sure if this also applies the the PS1 issue mentioned above, but I have noticed some problems with this patch, e.g. when apps use their own pager to show their output, such as when doing "git diff" or using systemd. It's also due to a position change not being following by a clear screen, and the added lines (by the patch) causing problems in such a case.

Finally tried to have a look at it, and this is the new patch I came up with: https://gist.github.com/2559054
Seems to solve the issue AFAICS, at least the ^L works the same (everything in the buffer preserved), and using "git diff" now works as expected. Not sure if that would solve the PS1 issue, but it might.

Offline

Board footer

Powered by FluxBB