X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=561d5b05c00c1900215e31e16250eca533e1c116;hb=a047431d34aa77ac7a8fab08151fb569bbe2148e;hp=3829e73836202e4d82699585c96a0fde0d5cd6c1;hpb=af75c433e56e74d2ad7a315d504a9303ea532f18;p=st.git diff --git a/st.c b/st.c index 3829e73..561d5b0 100644 --- a/st.c +++ b/st.c @@ -16,10 +16,11 @@ #include #include #include -#include #include -#include +#include #include +#include +#include #if defined(__linux) #include @@ -247,7 +248,7 @@ static CSIEscape escseq; static int cmdfd; static pid_t pid; static Selection sel; -static char *opt_cmd = NULL; +static char **opt_cmd = NULL; static char *opt_title = NULL; static char *opt_class = NULL; @@ -419,8 +420,8 @@ selcopy(void) { memcpy(ptr, term.line[y][x].c, sl); ptr += sl; } - if(ls) - *ptr = '\n', ptr++; + if(ls && y < sel.e.y) + *ptr++ = '\n'; } *ptr = 0; } @@ -545,13 +546,14 @@ die(const char *errstr, ...) { void execsh(void) { - char *args[] = {getenv("SHELL"), "-i", NULL}; - if(opt_cmd) - args[0] = opt_cmd, args[1] = NULL; - else - DEFAULT(args[0], SHELL); + char **args; + char *envshell = getenv("SHELL"); + + DEFAULT(envshell, "sh"); putenv("TERM="TNAME); + args = opt_cmd ? opt_cmd : (char*[]){envshell, "-i", NULL}; execvp(args[0], args); + exit(EXIT_FAILURE); } void @@ -630,7 +632,7 @@ ttyread(void) { } /* keep any uncomplete utf8 char for the next call */ - memcpy(buf, ptr, buflen); + memmove(buf, ptr, buflen); } void @@ -933,7 +935,7 @@ csihandle(void) { switch(escseq.mode) { default: unknown: - printf("erresc: unknown csi "); + fprintf(stderr, "erresc: unknown csi "); csidump(); /* die(""); */ break; @@ -1205,7 +1207,7 @@ tputc(char *c) { term.c.attr.mode &= ~ATTR_GFX; break; default: - printf("esc unhandled charset: ESC ( %c\n", ascii); + fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii); } term.esc = 0; } else { @@ -1502,6 +1504,7 @@ initfonts(char *fontstr, char *bfontstr) void xinit(void) { XSetWindowAttributes attrs; + Cursor cursor; if(!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); @@ -1549,6 +1552,13 @@ xinit(void) { /* gc */ dc.gc = XCreateGC(xw.dpy, xw.win, 0, NULL); + /* white cursor, black outline */ + cursor = XCreateFontCursor(xw.dpy, XC_xterm); + XDefineCursor(xw.dpy, xw.win, cursor); + XRecolorCursor(xw.dpy, cursor, + &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, + &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); + XMapWindow(xw.dpy, xw.win); xhints(); XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); @@ -1784,8 +1794,7 @@ kpress(XEvent *ev) { if(meta && len == 1) ttywrite("\033", 1); ttywrite(buf, len); - } else /* 4. nothing to send */ - fprintf(stderr, "errkey: %d\n", (int)ksym); + } break; } } @@ -1851,12 +1860,15 @@ main(int argc, char *argv[]) { if(++i < argc) opt_class = argv[i]; break; case 'e': - if(++i < argc) opt_cmd = argv[i]; + if(++i < argc) opt_cmd = &argv[i]; break; case 'v': default: die(USAGE); } + /* -e eats every remaining arguments */ + if(opt_cmd) + break; } setlocale(LC_CTYPE, ""); tnew(80, 24);