Code

Check the ncurses version before using set_tabsize
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index c963977bbdcdb71338534f27440563107ac9d8b1..01b55d74b81994856e3da0cf779e52c97a36615e 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -114,6 +114,7 @@ static void report(const char *msg, ...);
 #define S_ISGITLINK(mode) (((mode) & S_IFMT) == 0160000)
 
 /* Some ASCII-shorthands fitted into the ncurses namespace. */
+#define KEY_CTL(x)     ((x) & 0x1f) /* KEY_CTL(A) == ^A == \1 */
 #define KEY_TAB                '\t'
 #define KEY_RETURN     '\r'
 #define KEY_ESC                27
@@ -209,7 +210,7 @@ string_ncopy_do(char *dst, size_t dstlen, const char *src, size_t srclen)
 #define string_add(dst, from, src) \
        string_ncopy_do(dst + (from), sizeof(dst) - (from), src, sizeof(src))
 
-static void
+static size_t
 string_expand(char *dst, size_t dstlen, const char *src, int tabsize)
 {
        size_t size, pos;
@@ -228,6 +229,7 @@ string_expand(char *dst, size_t dstlen, const char *src, int tabsize)
        }
 
        dst[size] = 0;
+       return pos;
 }
 
 static char *
@@ -683,15 +685,23 @@ argv_free(const char *argv[])
        argv[0] = NULL;
 }
 
+static size_t
+argv_size(const char **argv)
+{
+       int argc = 0;
+
+       while (argv && argv[argc])
+               argc++;
+
+       return argc;
+}
+
 DEFINE_ALLOCATOR(argv_realloc, const char *, SIZEOF_ARG)
 
 static bool
 argv_append(const char ***argv, const char *arg)
 {
-       int argc = 0;
-
-       while (*argv && (*argv)[argc])
-               argc++;
+       size_t argc = argv_size(*argv);
 
        if (!argv_realloc(argv, argc, 2))
                return FALSE;
@@ -1126,6 +1136,7 @@ io_run_load(const char **argv, const char *separators,
        REQ_(MOVE_LAST_LINE,    "Move cursor to last line"), \
        \
        REQ_GROUP("Scrolling") \
+       REQ_(SCROLL_FIRST_COL,  "Scroll to the first line columns"), \
        REQ_(SCROLL_LEFT,       "Scroll two columns left"), \
        REQ_(SCROLL_RIGHT,      "Scroll two columns right"), \
        REQ_(SCROLL_LINE_UP,    "Scroll one line up"), \
@@ -1143,7 +1154,6 @@ io_run_load(const char **argv, const char *separators,
        REQ_(OPTIONS,           "Open option menu"), \
        REQ_(TOGGLE_LINENO,     "Toggle line numbers"), \
        REQ_(TOGGLE_DATE,       "Toggle date display"), \
-       REQ_(TOGGLE_DATE_SHORT, "Toggle short (date-only) dates"), \
        REQ_(TOGGLE_AUTHOR,     "Toggle author display"), \
        REQ_(TOGGLE_REV_GRAPH,  "Toggle revision graph visualization"), \
        REQ_(TOGGLE_REFS,       "Toggle reference display (tags/branches)"), \
@@ -1213,6 +1223,7 @@ static bool opt_line_number               = FALSE;
 static bool opt_line_graphics          = TRUE;
 static bool opt_rev_graph              = FALSE;
 static bool opt_show_refs              = TRUE;
+static bool opt_untracked_dirs_content = TRUE;
 static int opt_num_interval            = 5;
 static double opt_hscroll              = 0.50;
 static double opt_scale_split_view     = 2.0 / 3.0;
@@ -1428,7 +1439,9 @@ static struct keybinding default_keybindings[] = {
        { KEY_TAB,      REQ_VIEW_NEXT },
        { KEY_RETURN,   REQ_ENTER },
        { KEY_UP,       REQ_PREVIOUS },
+       { KEY_CTL('P'), REQ_PREVIOUS },
        { KEY_DOWN,     REQ_NEXT },
+       { KEY_CTL('N'), REQ_NEXT },
        { 'R',          REQ_REFRESH },
        { KEY_F(5),     REQ_REFRESH },
        { 'O',          REQ_MAXIMIZE },
@@ -1439,16 +1452,21 @@ static struct keybinding default_keybindings[] = {
        { KEY_HOME,     REQ_MOVE_FIRST_LINE },
        { KEY_END,      REQ_MOVE_LAST_LINE },
        { KEY_NPAGE,    REQ_MOVE_PAGE_DOWN },
+       { KEY_CTL('D'), REQ_MOVE_PAGE_DOWN },
        { ' ',          REQ_MOVE_PAGE_DOWN },
        { KEY_PPAGE,    REQ_MOVE_PAGE_UP },
+       { KEY_CTL('U'), REQ_MOVE_PAGE_UP },
        { 'b',          REQ_MOVE_PAGE_UP },
        { '-',          REQ_MOVE_PAGE_UP },
 
        /* Scrolling */
+       { '|',          REQ_SCROLL_FIRST_COL },
        { KEY_LEFT,     REQ_SCROLL_LEFT },
        { KEY_RIGHT,    REQ_SCROLL_RIGHT },
        { KEY_IC,       REQ_SCROLL_LINE_UP },
+       { KEY_CTL('Y'), REQ_SCROLL_LINE_UP },
        { KEY_DC,       REQ_SCROLL_LINE_DOWN },
+       { KEY_CTL('E'), REQ_SCROLL_LINE_DOWN },
        { 'w',          REQ_SCROLL_PAGE_UP },
        { 's',          REQ_SCROLL_PAGE_DOWN },
 
@@ -1463,6 +1481,7 @@ static struct keybinding default_keybindings[] = {
        { 'z',          REQ_STOP_LOADING },
        { 'v',          REQ_SHOW_VERSION },
        { 'r',          REQ_SCREEN_REDRAW },
+       { KEY_CTL('L'), REQ_SCREEN_REDRAW },
        { 'o',          REQ_OPTIONS },
        { '.',          REQ_TOGGLE_LINENO },
        { 'D',          REQ_TOGGLE_DATE },
@@ -1611,16 +1630,17 @@ get_key_value(const char *name)
                if (!strcasecmp(key_table[i].name, name))
                        return key_table[i].value;
 
+       if (strlen(name) == 2 && name[0] == '^' && isprint(*name))
+               return (int)name[1] & 0x1f;
        if (strlen(name) == 1 && isprint(*name))
                return (int) *name;
-
        return ERR;
 }
 
 static const char *
 get_key_name(int key_value)
 {
-       static char key_char[] = "'X'";
+       static char key_char[] = "'X'\0";
        const char *seq = NULL;
        int key;
 
@@ -1628,10 +1648,17 @@ get_key_name(int key_value)
                if (key_table[key].value == key_value)
                        seq = key_table[key].name;
 
-       if (seq == NULL &&
-           key_value < 127 &&
-           isprint(key_value)) {
-               key_char[1] = (char) key_value;
+       if (seq == NULL && key_value < 0x7f) {
+               char *s = key_char + 1;
+
+               if (key_value >= 0x20) {
+                       *s++ = key_value;
+               } else {
+                       *s++ = '^';
+                       *s++ = 0x40 | (key_value & 0x1f);
+               }
+               *s++ = '\'';
+               *s++ = '\0';
                seq = key_char;
        }
 
@@ -1991,6 +2018,9 @@ option_set_command(int argc, const char *argv[])
        if (!strcmp(argv[0], "commit-encoding"))
                return parse_string(opt_encoding, argv[2], sizeof(opt_encoding));
 
+       if (!strcmp(argv[0], "status-untracked-dirs"))
+               return parse_bool(&opt_untracked_dirs_content, argv[2]);
+
        config_msg = "Unknown variable name";
        return ERR;
 }
@@ -2134,6 +2164,7 @@ load_options(void)
        const char *home = getenv("HOME");
        const char *tigrc_user = getenv("TIGRC_USER");
        const char *tigrc_system = getenv("TIGRC_SYSTEM");
+       const char *tig_diff_opts = getenv("TIG_DIFF_OPTS");
        char buf[SIZEOF_STR];
 
        if (!tigrc_system)
@@ -2151,6 +2182,17 @@ load_options(void)
         * that conflict with keybindings. */
        add_builtin_run_requests();
 
+       if (!opt_diff_args && tig_diff_opts && *tig_diff_opts) {
+               static const char *diff_opts[SIZEOF_ARG] = { NULL };
+               int argc = 0;
+
+               if (!string_format(buf, "%s", tig_diff_opts) ||
+                   !argv_from_string(diff_opts, &argc, buf))
+                       die("TIG_DIFF_OPTS contains too many arguments");
+               else if (!argv_copy(&opt_diff_args, diff_opts))
+                       die("Failed to format TIG_DIFF_OPTS arguments");
+       }
+
        return OK;
 }
 
@@ -2295,7 +2337,7 @@ static struct view views[] = {
        VIEW_(BLAME,  "blame",  &blame_ops,  TRUE,  ref_commit),
        VIEW_(BRANCH, "branch", &branch_ops, TRUE,  ref_head),
        VIEW_(HELP,   "help",   &help_ops,   FALSE, ""),
-       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, "stdin"),
+       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, ""),
        VIEW_(STATUS, "status", &status_ops, TRUE,  ""),
        VIEW_(STAGE,  "stage",  &stage_ops,  TRUE,  ""),
 };
@@ -2365,11 +2407,12 @@ draw_chars(struct view *view, enum line_type type, const char *string,
                }
 
                waddnstr(view->win, string, len);
-       }
-       if (trimmed && use_tilde) {
-               set_view_attr(view, LINE_DELIMITER);
-               waddch(view->win, '~');
-               col++;
+
+               if (trimmed && use_tilde) {
+                       set_view_attr(view, LINE_DELIMITER);
+                       waddch(view->win, '~');
+                       col++;
+               }
        }
 
        return col;
@@ -2396,7 +2439,15 @@ draw_space(struct view *view, enum line_type type, int max, int spaces)
 static bool
 draw_text(struct view *view, enum line_type type, const char *string, bool trim)
 {
-       view->col += draw_chars(view, type, string, view->width + view->yoffset - view->col, trim);
+       char text[SIZEOF_STR];
+
+       do {
+               size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
+
+               view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, trim);
+               string += pos;
+       } while (*string && view->width + view->yoffset > view->col);
+
        return view->width + view->yoffset <= view->col;
 }
 
@@ -2857,6 +2908,11 @@ scroll_view(struct view *view, enum request request)
        assert(view_is_displayed(view));
 
        switch (request) {
+       case REQ_SCROLL_FIRST_COL:
+               view->yoffset = 0;
+               redraw_view_from(view, 0);
+               report("");
+               return;
        case REQ_SCROLL_LEFT:
                if (view->yoffset == 0) {
                        report("Cannot scroll beyond the first column");
@@ -3168,7 +3224,7 @@ format_arg(const char *name)
 }
 
 static bool
-format_argv(const char ***dst_argv, const char *src_argv[], bool replace)
+format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool first)
 {
        char buf[SIZEOF_STR];
        int argc;
@@ -3179,17 +3235,18 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace)
                const char *arg = src_argv[argc];
                size_t bufpos = 0;
 
-               if (!strcmp(arg, "%(file-args)")) {
+               if (!strcmp(arg, "%(fileargs)")) {
                        if (!argv_append_array(dst_argv, opt_file_args))
                                break;
                        continue;
 
-               } else if (!strcmp(arg, "%(diff-args)")) {
+               } else if (!strcmp(arg, "%(diffargs)")) {
                        if (!argv_append_array(dst_argv, opt_diff_args))
                                break;
                        continue;
 
-               } else if (!strcmp(arg, "%(rev-args)")) {
+               } else if (!strcmp(arg, "%(revargs)") ||
+                          (first && !strcmp(arg, "%(commit)"))) {
                        if (!argv_append_array(dst_argv, opt_rev_args))
                                break;
                        continue;
@@ -3275,7 +3332,7 @@ static bool
 prepare_io(struct view *view, const char *dir, const char *argv[], bool replace)
 {
        view->dir = dir;
-       return format_argv(&view->argv, argv, replace);
+       return format_argv(&view->argv, argv, replace, !view->parent);
 }
 
 static bool
@@ -3612,7 +3669,7 @@ open_run_request(enum request request)
                return;
        }
 
-       if (format_argv(&argv, req->argv, TRUE))
+       if (format_argv(&argv, req->argv, TRUE, FALSE))
                open_external_viewer(argv, NULL);
        if (argv)
                argv_free(argv);
@@ -3651,6 +3708,7 @@ view_driver(struct view *view, enum request request)
                move_view(view, request);
                break;
 
+       case REQ_SCROLL_FIRST_COL:
        case REQ_SCROLL_LEFT:
        case REQ_SCROLL_RIGHT:
        case REQ_SCROLL_LINE_DOWN:
@@ -3679,6 +3737,13 @@ view_driver(struct view *view, enum request request)
                break;
 
        case REQ_VIEW_PAGER:
+               if (view == NULL) {
+                       if (!io_open(&VIEW(REQ_VIEW_PAGER)->io, ""))
+                               die("Failed to open stdin");
+                       open_view(view, request, OPEN_PREPARED);
+                       break;
+               }
+
                if (!VIEW(REQ_VIEW_PAGER)->pipe && !VIEW(REQ_VIEW_PAGER)->lines) {
                        report("No pager content, press %s to run command from prompt",
                               get_key(view->keymap, REQ_PROMPT));
@@ -3977,73 +4042,6 @@ parse_author_line(char *ident, const char **author, struct time *time)
        }
 }
 
-static bool
-open_commit_parent_menu(char buf[SIZEOF_STR], int *parents)
-{
-       char rev[SIZEOF_REV];
-       const char *revlist_argv[] = {
-               "git", "log", "--no-color", "-1", "--pretty=format:%s", rev, NULL
-       };
-       struct menu_item *items;
-       char text[SIZEOF_STR];
-       bool ok = TRUE;
-       int i;
-
-       items = calloc(*parents + 1, sizeof(*items));
-       if (!items)
-               return FALSE;
-
-       for (i = 0; i < *parents; i++) {
-               string_copy_rev(rev, &buf[SIZEOF_REV * i]);
-               if (!io_run_buf(revlist_argv, text, sizeof(text)) ||
-                   !(items[i].text = strdup(text))) {
-                       ok = FALSE;
-                       break;
-               }
-       }
-
-       if (ok) {
-               *parents = 0;
-               ok = prompt_menu("Select parent", items, parents);
-       }
-       for (i = 0; items[i].text; i++)
-               free((char *) items[i].text);
-       free(items);
-       return ok;
-}
-
-static bool
-select_commit_parent(const char *id, char rev[SIZEOF_REV], const char *path)
-{
-       char buf[SIZEOF_STR * 4];
-       const char *revlist_argv[] = {
-               "git", "log", "--no-color", "-1",
-                       "--pretty=format:%P", id, "--", path, NULL
-       };
-       int parents;
-
-       if (!io_run_buf(revlist_argv, buf, sizeof(buf)) ||
-           (parents = strlen(buf) / 40) < 0) {
-               report("Failed to get parent information");
-               return FALSE;
-
-       } else if (parents == 0) {
-               if (path)
-                       report("Path '%s' does not exist in the parent", path);
-               else
-                       report("The selected commit has no parents");
-               return FALSE;
-       }
-
-       if (parents == 1)
-               parents = 0;
-       else if (!open_commit_parent_menu(buf, &parents))
-               return FALSE;
-
-       string_copy_rev(rev, &buf[41 * parents]);
-       return TRUE;
-}
-
 /*
  * Pager backend
  */
@@ -4051,13 +4049,10 @@ select_commit_parent(const char *id, char rev[SIZEOF_REV], const char *path)
 static bool
 pager_draw(struct view *view, struct line *line, unsigned int lineno)
 {
-       char text[SIZEOF_STR];
-
        if (opt_line_number && draw_lineno(view, lineno))
                return TRUE;
 
-       string_expand(text, sizeof(text), line->data, opt_tab_size);
-       draw_text(view, line->type, text, TRUE);
+       draw_text(view, line->type, line->data, TRUE);
        return TRUE;
 }
 
@@ -4232,14 +4227,41 @@ static struct view_ops log_ops = {
 static const char *diff_argv[SIZEOF_ARG] = {
        "git", "show", "--pretty=fuller", "--no-color", "--root",
                "--patch-with-stat", "--find-copies-harder", "-C",
-               "%(diff-args)", "%(commit)", "--", "%(file-args)", NULL
+               "%(diffargs)", "%(commit)", "--", "%(fileargs)", NULL
 };
 
+static bool
+diff_read(struct view *view, char *data)
+{
+       if (!data) {
+               /* Fall back to retry if no diff will be shown. */
+               if (view->lines == 0 && opt_file_args) {
+                       int pos = argv_size(view->argv)
+                               - argv_size(opt_file_args) - 1;
+
+                       if (pos > 0 && !strcmp(view->argv[pos], "--")) {
+                               for (; view->argv[pos]; pos++) {
+                                       free((void *) view->argv[pos]);
+                                       view->argv[pos] = NULL;
+                               }
+
+                               if (view->pipe)
+                                       io_done(view->pipe);
+                               if (io_run(&view->io, IO_RD, view->dir, view->argv))
+                                       return FALSE;
+                       }
+               }
+               return TRUE;
+       }
+
+       return pager_read(view, data);
+}
+
 static struct view_ops diff_ops = {
        "line",
        diff_argv,
        NULL,
-       pager_read,
+       diff_read,
        pager_draw,
        pager_request,
        pager_grep,
@@ -4898,7 +4920,8 @@ struct blame_commit {
        const char *author;             /* Author of the commit. */
        struct time time;               /* Date from the author ident. */
        char filename[128];             /* Name of file. */
-       bool has_previous;              /* Was a "previous" line detected. */
+       char parent_id[SIZEOF_REV];     /* Parent/previous SHA1 ID. */
+       char parent_filename[128];      /* Parent/previous name of file. */
 };
 
 struct blame {
@@ -4911,6 +4934,7 @@ static bool
 blame_open(struct view *view)
 {
        char path[SIZEOF_STR];
+       size_t i;
 
        if (!view->prev && *opt_prefix) {
                string_copy(path, opt_file);
@@ -4928,6 +4952,24 @@ blame_open(struct view *view)
                        return FALSE;
        }
 
+       /* First pass: remove multiple references to the same commit. */
+       for (i = 0; i < view->lines; i++) {
+               struct blame *blame = view->line[i].data;
+
+               if (blame->commit && blame->commit->id[0])
+                       blame->commit->id[0] = 0;
+               else
+                       blame->commit = NULL;
+       }
+
+       /* Second pass: free existing references. */
+       for (i = 0; i < view->lines; i++) {
+               struct blame *blame = view->line[i].data;
+
+               if (blame->commit)
+                       free(blame->commit);
+       }
+
        setup_update(view, opt_file);
        string_format(view->ref, "%s ...", opt_file);
 
@@ -5097,7 +5139,11 @@ blame_read(struct view *view, char *line)
                string_ncopy(commit->title, line, strlen(line));
 
        } else if (match_blame_header("previous ", &line)) {
-               commit->has_previous = TRUE;
+               if (strlen(line) <= SIZEOF_REV)
+                       return FALSE;
+               string_copy_rev(commit->parent_id, line);
+               line += SIZEOF_REV;
+               string_ncopy(commit->parent_filename, line, strlen(line));
 
        } else if (match_blame_header("filename ", &line)) {
                string_ncopy(commit->filename, line, strlen(line));
@@ -5113,7 +5159,6 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno)
        struct blame *blame = line->data;
        struct time *time = NULL;
        const char *id = NULL, *author = NULL;
-       char text[SIZEOF_STR];
 
        if (blame->commit && *blame->commit->filename) {
                id = blame->commit->id;
@@ -5133,8 +5178,7 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno)
        if (draw_lineno(view, lineno))
                return TRUE;
 
-       string_expand(text, sizeof(text), blame->text, opt_tab_size);
-       draw_text(view, LINE_DEFAULT, text, TRUE);
+       draw_text(view, LINE_DEFAULT, blame->text, TRUE);
        return TRUE;
 }
 
@@ -5153,16 +5197,20 @@ check_blame_commit(struct blame *blame, bool check_null_id)
 static void
 setup_blame_parent_line(struct view *view, struct blame *blame)
 {
+       char from[SIZEOF_REF + SIZEOF_STR];
+       char to[SIZEOF_REF + SIZEOF_STR];
        const char *diff_tree_argv[] = {
-               "git", "diff-tree", "-U0", blame->commit->id,
-                       "--", blame->commit->filename, NULL
+               "git", "diff", "--no-textconv", "--no-extdiff", "--no-color",
+                       "-U0", from, to, "--", NULL
        };
        struct io io;
        int parent_lineno = -1;
        int blamed_lineno = -1;
        char *line;
 
-       if (!io_run(&io, IO_RD, NULL, diff_tree_argv))
+       if (!string_format(from, "%s:%s", opt_ref, opt_file) ||
+           !string_format(to, "%s:%s", blame->commit->id, blame->commit->filename) ||
+           !io_run(&io, IO_RD, NULL, diff_tree_argv))
                return;
 
        while ((line = io_get(&io, '\n', TRUE))) {
@@ -5204,10 +5252,13 @@ blame_request(struct view *view, enum request request, struct line *line)
                break;
 
        case REQ_PARENT:
-               if (check_blame_commit(blame, TRUE) &&
-                   select_commit_parent(blame->commit->id, opt_ref,
-                                        blame->commit->filename)) {
-                       string_copy(opt_file, blame->commit->filename);
+               if (!check_blame_commit(blame, TRUE))
+                       break;
+               if (!*blame->commit->parent_id) {
+                       report("The selected commit has no parents");
+               } else {
+                       string_copy_rev(opt_ref, blame->commit->parent_id);
+                       string_copy(opt_file, blame->commit->parent_filename);
                        setup_blame_parent_line(view, blame);
                        open_view(view, REQ_VIEW_BLAME, OPEN_REFRESH);
                }
@@ -5228,7 +5279,7 @@ blame_request(struct view *view, enum request request, struct line *line)
                                        "-C", "-M", "HEAD", "--", view->vid, NULL
                        };
 
-                       if (!blame->commit->has_previous) {
+                       if (!*blame->commit->parent_id) {
                                diff_index_argv[1] = "diff";
                                diff_index_argv[2] = "--no-color";
                                diff_index_argv[6] = "--";
@@ -5654,7 +5705,7 @@ static const char *status_diff_files_argv[] = {
 };
 
 static const char *status_list_other_argv[] = {
-       "git", "ls-files", "-z", "--others", "--exclude-standard", opt_prefix, NULL
+       "git", "ls-files", "-z", "--others", "--exclude-standard", opt_prefix, NULL, NULL,
 };
 
 static const char *status_list_no_head_argv[] = {
@@ -5759,6 +5810,9 @@ status_open(struct view *view)
                return FALSE;
        }
 
+       if (!opt_untracked_dirs_content)
+               status_list_other_argv[ARRAY_SIZE(status_list_other_argv) - 2] = "--directory";
+
        if (!status_run(view, status_diff_files_argv, 0, LINE_STAT_UNSTAGED) ||
            !status_run(view, status_list_other_argv, '?', LINE_STAT_UNTRACKED))
                return FALSE;
@@ -6727,8 +6781,8 @@ update_rev_graph(struct view *view, struct rev_graph *graph)
 
 static const char *main_argv[SIZEOF_ARG] = {
        "git", "log", "--no-color", "--pretty=raw", "--parents",
-               "--topo-order", "%(diff-args)", "%(rev-args)",
-               "--", "%(file-args)", NULL
+               "--topo-order", "%(diffargs)", "%(revargs)",
+               "--", "%(fileargs)", NULL
 };
 
 static bool
@@ -7057,7 +7111,11 @@ init_display(void)
        keypad(status_win, TRUE);
        wbkgdset(status_win, get_line_attr(LINE_STATUS));
 
+#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119)
+       set_tabsize(opt_tab_size);
+#else
        TABSIZE = opt_tab_size;
+#endif
 
        term = getenv("XTERM_VERSION") ? NULL : getenv("COLORTERM");
        if (term && !strcmp(term, "gnome-terminal")) {
@@ -7749,10 +7807,8 @@ parse_options(int argc, const char *argv[])
        const char **filter_argv = NULL;
        int i;
 
-       if (!isatty(STDIN_FILENO)) {
-               io_open(&VIEW(REQ_VIEW_PAGER)->io, "");
+       if (!isatty(STDIN_FILENO))
                return REQ_VIEW_PAGER;
-       }
 
        if (argc <= 1)
                return REQ_VIEW_MAIN;