summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authoryusufaktepe <yusuf@yusufaktepe.com>2019-05-08 04:05:57 +0300
committeryusufaktepe <yusuf@yusufaktepe.com>2019-05-08 04:05:57 +0300
commit3cd91894ec91a0de7aa71d62949ba3381e600afd (patch)
treeb20ec7e05d5970bdfc7c35bfbf9c89b7541b011b /st.c
parent35506b44adf9176062f2cc51bcfd54ac79246744 (diff)
Updated st to 0.8.2
Updated to latest git (20190414.f1546cf) & updated patches. Changes: . Upstream fixes. . Alpha: Opacity value is now typed in float (0-1). Also "-A" cmd option added as alternative opacity changing method. . Clipboard: middle click pastes from clipboard. . Organized shortcuts.
Diffstat (limited to 'st.c')
-rw-r--r--st.c81
1 files changed, 38 insertions, 43 deletions
diff --git a/st.c b/st.c
index 9fd04bd..bcb3444 100644
--- a/st.c
+++ b/st.c
@@ -35,6 +35,7 @@
#define ESC_ARG_SIZ 16
#define STR_BUF_SIZ ESC_BUF_SIZ
#define STR_ARG_SIZ ESC_ARG_SIZ
+#define HISTSIZE 2000
/* macros */
#define IS_SET(flag) ((term.mode & (flag)) != 0)
@@ -42,7 +43,10 @@
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
-#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
+#define ISDELIM(u) (u && wcschr(worddelimiters, u))
+#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
+ term.scr + HISTSIZE + 1) % HISTSIZE] : \
+ term.line[(y) - term.scr])
/* constants */
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
@@ -217,7 +221,6 @@ static void selsnap(int *, int *, int);
static size_t utf8decode(const char *, Rune *, size_t);
static Rune utf8decodebyte(char, size_t *);
static char utf8encodebyte(Rune, size_t);
-static char *utf8strchr(char *, Rune);
static size_t utf8validate(Rune *, size_t);
static char *base64dec(const char *);
@@ -259,10 +262,10 @@ xwrite(int fd, const char *s, size_t len)
void *
xmalloc(size_t len)
{
- void *p = malloc(len);
+ void *p;
- if (!p)
- die("Out of memory\n");
+ if (!(p = malloc(len)))
+ die("malloc: %s\n", strerror(errno));
return p;
}
@@ -271,7 +274,7 @@ void *
xrealloc(void *p, size_t len)
{
if ((p = realloc(p, len)) == NULL)
- die("Out of memory\n");
+ die("realloc: %s\n", strerror(errno));
return p;
}
@@ -280,7 +283,7 @@ char *
xstrdup(char *s)
{
if ((s = strdup(s)) == NULL)
- die("Out of memory\n");
+ die("strdup: %s\n", strerror(errno));
return s;
}
@@ -344,23 +347,6 @@ utf8encodebyte(Rune u, size_t i)
return utfbyte[i] | (u & ~utfmask[i]);
}
-char *
-utf8strchr(char *s, Rune u)
-{
- Rune r;
- size_t i, j, len;
-
- len = strlen(s);
- for (i = 0, j = 0; i < len; i += j) {
- if (!(j = utf8decode(&s[i], &r, len - i)))
- break;
- if (r == u)
- return &(s[i]);
- }
-
- return NULL;
-}
-
size_t
utf8validate(Rune *u, size_t i)
{
@@ -449,6 +435,7 @@ selstart(int col, int row, int snap)
selclear();
sel.mode = SEL_EMPTY;
sel.type = SEL_REGULAR;
+ sel.alt = IS_SET(MODE_ALTSCREEN);
sel.snap = snap;
sel.oe.x = sel.ob.x = col;
sel.oe.y = sel.ob.y = row;
@@ -477,13 +464,12 @@ selextend(int col, int row, int type, int done)
oldsey = sel.ne.y;
oldtype = sel.type;
- sel.alt = IS_SET(MODE_ALTSCREEN);
sel.oe.x = col;
sel.oe.y = row;
selnormalize();
sel.type = type;
- if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
+ if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY)
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
sel.mode = done ? SEL_IDLE : SEL_READY;
@@ -690,7 +676,7 @@ execsh(char *cmd, char **args)
errno = 0;
if ((pw = getpwuid(getuid())) == NULL) {
if (errno)
- die("getpwuid:%s\n", strerror(errno));
+ die("getpwuid: %s\n", strerror(errno));
else
die("who are you?\n");
}
@@ -733,7 +719,7 @@ sigchld(int a)
pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
- die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
+ die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
return;
@@ -786,7 +772,8 @@ ttynew(char *line, char *cmd, char *out, char **args)
if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0)
- die("open line failed: %s\n", strerror(errno));
+ die("open line '%s' failed: %s\n",
+ line, strerror(errno));
dup2(cmdfd, 0);
stty(args);
return cmdfd;
@@ -798,7 +785,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
switch (pid = fork()) {
case -1:
- die("fork failed\n");
+ die("fork failed: %s\n", strerror(errno));
break;
case 0:
close(iofd);
@@ -810,9 +797,17 @@ ttynew(char *line, char *cmd, char *out, char **args)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
+#ifdef __OpenBSD__
+ if (pledge("stdio getpw proc exec", NULL) == -1)
+ die("pledge\n");
+#endif
execsh(cmd, args);
break;
default:
+#ifdef __OpenBSD__
+ if (pledge("stdio rpath tty proc", NULL) == -1)
+ die("pledge\n");
+#endif
close(s);
cmdfd = m;
signal(SIGCHLD, sigchld);
@@ -831,7 +826,7 @@ ttyread(void)
/* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
- die("Couldn't read from shell: %s\n", strerror(errno));
+ die("couldn't read from shell: %s\n", strerror(errno));
buflen += ret;
written = twrite(buf, buflen, 0);
@@ -840,9 +835,6 @@ ttyread(void)
if (buflen > 0)
memmove(buf, buf + written, buflen);
- if (term.scr > 0 && term.scr < HISTSIZE-1)
- term.scr++;
-
return ret;
}
@@ -1096,7 +1088,6 @@ kscrollup(const Arg* a)
}
}
-
void
tscrolldown(int orig, int n, int copyhist)
{
@@ -1139,6 +1130,9 @@ tscrollup(int orig, int n, int copyhist)
term.line[orig] = temp;
}
+ if (term.scr > 0 && term.scr < HISTSIZE)
+ term.scr = MIN(term.scr + n, HISTSIZE-1);
+
tclearregion(0, orig, term.col-1, orig+n-1);
tsetdirt(orig+n, term.bot);
@@ -1627,6 +1621,7 @@ tsetmode(int priv, int set, int *args, int narg)
case 1015: /* urxvt mangled mouse mode; incompatible
and can be mistaken for other control
codes. */
+ break;
default:
fprintf(stderr,
"erresc: unknown private set/reset mode %d\n",
@@ -1898,7 +1893,7 @@ csireset(void)
void
strhandle(void)
{
- char *p = NULL;
+ char *p = NULL, *dec;
int j, narg, par;
term.esc &= ~(ESC_STR_END|ESC_STR);
@@ -1916,8 +1911,6 @@ strhandle(void)
return;
case 52:
if (narg > 2) {
- char *dec;
-
dec = base64dec(strescseq.args[2]);
if (dec) {
xsetsel(dec);
@@ -1935,7 +1928,10 @@ strhandle(void)
case 104: /* color reset, here p = NULL */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
if (xsetcolorname(j, p)) {
- fprintf(stderr, "erresc: invalid color %s\n", p);
+ if (par == 104 && narg <= 1)
+ return; /* color reset without parameter */
+ fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
+ j, p ? p : "(null)");
} else {
/*
* TODO if defaultbg color is changed, borders
@@ -2462,7 +2458,6 @@ tputc(Rune u)
goto check_control_code;
}
-
if (IS_SET(MODE_SIXEL)) {
/* TODO: implement sixel mode */
return;
@@ -2647,7 +2642,7 @@ tresize(int col, int row)
}
}
- /* resize each r w to new width, zero-pad if needed */
+ /* 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));
@@ -2725,12 +2720,12 @@ draw(void)
cx--;
drawregion(0, 0, term.col, term.row);
- if (term.scr == 0) {
+ if (term.scr == 0)
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
- }
term.ocx = cx, term.ocy = term.c.y;
xfinishdraw();
+ xximspot(term.ocx, term.ocy);
}
void