st-full-scrollback-0.7.diff 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. diff --git st-0.7/config.def.h st-0.7/config.def.h
  2. index b41747f..eae969e 100644
  3. --- st-0.7/config.def.h
  4. +++ st-0.7/config.def.h
  5. @@ -7,6 +7,7 @@
  6. */
  7. static char font[] = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
  8. static int borderpx = 2;
  9. +#define histsize 2000
  10. /*
  11. * What program is execed by st depends of these precedence rules:
  12. @@ -172,6 +173,8 @@ static Shortcut shortcuts[] = {
  13. { MODKEY|ShiftMask, XK_C, clipcopy, {.i = 0} },
  14. { MODKEY|ShiftMask, XK_V, clippaste, {.i = 0} },
  15. { MODKEY, XK_Num_Lock, numlock, {.i = 0} },
  16. + { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
  17. + { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
  18. };
  19. /*
  20. diff --git a/st.c b/st.c
  21. index 2594c65..233d301 100644
  22. --- st-0.7/st.c
  23. +++ st-0.7/st.c
  24. @@ -86,6 +86,8 @@ char *argv0;
  25. #define TRUERED(x) (((x) & 0xff0000) >> 8)
  26. #define TRUEGREEN(x) (((x) & 0xff00))
  27. #define TRUEBLUE(x) (((x) & 0xff) << 8)
  28. +#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - term.scr \
  29. + + histsize + 1) % histsize] : term.line[(y) - term.scr])
  30. enum glyph_attribute {
  31. @@ -228,26 +230,6 @@ typedef struct {
  32. int narg; /* nb of args */
  33. } STREscape;
  34. -/* Internal representation of the screen */
  35. -typedef struct {
  36. - int row; /* nb row */
  37. - int col; /* nb col */
  38. - Line *line; /* screen */
  39. - Line *alt; /* alternate screen */
  40. - int *dirty; /* dirtyness of lines */
  41. - XftGlyphFontSpec *specbuf; /* font spec buffer used for rendering */
  42. - TCursor c; /* cursor */
  43. - int top; /* top scroll limit */
  44. - int bot; /* bottom scroll limit */
  45. - int mode; /* terminal mode flags */
  46. - int esc; /* escape state flags */
  47. - char trantbl[4]; /* charset table translation */
  48. - int charset; /* current charset */
  49. - int icharset; /* selected charset for sequence */
  50. - int numlock; /* lock numbers in keyboard */
  51. - int *tabs;
  52. -} Term;
  53. -
  54. /* Purely graphic info */
  55. typedef struct {
  56. Display *dpy;
  57. @@ -327,6 +309,8 @@ typedef struct {
  58. /* function definitions used in config.h */
  59. static void clipcopy(const Arg *);
  60. static void clippaste(const Arg *);
  61. +static void kscrolldown(const Arg *);
  62. +static void kscrollup(const Arg *);
  63. static void numlock(const Arg *);
  64. static void selpaste(const Arg *);
  65. static void xzoom(const Arg *);
  66. @@ -340,6 +324,29 @@ static void sendbreak(const Arg *);
  67. /* Config.h for applying patches and the configuration. */
  68. #include "config.h"
  69. +/* Internal representation of the screen */
  70. +typedef struct {
  71. + int row; /* nb row */
  72. + int col; /* nb col */
  73. + Line *line; /* screen */
  74. + Line *alt; /* alternate screen */
  75. + Line hist[histsize]; /* history buffer */
  76. + int histi; /* history index */
  77. + int scr; /* scroll back */
  78. + int *dirty; /* dirtyness of lines */
  79. + XftGlyphFontSpec *specbuf; /* font spec buffer used for rendering */
  80. + TCursor c; /* cursor */
  81. + int top; /* top scroll limit */
  82. + int bot; /* bottom scroll limit */
  83. + int mode; /* terminal mode flags */
  84. + int esc; /* escape state flags */
  85. + char trantbl[4]; /* charset table translation */
  86. + int charset; /* current charset */
  87. + int icharset; /* selected charset for sequence */
  88. + int numlock; /* lock numbers in keyboard */
  89. + int *tabs;
  90. +} Term;
  91. +
  92. /* Font structure */
  93. typedef struct {
  94. int height;
  95. @@ -399,8 +406,8 @@ static void tputtab(int);
  96. static void tputc(Rune);
  97. static void treset(void);
  98. static void tresize(int, int);
  99. -static void tscrollup(int, int);
  100. -static void tscrolldown(int, int);
  101. +static void tscrollup(int, int, int);
  102. +static void tscrolldown(int, int, int);
  103. static void tsetattr(int *, int);
  104. static void tsetchar(Rune, Glyph *, int, int);
  105. static void tsetscroll(int, int);
  106. @@ -731,10 +738,10 @@ tlinelen(int y)
  107. {
  108. int i = term.col;
  109. - if (term.line[y][i - 1].mode & ATTR_WRAP)
  110. + if (TLINE(y)[i - 1].mode & ATTR_WRAP)
  111. return i;
  112. - while (i > 0 && term.line[y][i - 1].u == ' ')
  113. + while (i > 0 && TLINE(y)[i - 1].u == ' ')
  114. --i;
  115. return i;
  116. @@ -796,7 +803,7 @@ selsnap(int *x, int *y, int direction)
  117. * Snap around if the word wraps around at the end or
  118. * beginning of a line.
  119. */
  120. - prevgp = &term.line[*y][*x];
  121. + prevgp = &TLINE(*y)[*x];
  122. prevdelim = ISDELIM(prevgp->u);
  123. for (;;) {
  124. newx = *x + direction;
  125. @@ -811,14 +818,14 @@ selsnap(int *x, int *y, int direction)
  126. yt = *y, xt = *x;
  127. else
  128. yt = newy, xt = newx;
  129. - if (!(term.line[yt][xt].mode & ATTR_WRAP))
  130. + if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
  131. break;
  132. }
  133. if (newx >= tlinelen(newy))
  134. break;
  135. - gp = &term.line[newy][newx];
  136. + gp = &TLINE(newy)[newx];
  137. delim = ISDELIM(gp->u);
  138. if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
  139. || (delim && gp->u != prevgp->u)))
  140. @@ -839,14 +846,14 @@ selsnap(int *x, int *y, int direction)
  141. *x = (direction < 0) ? 0 : term.col - 1;
  142. if (direction < 0) {
  143. for (; *y > 0; *y += direction) {
  144. - if (!(term.line[*y-1][term.col-1].mode
  145. + if (!(TLINE(*y-1)[term.col-1].mode
  146. & ATTR_WRAP)) {
  147. break;
  148. }
  149. }
  150. } else if (direction > 0) {
  151. for (; *y < term.row-1; *y += direction) {
  152. - if (!(term.line[*y][term.col-1].mode
  153. + if (!(TLINE(*y)[term.col-1].mode
  154. & ATTR_WRAP)) {
  155. break;
  156. }
  157. @@ -1012,13 +1019,13 @@ getsel(void)
  158. }
  159. if (sel.type == SEL_RECTANGULAR) {
  160. - gp = &term.line[y][sel.nb.x];
  161. + gp = &TLINE(y)[sel.nb.x];
  162. lastx = sel.ne.x;
  163. } else {
  164. - gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
  165. + gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
  166. lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
  167. }
  168. - last = &term.line[y][MIN(lastx, linelen-1)];
  169. + last = &TLINE(y)[MIN(lastx, linelen-1)];
  170. while (last >= gp && last->u == ' ')
  171. --last;
  172. @@ -1490,6 +1497,9 @@ ttyread(void)
  173. /* keep any uncomplete utf8 char for the next call */
  174. memmove(buf, ptr, buflen);
  175. + if (term.scr > 0 && term.scr < histsize-1)
  176. + term.scr++;
  177. +
  178. return ret;
  179. }
  180. @@ -1499,6 +1509,9 @@ ttywrite(const char *s, size_t n)
  181. fd_set wfd, rfd;
  182. ssize_t r;
  183. size_t lim = 256;
  184. + Arg arg = (Arg){ .i = term.scr };
  185. +
  186. + kscrolldown(&arg);
  187. /*
  188. * Remember that we are using a pty, which might be a modem line.
  189. @@ -1690,13 +1703,53 @@ tswapscreen(void)
  190. }
  191. void
  192. -tscrolldown(int orig, int n)
  193. +kscrolldown(const Arg* a)
  194. +{
  195. + int n = a->i;
  196. +
  197. + if (n < 0)
  198. + n = term.row + n;
  199. +
  200. + if (n > term.scr)
  201. + n = term.scr;
  202. +
  203. + if (term.scr > 0) {
  204. + term.scr -= n;
  205. + selscroll(0, -n);
  206. + tfulldirt();
  207. + }
  208. +}
  209. +
  210. +void
  211. +kscrollup(const Arg* a)
  212. +{
  213. + int n = a->i;
  214. +
  215. + if (n < 0)
  216. + n = term.row + n;
  217. +
  218. + if (term.scr <= histsize - n) {
  219. + term.scr += n;
  220. + selscroll(0, n);
  221. + tfulldirt();
  222. + }
  223. +}
  224. +
  225. +void
  226. +tscrolldown(int orig, int n, int copyhist)
  227. {
  228. int i;
  229. Line temp;
  230. LIMIT(n, 0, term.bot-orig+1);
  231. + if (copyhist) {
  232. + term.histi = (term.histi - 1 + histsize) % histsize;
  233. + temp = term.hist[term.histi];
  234. + term.hist[term.histi] = term.line[term.bot];
  235. + term.line[term.bot] = temp;
  236. + }
  237. +
  238. tsetdirt(orig, term.bot-n);
  239. tclearregion(0, term.bot-n+1, term.col-1, term.bot);
  240. @@ -1710,13 +1763,20 @@ tscrolldown(int orig, int n)
  241. }
  242. void
  243. -tscrollup(int orig, int n)
  244. +tscrollup(int orig, int n, int copyhist)
  245. {
  246. int i;
  247. Line temp;
  248. LIMIT(n, 0, term.bot-orig+1);
  249. + if (copyhist) {
  250. + term.histi = (term.histi + 1) % histsize;
  251. + temp = term.hist[term.histi];
  252. + term.hist[term.histi] = term.line[orig];
  253. + term.line[orig] = temp;
  254. + }
  255. +
  256. tclearregion(0, orig, term.col-1, orig+n-1);
  257. tsetdirt(orig+n, term.bot);
  258. @@ -1765,7 +1825,7 @@ tnewline(int first_col)
  259. int y = term.c.y;
  260. if (y == term.bot) {
  261. - tscrollup(term.top, 1);
  262. + tscrollup(term.top, 1, 1);
  263. } else {
  264. y++;
  265. }
  266. @@ -1930,14 +1990,14 @@ void
  267. tinsertblankline(int n)
  268. {
  269. if (BETWEEN(term.c.y, term.top, term.bot))
  270. - tscrolldown(term.c.y, n);
  271. + tscrolldown(term.c.y, n, 0);
  272. }
  273. void
  274. tdeleteline(int n)
  275. {
  276. if (BETWEEN(term.c.y, term.top, term.bot))
  277. - tscrollup(term.c.y, n);
  278. + tscrollup(term.c.y, n, 0);
  279. }
  280. int32_t
  281. @@ -2371,11 +2431,11 @@ csihandle(void)
  282. break;
  283. case 'S': /* SU -- Scroll <n> line up */
  284. DEFAULT(csiescseq.arg[0], 1);
  285. - tscrollup(term.top, csiescseq.arg[0]);
  286. + tscrollup(term.top, csiescseq.arg[0], 0);
  287. break;
  288. case 'T': /* SD -- Scroll <n> line down */
  289. DEFAULT(csiescseq.arg[0], 1);
  290. - tscrolldown(term.top, csiescseq.arg[0]);
  291. + tscrolldown(term.top, csiescseq.arg[0], 0);
  292. break;
  293. case 'L': /* IL -- Insert <n> blank lines */
  294. DEFAULT(csiescseq.arg[0], 1);
  295. @@ -2871,7 +2931,7 @@ eschandle(uchar ascii)
  296. return 0;
  297. case 'D': /* IND -- Linefeed */
  298. if (term.c.y == term.bot) {
  299. - tscrollup(term.top, 1);
  300. + tscrollup(term.top, 1, 1);
  301. } else {
  302. tmoveto(term.c.x, term.c.y+1);
  303. }
  304. @@ -2884,7 +2944,7 @@ eschandle(uchar ascii)
  305. break;
  306. case 'M': /* RI -- Reverse index */
  307. if (term.c.y == term.top) {
  308. - tscrolldown(term.top, 1);
  309. + tscrolldown(term.top, 1, 1);
  310. } else {
  311. tmoveto(term.c.x, term.c.y-1);
  312. }
  313. @@ -3047,7 +3107,7 @@ tputc(Rune u)
  314. void
  315. tresize(int col, int row)
  316. {
  317. - int i;
  318. + int i, j;
  319. int minrow = MIN(row, term.row);
  320. int mincol = MIN(col, term.col);
  321. int *bp;
  322. @@ -3087,6 +3147,14 @@ tresize(int col, int row)
  323. term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
  324. term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
  325. + for (i = 0; i < histsize; i++) {
  326. + term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
  327. + for (j = mincol; j < col; j++) {
  328. + term.hist[i][j] = term.c.attr;
  329. + term.hist[i][j].u = ' ';
  330. + }
  331. + }
  332. +
  333. /* resize each row to new width, zero-pad if needed */
  334. for (i = 0; i < minrow; i++) {
  335. term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
  336. @@ -3976,11 +4044,11 @@ drawregion(int x1, int y1, int x2, int y2)
  337. term.dirty[y] = 0;
  338. specs = term.specbuf;
  339. - numspecs = xmakeglyphfontspecs(specs, &term.line[y][x1], x2 - x1, x1, y);
  340. + numspecs = xmakeglyphfontspecs(specs, &TLINE(y)[x1], x2 - x1, x1, y);
  341. i = ox = 0;
  342. for (x = x1; x < x2 && i < numspecs; x++) {
  343. - new = term.line[y][x];
  344. + new = TLINE(y)[x];
  345. if (new.mode == ATTR_WDUMMY)
  346. continue;
  347. if (ena_sel && selected(x, y))
  348. @@ -4000,7 +4068,8 @@ drawregion(int x1, int y1, int x2, int y2)
  349. if (i > 0)
  350. xdrawglyphfontspecs(specs, base, i, ox, y);
  351. }
  352. - xdrawcursor();
  353. + if (term.scr == 0)
  354. + xdrawcursor();
  355. }
  356. void