summarylogtreecommitdiffstats
path: root/clear.patch
blob: 402287677a613f2a40c739bab58d6c935dde8d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
diff -r 4399ffb6a87c -r 48f53e1cf599 src/command.C
--- a/src/command.C	Sat Jan 21 13:57:22 2012 +0100
+++ b/src/command.C	Mon Apr 30 16:22:25 2012 +0200
@@ -2869,6 +2869,10 @@
       return;
     }
 
+  /* remember the current row on position change, in case there's a clear screen
+   * right after, so that we can add "preserve" the buffer (e.g. on ^L) */
+  static int old_row = -1, was_moved = 0;
+  
   switch (ch)
     {
         /*
@@ -2932,6 +2936,12 @@
 
       case CSI_CUP:		/* 8.3.21: (1,1) CURSOR POSITION */
       case CSI_HVP:		/* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
+        /* if moving to row 1, remember current row in case a clear screen comes next */
+        if (nargs == 1 && arg[0] == 1 && current_screen == 0)
+          {
+            was_moved = 1;
+            old_row = screen.cur.row;
+          }
         scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
         break;
 
@@ -2943,6 +2953,16 @@
         break;
 
       case CSI_ED:		/* 8.3.40: (0) ERASE IN PAGE */
+        if (was_moved)
+          {
+            /* this is most likely a ^L, so we'll go back to where we where before
+             * the position change, add a screen of empty lines, then move back
+             * on top. that way the (scrolling) buffer will be preserved */
+            scr_gotorc (old_row, 0, 0);
+            for (int i = nrow - 1; i > 0; --i)
+                scr_add_lines (L"\r\n", 2);
+            scr_gotorc (0, 0, 0);
+          }
         scr_erase_screen (arg[0]);
         break;
 
@@ -3086,6 +3106,16 @@
       default:
         break;
     }
+    if (was_moved > 0)
+      {
+        if (was_moved > 1)
+          {
+            was_moved = 0;
+            old_row = -1;
+          }
+        else
+          ++was_moved;
+      }
 }
 /*}}} */