summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-12 12:56:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-12 14:58:13 +0900
commit3825662d777ae406136fa7d720b60fe04c6eafd2 (patch)
tree48431b67750b698badc881c6fb314684578fb4a3 /ruby.c
parente6551d835febe00fce6c6a3b12c4e394d2a05bd6 (diff)
Set up environment variable for pager [Feature #16754]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3000
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ruby.c b/ruby.c
index 79cd595..03c1644 100644
--- a/ruby.c
+++ b/ruby.c
@@ -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)
{
@@ -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);