JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
remove debugging printf
[st.git] / st.c
diff --git a/st.c b/st.c
index d43c30c..d0a607b 100644 (file)
--- a/st.c
+++ b/st.c
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
-#include <X11/Xlib.h>
 #include <X11/Xatom.h>
-#include <X11/keysym.h>
+#include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <X11/keysym.h>
 
 #if   defined(__linux)
  #include <pty.h>
@@ -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;
 
@@ -547,15 +548,12 @@ void
 execsh(void) {
        char **args;
        char *envshell = getenv("SHELL");
-       DEFAULT(envshell, "sh");
 
-       if(opt_cmd)
-               args = (char*[]){"sh", "-c", opt_cmd, NULL};
-       else
-               args = (char*[]){envshell, "-i", NULL};
-       
+       DEFAULT(envshell, "sh");
        putenv("TERM="TNAME);
+       args = opt_cmd ? opt_cmd : (char*[]){envshell, "-i", NULL};
        execvp(args[0], args);
+       exit(EXIT_FAILURE);
 }
 
 void 
@@ -937,7 +935,7 @@ csihandle(void) {
        switch(escseq.mode) {
        default:
        unknown:
-               printf("erresc: unknown csi ");
+               fprintf(stderr, "erresc: unknown csi ");
                csidump();
                /* die(""); */
                break;
@@ -1209,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 {
@@ -1506,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");
@@ -1553,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");
@@ -1788,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;
                }
 }
@@ -1855,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);