Skip to content

Commit

Permalink
Set up environment variable for pager [Feature #16754]
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Apr 12, 2020
1 parent e6551d8 commit 3825662
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ruby.c
Expand Up @@ -1585,6 +1585,12 @@ rb_f_chomp(int argc, VALUE *argv, VALUE _)
return str;
}

static void
setup_pager_env(void)
{
if (!getenv("LESS")) ruby_setenv("LESS", "-R"); // Output "raw" control characters.
}

static VALUE
process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
{
Expand Down Expand Up @@ -1627,12 +1633,14 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
close(fds[0]);
close(fds[1]);
if (pid > 0) {
setup_pager_env();
rb_f_exec(1, &pager);
kill(SIGTERM, pid);
rb_waitpid(pid, 0, 0);
}
}
#else
setup_pager_env();
VALUE port = rb_io_popen(pager, rb_str_new_lit("w"), Qnil, Qnil);
if (!NIL_P(port)) {
int oldout = dup(1);
Expand Down

0 comments on commit 3825662

Please sign in to comment.