summaryrefslogtreecommitdiff
path: root/utils/st-0.8.5/patches
diff options
context:
space:
mode:
Diffstat (limited to 'utils/st-0.8.5/patches')
-rw-r--r--utils/st-0.8.5/patches/st-alpha-20220206-0.8.5.diff146
-rw-r--r--utils/st-0.8.5/patches/st-blinking_cursor-20211116-2f6e597.diff153
-rw-r--r--utils/st-0.8.5/patches/st-graphics.diff166
-rw-r--r--utils/st-0.8.5/patches/st-hidecursor-0.8.3.diff88
-rw-r--r--utils/st-0.8.5/patches/st-scrollback-ringbuffer-0.8.5.diff730
5 files changed, 0 insertions, 1283 deletions
diff --git a/utils/st-0.8.5/patches/st-alpha-20220206-0.8.5.diff b/utils/st-0.8.5/patches/st-alpha-20220206-0.8.5.diff
deleted file mode 100644
index ab029f6..0000000
--- a/utils/st-0.8.5/patches/st-alpha-20220206-0.8.5.diff
+++ /dev/null
@@ -1,146 +0,0 @@
-diff --git a/config.def.h b/config.def.h
-index 91ab8ca..6af616e 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -93,6 +93,9 @@ char *termname = "st-256color";
- */
- unsigned int tabspaces = 8;
-
-+/* bg opacity */
-+float alpha = 0.8;
-+
- /* Terminal colors (16 first used in escape sequence) */
- static const char *colorname[] = {
- /* 8 normal colors */
-diff --git a/config.mk b/config.mk
-index 4c4c5d5..0114bad 100644
---- a/config.mk
-+++ b/config.mk
-@@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
- INCS = -I$(X11INC) \
- `$(PKG_CONFIG) --cflags fontconfig` \
- `$(PKG_CONFIG) --cflags freetype2`
--LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
-+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
- `$(PKG_CONFIG) --libs fontconfig` \
- `$(PKG_CONFIG) --libs freetype2`
-
-diff --git a/st.h b/st.h
-index 519b9bd..8bb533d 100644
---- a/st.h
-+++ b/st.h
-@@ -126,3 +126,4 @@ extern unsigned int tabspaces;
- extern unsigned int defaultfg;
- extern unsigned int defaultbg;
- extern unsigned int defaultcs;
-+extern float alpha;
-diff --git a/x.c b/x.c
-index 8a16faa..ddf4178 100644
---- a/x.c
-+++ b/x.c
-@@ -105,6 +105,7 @@ typedef struct {
- XSetWindowAttributes attrs;
- int scr;
- int isfixed; /* is fixed geometry? */
-+ int depth; /* bit depth */
- int l, t; /* left and top offset */
- int gm; /* geometry mask */
- } XWindow;
-@@ -243,6 +244,7 @@ static char *usedfont = NULL;
- static double usedfontsize = 0;
- static double defaultfontsize = 0;
-
-+static char *opt_alpha = NULL;
- static char *opt_class = NULL;
- static char **opt_cmd = NULL;
- static char *opt_embed = NULL;
-@@ -736,7 +738,7 @@ xresize(int col, int row)
-
- XFreePixmap(xw.dpy, xw.buf);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
-- DefaultDepth(xw.dpy, xw.scr));
-+ xw.depth);
- XftDrawChange(xw.draw, xw.buf);
- xclear(0, 0, win.w, win.h);
-
-@@ -796,6 +798,13 @@ xloadcols(void)
- else
- die("could not allocate color %d\n", i);
- }
-+
-+ /* set alpha value of bg color */
-+ if (opt_alpha)
-+ alpha = strtof(opt_alpha, NULL);
-+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
-+ dc.col[defaultbg].pixel &= 0x00FFFFFF;
-+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
- loaded = 1;
- }
-
-@@ -1118,11 +1127,23 @@ xinit(int cols, int rows)
- Window parent;
- pid_t thispid = getpid();
- XColor xmousefg, xmousebg;
-+ XWindowAttributes attr;
-+ XVisualInfo vis;
-
- if (!(xw.dpy = XOpenDisplay(NULL)))
- die("can't open display\n");
- xw.scr = XDefaultScreen(xw.dpy);
-- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
-+
-+ if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
-+ parent = XRootWindow(xw.dpy, xw.scr);
-+ xw.depth = 32;
-+ } else {
-+ XGetWindowAttributes(xw.dpy, parent, &attr);
-+ xw.depth = attr.depth;
-+ }
-+
-+ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
-+ xw.vis = vis.visual;
-
- /* font */
- if (!FcInit())
-@@ -1132,7 +1153,7 @@ xinit(int cols, int rows)
- xloadfonts(usedfont, 0);
-
- /* colors */
-- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
-+ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
- xloadcols();
-
- /* adjust fixed window geometry */
-@@ -1152,19 +1173,15 @@ xinit(int cols, int rows)
- | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
- xw.attrs.colormap = xw.cmap;
-
-- if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
-- parent = XRootWindow(xw.dpy, xw.scr);
- xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
-- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
-+ win.w, win.h, 0, xw.depth, InputOutput,
- xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
- | CWEventMask | CWColormap, &xw.attrs);
-
- memset(&gcvalues, 0, sizeof(gcvalues));
- gcvalues.graphics_exposures = False;
-- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
-- &gcvalues);
-- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
-- DefaultDepth(xw.dpy, xw.scr));
-+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
-+ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
- XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
- XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
-
-@@ -2019,6 +2036,9 @@ main(int argc, char *argv[])
- case 'a':
- allowaltscreen = 0;
- break;
-+ case 'A':
-+ opt_alpha = EARGF(usage());
-+ break;
- case 'c':
- opt_class = EARGF(usage());
- break;
diff --git a/utils/st-0.8.5/patches/st-blinking_cursor-20211116-2f6e597.diff b/utils/st-0.8.5/patches/st-blinking_cursor-20211116-2f6e597.diff
deleted file mode 100644
index 91c871a..0000000
--- a/utils/st-0.8.5/patches/st-blinking_cursor-20211116-2f6e597.diff
+++ /dev/null
@@ -1,153 +0,0 @@
-From a3cdd0753bf578cd4e6db7c6507481f3b5c38aea Mon Sep 17 00:00:00 2001
-From: Steve Ward <planet36@gmail.com>
-Date: Tue, 16 Nov 2021 14:15:06 -0500
-Subject: [PATCH] Allow blinking cursor
-
----
- config.def.h | 19 +++++++++++++------
- x.c | 47 +++++++++++++++++++++++++++++++++++------------
- 2 files changed, 48 insertions(+), 18 deletions(-)
-
-diff --git a/config.def.h b/config.def.h
-index 6f05dce..1a5fed0 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -133,13 +133,20 @@ static unsigned int defaultcs = 256;
- static unsigned int defaultrcs = 257;
-
- /*
-- * Default shape of cursor
-- * 2: Block ("█")
-- * 4: Underline ("_")
-- * 6: Bar ("|")
-- * 7: Snowman ("☃")
-+ * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
-+ * Default style of cursor
-+ * 0: blinking block
-+ * 1: blinking block (default)
-+ * 2: steady block ("█")
-+ * 3: blinking underline
-+ * 4: steady underline ("_")
-+ * 5: blinking bar
-+ * 6: steady bar ("|")
-+ * 7: blinking st cursor
-+ * 8: steady st cursor
- */
--static unsigned int cursorshape = 2;
-+static unsigned int cursorstyle = 1;
-+static Rune stcursor = 0x2603; /* snowman ("☃") */
-
- /*
- * Default columns and rows numbers
-diff --git a/x.c b/x.c
-index 89786b8..7d2447d 100644
---- a/x.c
-+++ b/x.c
-@@ -253,6 +253,7 @@ static char *opt_name = NULL;
- static char *opt_title = NULL;
-
- static int oldbutton = 3; /* button event on startup: 3 = release */
-+static int cursorblinks = 0;
-
- void
- clipcopy(const Arg *dummy)
-@@ -1529,29 +1530,44 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
- /* draw the new one */
- if (IS_SET(MODE_FOCUSED)) {
- switch (win.cursor) {
-- case 7: /* st extension */
-- g.u = 0x2603; /* snowman (U+2603) */
-+ default:
-+ case 0: /* blinking block */
-+ case 1: /* blinking block (default) */
-+ if (IS_SET(MODE_BLINK))
-+ break;
- /* FALLTHROUGH */
-- case 0: /* Blinking Block */
-- case 1: /* Blinking Block (Default) */
-- case 2: /* Steady Block */
-+ case 2: /* steady block */
- xdrawglyph(g, cx, cy);
- break;
-- case 3: /* Blinking Underline */
-- case 4: /* Steady Underline */
-+ case 3: /* blinking underline */
-+ if (IS_SET(MODE_BLINK))
-+ break;
-+ /* FALLTHROUGH */
-+ case 4: /* steady underline */
- XftDrawRect(xw.draw, &drawcol,
- borderpx + cx * win.cw,
- borderpx + (cy + 1) * win.ch - \
- cursorthickness,
- win.cw, cursorthickness);
- break;
-- case 5: /* Blinking bar */
-- case 6: /* Steady bar */
-+ case 5: /* blinking bar */
-+ if (IS_SET(MODE_BLINK))
-+ break;
-+ /* FALLTHROUGH */
-+ case 6: /* steady bar */
- XftDrawRect(xw.draw, &drawcol,
- borderpx + cx * win.cw,
- borderpx + cy * win.ch,
- cursorthickness, win.ch);
- break;
-+ case 7: /* blinking st cursor */
-+ if (IS_SET(MODE_BLINK))
-+ break;
-+ /* FALLTHROUGH */
-+ case 8: /* steady st cursor */
-+ g.u = stcursor;
-+ xdrawglyph(g, cx, cy);
-+ break;
- }
- } else {
- XftDrawRect(xw.draw, &drawcol,
-@@ -1708,9 +1724,12 @@ xsetmode(int set, unsigned int flags)
- int
- xsetcursor(int cursor)
- {
-- if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
-+ if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */
- return 1;
- win.cursor = cursor;
-+ cursorblinks = win.cursor == 0 || win.cursor == 1 ||
-+ win.cursor == 3 || win.cursor == 5 ||
-+ win.cursor == 7;
- return 0;
- }
-
-@@ -1954,6 +1973,10 @@ run(void)
- if (FD_ISSET(ttyfd, &rfd) || xev) {
- if (!drawing) {
- trigger = now;
-+ if (IS_SET(MODE_BLINK)) {
-+ win.mode ^= MODE_BLINK;
-+ }
-+ lastblink = now;
- drawing = 1;
- }
- timeout = (maxlatency - TIMEDIFF(now, trigger)) \
-@@ -1964,7 +1987,7 @@ run(void)
-
- /* idle detected or maxlatency exhausted -> draw */
- timeout = -1;
-- if (blinktimeout && tattrset(ATTR_BLINK)) {
-+ if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) {
- timeout = blinktimeout - TIMEDIFF(now, lastblink);
- if (timeout <= 0) {
- if (-timeout > blinktimeout) /* start visible */
-@@ -2000,7 +2023,7 @@ main(int argc, char *argv[])
- {
- xw.l = xw.t = 0;
- xw.isfixed = False;
-- xsetcursor(cursorshape);
-+ xsetcursor(cursorstyle);
-
- ARGBEGIN {
- case 'a':
---
-2.34.0
-
diff --git a/utils/st-0.8.5/patches/st-graphics.diff b/utils/st-0.8.5/patches/st-graphics.diff
deleted file mode 100644
index 1bc4d48..0000000
--- a/utils/st-0.8.5/patches/st-graphics.diff
+++ /dev/null
@@ -1,166 +0,0 @@
-# A patch taken from boards.4channel.org/g/thread/87102876
-# adds graphics to st
-diff --git a/st.c b/st.c
-index 6ba467d..efad5ec 100644
---- a/st.c
-+++ b/st.c
-@@ -752,10 +752,11 @@ stty(char **args)
- perror("Couldn't call stty");
- }
-
--int
-+TTYConn
- ttynew(const char *line, char *cmd, const char *out, char **args)
- {
- int m, s;
-+ int mypipe[2];
-
- if (out) {
- term.mode |= MODE_PRINT;
-@@ -766,6 +767,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
- out, strerror(errno));
- }
- }
-+ pipe(mypipe);
-
- if (line) {
- if ((cmdfd = open(line, O_RDWR)) < 0)
-@@ -773,7 +775,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
- line, strerror(errno));
- dup2(cmdfd, 0);
- stty(args);
-- return cmdfd;
-+ return (TTYConn){ cmdfd, cmdfd };
- }
-
- /* seems to work fine on linux, openbsd and freebsd */
-@@ -791,6 +793,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
- dup2(s, 0);
- dup2(s, 1);
- dup2(s, 2);
-+ dup2(mypipe[1], 3);
- if (ioctl(s, TIOCSCTTY, NULL) < 0)
- die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
- if (s > 2)
-@@ -807,11 +810,12 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
- die("pledge\n");
- #endif
- close(s);
-+ close(mypipe[1]);
- cmdfd = m;
- signal(SIGCHLD, sigchld);
- break;
- }
-- return cmdfd;
-+ return (TTYConn){ .cmdfd = cmdfd, .pipefd = mypipe[0] };
- }
-
- size_t
-diff --git a/st.h b/st.h
-index fd3b0d8..e5613ba 100644
---- a/st.h
-+++ b/st.h
-@@ -59,6 +59,10 @@ typedef unsigned short ushort;
-
- typedef uint_least32_t Rune;
-
-+typedef struct TTYConn {
-+ int cmdfd, pipefd;
-+} TTYConn;
-+
- #define Glyph Glyph_
- typedef struct {
- Rune u; /* character code */
-@@ -91,7 +95,7 @@ void tnew(int, int);
- void tresize(int, int);
- void tsetdirtattr(int);
- void ttyhangup(void);
--int ttynew(const char *, char *, const char *, char **);
-+TTYConn ttynew(const char *, char *, const char *, char **);
- size_t ttyread(void);
- void ttyresize(int, int);
- void ttywrite(const char *, size_t, int);
-diff --git a/x.c b/x.c
-index 2a3bd38..16caf2b 100644
---- a/x.c
-+++ b/x.c
-@@ -5,6 +5,7 @@
- #include <locale.h>
- #include <signal.h>
- #include <sys/select.h>
-+#include <fcntl.h>
- #include <time.h>
- #include <unistd.h>
- #include <libgen.h>
-@@ -1914,9 +1915,11 @@ run(void)
- XEvent ev;
- int w = win.w, h = win.h;
- fd_set rfd;
-- int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
-+ int xfd = XConnectionNumber(xw.dpy), ttyfd, pipefd, xev, drawing;
- struct timespec seltv, *tv, now, lastblink, trigger;
- double timeout;
-+ TTYConn conn;
-+ unsigned long color;
-
- /* Waiting for window mapping */
- do {
-@@ -1934,12 +1937,17 @@ run(void)
- }
- } while (ev.type != MapNotify);
-
-- ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
-+ conn = ttynew(opt_line, shell, opt_io, opt_cmd);
-+ ttyfd = conn.cmdfd;
-+ pipefd = conn.pipefd;
- cresize(w, h);
-
-+ fcntl(pipefd, F_SETFL, O_NONBLOCK);
-+ FILE *command = fdopen(pipefd, "r");
- for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
- FD_ZERO(&rfd);
- FD_SET(ttyfd, &rfd);
-+ FD_SET(pipefd, &rfd);
- FD_SET(xfd, &rfd);
-
- if (XPending(xw.dpy))
-@@ -1949,7 +1957,7 @@ run(void)
- seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec);
- tv = timeout >= 0 ? &seltv : NULL;
-
-- if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
-+ if (pselect(MAX(MAX(xfd, ttyfd), pipefd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
- if (errno == EINTR)
- continue;
- die("select failed: %s\n", strerror(errno));
-@@ -2006,6 +2014,30 @@ run(void)
- }
-
- draw();
-+ if(FD_ISSET(pipefd, &rfd)) {
-+ char header[128];
-+ int x, y;
-+ int w, h;
-+ int r, g, b;
-+
-+ xstartdraw();
-+ while(fscanf(command, "%s", header) != EOF) {
-+ printf("Command: %s\n", header);
-+ if(strcmp(header, "set-color") == 0) {
-+ fscanf(command, "%d %d %d", &r, &g, &b);
-+
-+ color = b + (g << 8) + (r << 16);
-+ }
-+
-+ if(strcmp(header, "fill-rectangle") == 0) {
-+ fscanf(command, "%d %d %d %d", &x, &y, &w, &h);
-+ XSetForeground(xw.dpy, dc.gc, color);
-+ XFillRectangle(xw.dpy, xw.buf, dc.gc, x, y, w, h);
-+ }
-+ }
-+ xfinishdraw();
-+ }
-+
- XFlush(xw.dpy);
- drawing = 0;
- }
diff --git a/utils/st-0.8.5/patches/st-hidecursor-0.8.3.diff b/utils/st-0.8.5/patches/st-hidecursor-0.8.3.diff
deleted file mode 100644
index 4895a66..0000000
--- a/utils/st-0.8.5/patches/st-hidecursor-0.8.3.diff
+++ /dev/null
@@ -1,88 +0,0 @@
-diff --git a/x.c b/x.c
-index e5f1737..7e759b0 100644
---- a/x.c
-+++ b/x.c
-@@ -103,6 +103,11 @@ typedef struct {
- Draw draw;
- Visual *vis;
- XSetWindowAttributes attrs;
-+ /* Here, we use the term *pointer* to differentiate the cursor
-+ * one sees when hovering the mouse over the terminal from, e.g.,
-+ * a green rectangle where text would be entered. */
-+ Cursor vpointer, bpointer; /* visible and hidden pointers */
-+ int pointerisvisible;
- int scr;
- int isfixed; /* is fixed geometry? */
- int l, t; /* left and top offset */
-@@ -698,6 +703,13 @@ brelease(XEvent *e)
- void
- bmotion(XEvent *e)
- {
-+ if (!xw.pointerisvisible) {
-+ XDefineCursor(xw.dpy, xw.win, xw.vpointer);
-+ xw.pointerisvisible = 1;
-+ if (!IS_SET(MODE_MOUSEMANY))
-+ xsetpointermotion(0);
-+ }
-+
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
- mousereport(e);
- return;
-@@ -1099,10 +1111,10 @@ void
- xinit(int cols, int rows)
- {
- XGCValues gcvalues;
-- Cursor cursor;
- Window parent;
- pid_t thispid = getpid();
- XColor xmousefg, xmousebg;
-+ Pixmap blankpm;
-
- if (!(xw.dpy = XOpenDisplay(NULL)))
- die("can't open display\n");
-@@ -1166,8 +1178,9 @@ xinit(int cols, int rows)
- }
-
- /* white cursor, black outline */
-- cursor = XCreateFontCursor(xw.dpy, mouseshape);
-- XDefineCursor(xw.dpy, xw.win, cursor);
-+ xw.pointerisvisible = 1;
-+ xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
-+ XDefineCursor(xw.dpy, xw.win, xw.vpointer);
-
- if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
- xmousefg.red = 0xffff;
-@@ -1181,7 +1194,10 @@ xinit(int cols, int rows)
- xmousebg.blue = 0x0000;
- }
-
-- XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
-+ XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
-+ blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
-+ xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
-+ &xmousefg, &xmousebg, 0, 0);
-
- xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
- xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
-@@ -1673,6 +1689,8 @@ unmap(XEvent *ev)
- void
- xsetpointermotion(int set)
- {
-+ if (!set && !xw.pointerisvisible)
-+ return;
- MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
- XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
- }
-@@ -1793,6 +1811,12 @@ kpress(XEvent *ev)
- Status status;
- Shortcut *bp;
-
-+ if (xw.pointerisvisible) {
-+ XDefineCursor(xw.dpy, xw.win, xw.bpointer);
-+ xsetpointermotion(1);
-+ xw.pointerisvisible = 0;
-+ }
-+
- if (IS_SET(MODE_KBDLOCK))
- return;
-
diff --git a/utils/st-0.8.5/patches/st-scrollback-ringbuffer-0.8.5.diff b/utils/st-0.8.5/patches/st-scrollback-ringbuffer-0.8.5.diff
deleted file mode 100644
index 7c060c5..0000000
--- a/utils/st-0.8.5/patches/st-scrollback-ringbuffer-0.8.5.diff
+++ /dev/null
@@ -1,730 +0,0 @@
-commit 0663bdf11a409961da5b1120741a69814da8ce65
-Author: Timo Röhling <timo@gaussglocke.de>
-Date: Tue Nov 23 19:45:33 2021 +0100
-
- Terminal scrollback with ring buffer
-
- This patch adds a ring buffer for scrollback to the terminal. The
- advantage of using a ring buffer is that the common case, scrolling with
- no static screen content, can be achieved very efficiently by
- incrementing and decrementing the starting line (modulo buffer size).
-
- The scrollback buffer is limited to HISTSIZE lines in order to bound
- memory usage. As the lines are allocated on demand, it is possible to
- implement unlimited scrollback with few changes. If the terminal is
- reset, the scroll back buffer is reset, too.
-
-diff --git a/config.def.h b/config.def.h
-index 91ab8ca..e3b469b 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -201,6 +201,8 @@ static Shortcut shortcuts[] = {
- { TERMMOD, XK_Y, selpaste, {.i = 0} },
- { ShiftMask, XK_Insert, selpaste, {.i = 0} },
- { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
-+ { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
-+ { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
- };
-
- /*
-diff --git a/st.c b/st.c
-index 51049ba..f9e24ba 100644
---- a/st.c
-+++ b/st.c
-@@ -43,6 +43,10 @@
- #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
- #define ISDELIM(u) (u && wcschr(worddelimiters, u))
-
-+#define TSCREEN term.screen[IS_SET(MODE_ALTSCREEN)]
-+#define TLINEOFFSET(y) (((y) + TSCREEN.cur - TSCREEN.off + TSCREEN.size) % TSCREEN.size)
-+#define TLINE(y) (TSCREEN.buffer[TLINEOFFSET(y)])
-+
- enum term_mode {
- MODE_WRAP = 1 << 0,
- MODE_INSERT = 1 << 1,
-@@ -109,12 +113,21 @@ typedef struct {
- int alt;
- } Selection;
-
-+/* Screen lines */
-+typedef struct {
-+ Line* buffer; /* ring buffer */
-+ int size; /* size of buffer */
-+ int cur; /* start of active screen */
-+ int off; /* scrollback line offset */
-+ TCursor sc; /* saved cursor */
-+} LineBuffer;
-+
- /* Internal representation of the screen */
- typedef struct {
- int row; /* nb row */
- int col; /* nb col */
-- Line *line; /* screen */
-- Line *alt; /* alternate screen */
-+ LineBuffer screen[2]; /* screen and alternate screen */
-+ int linelen; /* allocated line length */
- int *dirty; /* dirtyness of lines */
- TCursor c; /* cursor */
- int ocx; /* old cursor col */
-@@ -202,6 +215,8 @@ static void tdeftran(char);
- static void tstrsequence(uchar);
-
- static void drawregion(int, int, int, int);
-+static void clearline(Line, Glyph, int, int);
-+static Line ensureline(Line);
-
- static void selnormalize(void);
- static void selscroll(int, int);
-@@ -415,11 +430,12 @@ int
- tlinelen(int y)
- {
- int i = term.col;
-+ Line line = TLINE(y);
-
-- if (term.line[y][i - 1].mode & ATTR_WRAP)
-+ if (line[i - 1].mode & ATTR_WRAP)
- return i;
-
-- while (i > 0 && term.line[y][i - 1].u == ' ')
-+ while (i > 0 && line[i - 1].u == ' ')
- --i;
-
- return i;
-@@ -528,7 +544,7 @@ selsnap(int *x, int *y, int direction)
- * Snap around if the word wraps around at the end or
- * beginning of a line.
- */
-- prevgp = &term.line[*y][*x];
-+ prevgp = &TLINE(*y)[*x];
- prevdelim = ISDELIM(prevgp->u);
- for (;;) {
- newx = *x + direction;
-@@ -543,14 +559,14 @@ selsnap(int *x, int *y, int direction)
- yt = *y, xt = *x;
- else
- yt = newy, xt = newx;
-- if (!(term.line[yt][xt].mode & ATTR_WRAP))
-+ if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
- break;
- }
-
- if (newx >= tlinelen(newy))
- break;
-
-- gp = &term.line[newy][newx];
-+ gp = &TLINE(newy)[newx];
- delim = ISDELIM(gp->u);
- if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
- || (delim && gp->u != prevgp->u)))
-@@ -571,14 +587,14 @@ selsnap(int *x, int *y, int direction)
- *x = (direction < 0) ? 0 : term.col - 1;
- if (direction < 0) {
- for (; *y > 0; *y += direction) {
-- if (!(term.line[*y-1][term.col-1].mode
-+ if (!(TLINE(*y-1)[term.col-1].mode
- & ATTR_WRAP)) {
- break;
- }
- }
- } else if (direction > 0) {
- for (; *y < term.row-1; *y += direction) {
-- if (!(term.line[*y][term.col-1].mode
-+ if (!(TLINE(*y)[term.col-1].mode
- & ATTR_WRAP)) {
- break;
- }
-@@ -609,13 +625,13 @@ getsel(void)
- }
-
- if (sel.type == SEL_RECTANGULAR) {
-- gp = &term.line[y][sel.nb.x];
-+ gp = &TLINE(y)[sel.nb.x];
- lastx = sel.ne.x;
- } else {
-- gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
-+ gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
- lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
- }
-- last = &term.line[y][MIN(lastx, linelen-1)];
-+ last = &TLINE(y)[MIN(lastx, linelen-1)];
- while (last >= gp && last->u == ' ')
- --last;
-
-@@ -956,12 +972,15 @@ int
- tattrset(int attr)
- {
- int i, j;
-+ int y = TLINEOFFSET(0);
-
- for (i = 0; i < term.row-1; i++) {
-+ Line line = TSCREEN.buffer[y];
- for (j = 0; j < term.col-1; j++) {
-- if (term.line[i][j].mode & attr)
-+ if (line[j].mode & attr)
- return 1;
- }
-+ y = (y+1) % TSCREEN.size;
- }
-
- return 0;
-@@ -983,14 +1002,17 @@ void
- tsetdirtattr(int attr)
- {
- int i, j;
-+ int y = TLINEOFFSET(0);
-
- for (i = 0; i < term.row-1; i++) {
-+ Line line = TSCREEN.buffer[y];
- for (j = 0; j < term.col-1; j++) {
-- if (term.line[i][j].mode & attr) {
-+ if (line[j].mode & attr) {
- tsetdirt(i, i);
- break;
- }
- }
-+ y = (y+1) % TSCREEN.size;
- }
- }
-
-@@ -1003,27 +1025,19 @@ tfulldirt(void)
- void
- tcursor(int mode)
- {
-- static TCursor c[2];
-- int alt = IS_SET(MODE_ALTSCREEN);
--
- if (mode == CURSOR_SAVE) {
-- c[alt] = term.c;
-+ TSCREEN.sc = term.c;
- } else if (mode == CURSOR_LOAD) {
-- term.c = c[alt];
-- tmoveto(c[alt].x, c[alt].y);
-+ term.c = TSCREEN.sc;
-+ tmoveto(term.c.x, term.c.y);
- }
- }
-
- void
- treset(void)
- {
-- uint i;
--
-- term.c = (TCursor){{
-- .mode = ATTR_NULL,
-- .fg = defaultfg,
-- .bg = defaultbg
-- }, .x = 0, .y = 0, .state = CURSOR_DEFAULT};
-+ int i, j;
-+ Glyph g = (Glyph){ .fg = defaultfg, .bg = defaultbg};
-
- memset(term.tabs, 0, term.col * sizeof(*term.tabs));
- for (i = tabspaces; i < term.col; i += tabspaces)
-@@ -1035,17 +1049,37 @@ treset(void)
- term.charset = 0;
-
- for (i = 0; i < 2; i++) {
-- tmoveto(0, 0);
-- tcursor(CURSOR_SAVE);
-- tclearregion(0, 0, term.col-1, term.row-1);
-- tswapscreen();
-+ term.screen[i].sc = (TCursor){{
-+ .fg = defaultfg,
-+ .bg = defaultbg
-+ }};
-+ term.screen[i].cur = 0;
-+ term.screen[i].off = 0;
-+ for (j = 0; j < term.row; ++j) {
-+ if (term.col != term.linelen)
-+ term.screen[i].buffer[j] = xrealloc(term.screen[i].buffer[j], term.col * sizeof(Glyph));
-+ clearline(term.screen[i].buffer[j], g, 0, term.col);
-+ }
-+ for (j = term.row; j < term.screen[i].size; ++j) {
-+ free(term.screen[i].buffer[j]);
-+ term.screen[i].buffer[j] = NULL;
-+ }
- }
-+ tcursor(CURSOR_LOAD);
-+ term.linelen = term.col;
-+ tfulldirt();
- }
-
- void
- tnew(int col, int row)
- {
-- term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
-+ int i;
-+ term = (Term){};
-+ term.screen[0].buffer = xmalloc(HISTSIZE * sizeof(Line));
-+ term.screen[0].size = HISTSIZE;
-+ term.screen[1].buffer = NULL;
-+ for (i = 0; i < HISTSIZE; ++i) term.screen[0].buffer[i] = NULL;
-+
- tresize(col, row);
- treset();
- }
-@@ -1053,14 +1087,42 @@ tnew(int col, int row)
- void
- tswapscreen(void)
- {
-- Line *tmp = term.line;
--
-- term.line = term.alt;
-- term.alt = tmp;
- term.mode ^= MODE_ALTSCREEN;
- tfulldirt();
- }
-
-+void
-+kscrollup(const Arg *a)
-+{
-+ int n = a->i;
-+
-+ if (IS_SET(MODE_ALTSCREEN))
-+ return;
-+
-+ if (n < 0) n = (-n) * term.row;
-+ if (n > TSCREEN.size - term.row - TSCREEN.off) n = TSCREEN.size - term.row - TSCREEN.off;
-+ while (!TLINE(-n)) --n;
-+ TSCREEN.off += n;
-+ selscroll(0, n);
-+ tfulldirt();
-+}
-+
-+void
-+kscrolldown(const Arg *a)
-+{
-+
-+ int n = a->i;
-+
-+ if (IS_SET(MODE_ALTSCREEN))
-+ return;
-+
-+ if (n < 0) n = (-n) * term.row;
-+ if (n > TSCREEN.off) n = TSCREEN.off;
-+ TSCREEN.off -= n;
-+ selscroll(0, -n);
-+ tfulldirt();
-+}
-+
- void
- tscrolldown(int orig, int n)
- {
-@@ -1069,15 +1131,29 @@ tscrolldown(int orig, int n)
-
- LIMIT(n, 0, term.bot-orig+1);
-
-- tsetdirt(orig, term.bot-n);
-- tclearregion(0, term.bot-n+1, term.col-1, term.bot);
-+ /* Ensure that lines are allocated */
-+ for (i = -n; i < 0; i++) {
-+ TLINE(i) = ensureline(TLINE(i));
-+ }
-
-- for (i = term.bot; i >= orig+n; i--) {
-- temp = term.line[i];
-- term.line[i] = term.line[i-n];
-- term.line[i-n] = temp;
-+ /* Shift non-scrolling areas in ring buffer */
-+ for (i = term.bot+1; i < term.row; i++) {
-+ temp = TLINE(i);
-+ TLINE(i) = TLINE(i-n);
-+ TLINE(i-n) = temp;
-+ }
-+ for (i = 0; i < orig; i++) {
-+ temp = TLINE(i);
-+ TLINE(i) = TLINE(i-n);
-+ TLINE(i-n) = temp;
- }
-
-+ /* Scroll buffer */
-+ TSCREEN.cur = (TSCREEN.cur + TSCREEN.size - n) % TSCREEN.size;
-+ /* Clear lines that have entered the view */
-+ tclearregion(0, orig, term.linelen-1, orig+n-1);
-+ /* Redraw portion of the screen that has scrolled */
-+ tsetdirt(orig+n-1, term.bot);
- selscroll(orig, n);
- }
-
-@@ -1089,15 +1165,29 @@ tscrollup(int orig, int n)
-
- LIMIT(n, 0, term.bot-orig+1);
-
-- tclearregion(0, orig, term.col-1, orig+n-1);
-- tsetdirt(orig+n, term.bot);
-+ /* Ensure that lines are allocated */
-+ for (i = term.row; i < term.row + n; i++) {
-+ TLINE(i) = ensureline(TLINE(i));
-+ }
-
-- for (i = orig; i <= term.bot-n; i++) {
-- temp = term.line[i];
-- term.line[i] = term.line[i+n];
-- term.line[i+n] = temp;
-+ /* Shift non-scrolling areas in ring buffer */
-+ for (i = orig-1; i >= 0; i--) {
-+ temp = TLINE(i);
-+ TLINE(i) = TLINE(i+n);
-+ TLINE(i+n) = temp;
-+ }
-+ for (i = term.row-1; i >term.bot; i--) {
-+ temp = TLINE(i);
-+ TLINE(i) = TLINE(i+n);
-+ TLINE(i+n) = temp;
- }
-
-+ /* Scroll buffer */
-+ TSCREEN.cur = (TSCREEN.cur + n) % TSCREEN.size;
-+ /* Clear lines that have entered the view */
-+ tclearregion(0, term.bot-n+1, term.linelen-1, term.bot);
-+ /* Redraw portion of the screen that has scrolled */
-+ tsetdirt(orig, term.bot-n+1);
- selscroll(orig, -n);
- }
-
-@@ -1201,6 +1291,7 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
- "⎻", "─", "⎼", "⎽", "├", "┤", "┴", "┬", /* p - w */
- "│", "≤", "≥", "π", "≠", "£", "·", /* x - ~ */
- };
-+ Line line = TLINE(y);
-
- /*
- * The table is proudly stolen from rxvt.
-@@ -1209,25 +1300,25 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
- BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41])
- utf8decode(vt100_0[u - 0x41], &u, UTF_SIZ);
-
-- if (term.line[y][x].mode & ATTR_WIDE) {
-+ if (line[x].mode & ATTR_WIDE) {
- if (x+1 < term.col) {
-- term.line[y][x+1].u = ' ';
-- term.line[y][x+1].mode &= ~ATTR_WDUMMY;
-+ line[x+1].u = ' ';
-+ line[x+1].mode &= ~ATTR_WDUMMY;
- }
-- } else if (term.line[y][x].mode & ATTR_WDUMMY) {
-- term.line[y][x-1].u = ' ';
-- term.line[y][x-1].mode &= ~ATTR_WIDE;
-+ } else if (line[x].mode & ATTR_WDUMMY) {
-+ line[x-1].u = ' ';
-+ line[x-1].mode &= ~ATTR_WIDE;
- }
-
- term.dirty[y] = 1;
-- term.line[y][x] = *attr;
-- term.line[y][x].u = u;
-+ line[x] = *attr;
-+ line[x].u = u;
- }
-
- void
- tclearregion(int x1, int y1, int x2, int y2)
- {
-- int x, y, temp;
-+ int x, y, L, S, temp;
- Glyph *gp;
-
- if (x1 > x2)
-@@ -1235,15 +1326,16 @@ tclearregion(int x1, int y1, int x2, int y2)
- if (y1 > y2)
- temp = y1, y1 = y2, y2 = temp;
-
-- LIMIT(x1, 0, term.col-1);
-- LIMIT(x2, 0, term.col-1);
-+ LIMIT(x1, 0, term.linelen-1);
-+ LIMIT(x2, 0, term.linelen-1);
- LIMIT(y1, 0, term.row-1);
- LIMIT(y2, 0, term.row-1);
-
-+ L = TLINEOFFSET(y1);
- for (y = y1; y <= y2; y++) {
- term.dirty[y] = 1;
- for (x = x1; x <= x2; x++) {
-- gp = &term.line[y][x];
-+ gp = &TSCREEN.buffer[L][x];
- if (selected(x, y))
- selclear();
- gp->fg = term.c.attr.fg;
-@@ -1251,6 +1343,7 @@ tclearregion(int x1, int y1, int x2, int y2)
- gp->mode = 0;
- gp->u = ' ';
- }
-+ L = (L + 1) % TSCREEN.size;
- }
- }
-
-@@ -1265,7 +1358,7 @@ tdeletechar(int n)
- dst = term.c.x;
- src = term.c.x + n;
- size = term.col - src;
-- line = term.line[term.c.y];
-+ line = TLINE(term.c.y);
-
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
- tclearregion(term.col-n, term.c.y, term.col-1, term.c.y);
-@@ -1282,7 +1375,7 @@ tinsertblank(int n)
- dst = term.c.x + n;
- src = term.c.x;
- size = term.col - dst;
-- line = term.line[term.c.y];
-+ line = TLINE(term.c.y);
-
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
- tclearregion(src, term.c.y, dst - 1, term.c.y);
-@@ -2103,7 +2196,7 @@ tdumpline(int n)
- char buf[UTF_SIZ];
- const Glyph *bp, *end;
-
-- bp = &term.line[n][0];
-+ bp = &TLINE(n)[0];
- end = &bp[MIN(tlinelen(n), term.col) - 1];
- if (bp != end || bp->u != ' ') {
- for ( ; bp <= end; ++bp)
-@@ -2486,11 +2579,11 @@ check_control_code:
- if (selected(term.c.x, term.c.y))
- selclear();
-
-- gp = &term.line[term.c.y][term.c.x];
-+ gp = &TLINE(term.c.y)[term.c.x];
- if (IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
- gp->mode |= ATTR_WRAP;
- tnewline(1);
-- gp = &term.line[term.c.y][term.c.x];
-+ gp = &TLINE(term.c.y)[term.c.x];
- }
-
- if (IS_SET(MODE_INSERT) && term.c.x+width < term.col)
-@@ -2498,7 +2591,7 @@ check_control_code:
-
- if (term.c.x+width > term.col) {
- tnewline(1);
-- gp = &term.line[term.c.y][term.c.x];
-+ gp = &TLINE(term.c.y)[term.c.x];
- }
-
- tsetchar(u, &term.c.attr, term.c.x, term.c.y);
-@@ -2529,6 +2622,11 @@ twrite(const char *buf, int buflen, int show_ctrl)
- Rune u;
- int n;
-
-+ if (TSCREEN.off) {
-+ TSCREEN.off = 0;
-+ tfulldirt();
-+ }
-+
- for (n = 0; n < buflen; n += charsize) {
- if (IS_SET(MODE_UTF8)) {
- /* process a complete utf8 char */
-@@ -2555,56 +2653,85 @@ twrite(const char *buf, int buflen, int show_ctrl)
- }
-
- void
--tresize(int col, int row)
-+clearline(Line line, Glyph g, int x, int xend)
- {
- int i;
-+ g.mode = 0;
-+ g.u = ' ';
-+ for (i = x; i < xend; ++i) {
-+ line[i] = g;
-+ }
-+}
-+
-+Line
-+ensureline(Line line)
-+{
-+ if (!line) {
-+ line = xmalloc(term.linelen * sizeof(Glyph));
-+ }
-+ return line;
-+}
-+
-+void
-+tresize(int col, int row)
-+{
-+ int i, j;
- int minrow = MIN(row, term.row);
- int mincol = MIN(col, term.col);
-+ int linelen = MAX(col, term.linelen);
- int *bp;
-- TCursor c;
-
-- if (col < 1 || row < 1) {
-+ if (col < 1 || row < 1 || row > HISTSIZE) {
- fprintf(stderr,
- "tresize: error resizing to %dx%d\n", col, row);
- return;
- }
-
-- /*
-- * slide screen to keep cursor where we expect it -
-- * tscrollup would work here, but we can optimize to
-- * memmove because we're freeing the earlier lines
-- */
-- for (i = 0; i <= term.c.y - row; i++) {
-- free(term.line[i]);
-- free(term.alt[i]);
-+ /* Shift buffer to keep the cursor where we expect it */
-+ if (row <= term.c.y) {
-+ term.screen[0].cur = (term.screen[0].cur - row + term.c.y + 1) % term.screen[0].size;
-+ }
-+
-+ /* Resize and clear line buffers as needed */
-+ if (linelen > term.linelen) {
-+ for (i = 0; i < term.screen[0].size; ++i) {
-+ if (term.screen[0].buffer[i]) {
-+ term.screen[0].buffer[i] = xrealloc(term.screen[0].buffer[i], linelen * sizeof(Glyph));
-+ clearline(term.screen[0].buffer[i], term.c.attr, term.linelen, linelen);
-+ }
-+ }
-+ for (i = 0; i < minrow; ++i) {
-+ term.screen[1].buffer[i] = xrealloc(term.screen[1].buffer[i], linelen * sizeof(Glyph));
-+ clearline(term.screen[1].buffer[i], term.c.attr, term.linelen, linelen);
-+ }
- }
-- /* ensure that both src and dst are not NULL */
-- if (i > 0) {
-- memmove(term.line, term.line + i, row * sizeof(Line));
-- memmove(term.alt, term.alt + i, row * sizeof(Line));
-+ /* Allocate all visible lines for regular line buffer */
-+ for (j = term.screen[0].cur, i = 0; i < row; ++i, j = (j + 1) % term.screen[0].size)
-+ {
-+ if (!term.screen[0].buffer[j]) {
-+ term.screen[0].buffer[j] = xmalloc(linelen * sizeof(Glyph));
-+ }
-+ if (i >= term.row) {
-+ clearline(term.screen[0].buffer[j], term.c.attr, 0, linelen);
-+ }
- }
-- for (i += row; i < term.row; i++) {
-- free(term.line[i]);
-- free(term.alt[i]);
-+ /* Resize alt screen */
-+ term.screen[1].cur = 0;
-+ term.screen[1].size = row;
-+ for (i = row; i < term.row; ++i) {
-+ free(term.screen[1].buffer[i]);
-+ }
-+ term.screen[1].buffer = xrealloc(term.screen[1].buffer, row * sizeof(Line));
-+ for (i = term.row; i < row; ++i) {
-+ term.screen[1].buffer[i] = xmalloc(linelen * sizeof(Glyph));
-+ clearline(term.screen[1].buffer[i], term.c.attr, 0, linelen);
- }
-
- /* resize to new height */
-- term.line = xrealloc(term.line, row * sizeof(Line));
-- term.alt = xrealloc(term.alt, row * sizeof(Line));
- term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
- term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
-
-- /* resize each row to new width, zero-pad if needed */
-- for (i = 0; i < minrow; i++) {
-- term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
-- term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph));
-- }
--
-- /* allocate any new rows */
-- for (/* i = minrow */; i < row; i++) {
-- term.line[i] = xmalloc(col * sizeof(Glyph));
-- term.alt[i] = xmalloc(col * sizeof(Glyph));
-- }
-+ /* fix tabstops */
- if (col > term.col) {
- bp = term.tabs + term.col;
-
-@@ -2614,26 +2741,16 @@ tresize(int col, int row)
- for (bp += tabspaces; bp < term.tabs + col; bp += tabspaces)
- *bp = 1;
- }
-+
- /* update terminal size */
- term.col = col;
- term.row = row;
-+ term.linelen = linelen;
- /* reset scrolling region */
- tsetscroll(0, row-1);
- /* make use of the LIMIT in tmoveto */
- tmoveto(term.c.x, term.c.y);
-- /* Clearing both screens (it makes dirty all lines) */
-- c = term.c;
-- for (i = 0; i < 2; i++) {
-- if (mincol < col && 0 < minrow) {
-- tclearregion(mincol, 0, col - 1, minrow - 1);
-- }
-- if (0 < col && minrow < row) {
-- tclearregion(0, minrow, col - 1, row - 1);
-- }
-- tswapscreen();
-- tcursor(CURSOR_LOAD);
-- }
-- term.c = c;
-+ tfulldirt();
- }
-
- void
-@@ -2645,14 +2762,15 @@ resettitle(void)
- void
- drawregion(int x1, int y1, int x2, int y2)
- {
-- int y;
-+ int y, L;
-
-+ L = TLINEOFFSET(y1);
- for (y = y1; y < y2; y++) {
-- if (!term.dirty[y])
-- continue;
--
-- term.dirty[y] = 0;
-- xdrawline(term.line[y], x1, y, x2);
-+ if (term.dirty[y]) {
-+ term.dirty[y] = 0;
-+ xdrawline(TSCREEN.buffer[L], x1, y, x2);
-+ }
-+ L = (L + 1) % TSCREEN.size;
- }
- }
-
-@@ -2667,14 +2785,15 @@ draw(void)
- /* adjust cursor position */
- LIMIT(term.ocx, 0, term.col-1);
- LIMIT(term.ocy, 0, term.row-1);
-- if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY)
-+ if (TLINE(term.ocy)[term.ocx].mode & ATTR_WDUMMY)
- term.ocx--;
-- if (term.line[term.c.y][cx].mode & ATTR_WDUMMY)
-+ if (TLINE(term.c.y)[cx].mode & ATTR_WDUMMY)
- cx--;
-
- drawregion(0, 0, term.col, term.row);
-- xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
-- term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
-+ if (TSCREEN.off == 0)
-+ xdrawcursor(cx, term.c.y, TLINE(term.c.y)[cx],
-+ term.ocx, term.ocy, TLINE(term.ocy)[term.ocx]);
- term.ocx = cx;
- term.ocy = term.c.y;
- xfinishdraw();
-diff --git a/st.h b/st.h
-index 519b9bd..b48e810 100644
---- a/st.h
-+++ b/st.h
-@@ -19,6 +19,7 @@
-
- #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
- #define IS_TRUECOL(x) (1 << 24 & (x))
-+#define HISTSIZE 2000
-
- enum glyph_attribute {
- ATTR_NULL = 0,
-diff --git a/x.c b/x.c
-index 8a16faa..1bb5853 100644
---- a/x.c
-+++ b/x.c
-@@ -59,6 +59,8 @@ static void zoom(const Arg *);
- static void zoomabs(const Arg *);
- static void zoomreset(const Arg *);
- static void ttysend(const Arg *);
-+void kscrollup(const Arg *);
-+void kscrolldown(const Arg *);
-
- /* config.h for applying patches and the configuration. */
- #include "config.h"