Silence stderr for all view commands
[tig] / tig.c
diff --git a/tig.c b/tig.c
index cf65447..b2e1a36 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -12,7 +12,7 @@
  */
 
 #ifndef        VERSION
-#define VERSION        "tig-0.3"
+#define VERSION        "tig-0.4.git"
 #endif
 
 #ifndef DEBUG
@@ -74,13 +74,13 @@ static size_t utf8_length(const char *string, size_t max_width, int *coloffset,
        "git ls-remote . 2>/dev/null"
 
 #define TIG_DIFF_CMD \
-       "git show --patch-with-stat --find-copies-harder -B -C %s"
+       "git show --patch-with-stat --find-copies-harder -B -C %s 2>/dev/null"
 
 #define TIG_LOG_CMD    \
-       "git log --cc --stat -n100 %s"
+       "git log --cc --stat -n100 %s 2>/dev/null"
 
 #define TIG_MAIN_CMD \
-       "git log --topo-order --stat --pretty=raw %s"
+       "git log --topo-order --pretty=raw %s 2>/dev/null"
 
 /* XXX: Needs to be defined to the empty string. */
 #define TIG_HELP_CMD   ""
@@ -770,6 +770,7 @@ static struct key key_table[] = {
        { "Down",       KEY_DOWN },
        { "Insert",     KEY_IC },
        { "Delete",     KEY_DC },
+       { "Hash",       '#' },
        { "Home",       KEY_HOME },
        { "End",        KEY_END },
        { "PageUp",     KEY_PPAGE },
@@ -946,8 +947,22 @@ option_set_command(int argc, char *argv[])
        }
 
        if (!strcmp(argv[0], "commit-encoding")) {
-               string_copy(opt_encoding, argv[2]);
-               return OK;
+               char *arg = argv[2];
+               int delimiter = *arg;
+               int i;
+
+               switch (delimiter) {
+               case '"':
+               case '\'':
+                       for (arg++, i = 0; arg[i]; i++)
+                               if (arg[i] == delimiter) {
+                                       arg[i] = 0;
+                                       break;
+                               }
+               default:
+                       string_copy(opt_encoding, arg);
+                       return OK;
+               }
        }
 
        config_msg = "Unknown variable name";
@@ -1032,7 +1047,7 @@ read_option(char *opt, int optlen, char *value, int valuelen)
 
        /* Check for comment markers, since read_properties() will
         * only ensure opt and value are split at first " \t". */
-       optlen = strcspn(opt, "#;");
+       optlen = strcspn(opt, "#");
        if (optlen == 0)
                return OK;
 
@@ -1042,7 +1057,7 @@ read_option(char *opt, int optlen, char *value, int valuelen)
 
        }  else {
                /* Look for comment endings in the value. */
-               int len = strcspn(value, "#;");
+               int len = strcspn(value, "#");
 
                if (len < valuelen) {
                        valuelen = len;
@@ -2271,10 +2286,22 @@ main_read(struct view *view, char *line)
                        break;
 
                if (end) {
+                       char *email = end + 1;
+
                        for (; end > ident && isspace(end[-1]); end--) ;
+
+                       if (end == ident && *email) {
+                               ident = email;
+                               end = strchr(ident, '>');
+                               for (; end > ident && isspace(end[-1]); end--) ;
+                       }
                        *end = 0;
                }
 
+               /* End is NULL or ident meaning there's no author. */
+               if (end <= ident)
+                       ident = "Unknown";
+
                string_copy(commit->author, ident);
 
                /* Parse epoch and timezone */
@@ -2568,6 +2595,8 @@ init_display(void)
                /* Leave stdin and stdout alone when acting as a pager. */
                FILE *io = fopen("/dev/tty", "r+");
 
+               if (!io)
+                       die("Failed to open /dev/tty");
                cursed = !!newterm(NULL, io, io);
        }
 
@@ -2592,6 +2621,68 @@ init_display(void)
        wbkgdset(status_win, get_line_attr(LINE_STATUS));
 }
 
+static int
+read_prompt(void)
+{
+       enum { READING, STOP, CANCEL } status = READING;
+       char buf[sizeof(opt_cmd) - STRING_SIZE("git \0")];
+       int pos = 0;
+
+       while (status == READING) {
+               struct view *view;
+               int i, key;
+
+               foreach_view (view, i)
+                       update_view(view);
+
+               report(":%.*s", pos, buf);
+               /* Refresh, accept single keystroke of input */
+               key = wgetch(status_win);
+               switch (key) {
+               case KEY_RETURN:
+               case KEY_ENTER:
+               case '\n':
+                       status = pos ? STOP : CANCEL;
+                       break;
+
+               case KEY_BACKSPACE:
+                       if (pos > 0)
+                               pos--;
+                       else
+                               status = CANCEL;
+                       break;
+
+               case KEY_ESC:
+                       status = CANCEL;
+                       break;
+
+               case ERR:
+                       break;
+
+               default:
+                       if (pos >= sizeof(buf)) {
+                               report("Input string too long");
+                               return ERR;
+                       }
+
+                       if (isprint(key))
+                               buf[pos++] = (char) key;
+               }
+       }
+
+       if (status == CANCEL) {
+               /* Clear the status window */
+               report("");
+               return ERR;
+       }
+
+       buf[pos++] = 0;
+       if (!string_format(opt_cmd, "git %s", buf))
+               return ERR;
+       opt_request = REQ_VIEW_PAGER;
+
+       return OK;
+}
 
 /*
  * Repository references
@@ -2841,23 +2932,8 @@ main(int argc, char *argv[])
                 * status_win restricted. */
                switch (request) {
                case REQ_PROMPT:
-                       report(":");
-                       /* Temporarily switch to line-oriented and echoed
-                        * input. */
-                       nocbreak();
-                       echo();
-
-                       if (wgetnstr(status_win, opt_cmd + 4, sizeof(opt_cmd) - 4) == OK) {
-                               memcpy(opt_cmd, "git ", 4);
-                               opt_request = REQ_VIEW_PAGER;
-                       } else {
-                               report("Prompt interrupted by loading view, "
-                                      "press 'z' to stop loading views");
+                       if (read_prompt() == ERR)
                                request = REQ_SCREEN_UPDATE;
-                       }
-
-                       noecho();
-                       cbreak();
                        break;
 
                case REQ_SCREEN_RESIZE: