[前][次][番号順一覧][スレッド一覧]

ruby-changes:64409

From: Nobuyoshi <ko1@a...>
Date: Mon, 21 Dec 2020 18:13:32 +0900 (JST)
Subject: [ruby-changes:64409] b9d00f42e6 (master): Enable escape sequence on Windows10 console via pager too

https://git.ruby-lang.org/ruby.git/commit/?id=b9d00f42e6

From b9d00f42e63593e8c52dbe86cd4ebb7a120f768e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 21 Dec 2020 18:09:45 +0900
Subject: Enable escape sequence on Windows10 console via pager too


diff --git a/ruby.c b/ruby.c
index a19e08b..fa65c16 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1647,6 +1647,23 @@ setup_pager_env(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1647
     if (!getenv("LESS")) ruby_setenv("LESS", "-R"); // Output "raw" control characters.
 }
 
+#ifdef _WIN32
+static int
+tty_enabled(void)
+{
+    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
+    DWORD m;
+    if (!GetConsoleMode(h, &m)) return 0;
+# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#   define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x200
+# endif
+    if (!(m & ENABLE_VIRTUAL_TERMINAL_PROCESSING)) return 0;
+    return 1;
+}
+#elif !defined(HAVE_WORKING_FORK)
+# define tty_enabled() 0
+#endif
+
 static VALUE
 process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
 {
@@ -1707,10 +1724,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1724
                     int oldout = dup(1);
                     int olderr = dup(2);
                     int fd = RFILE(port)->fptr->fd;
+                    tty = tty_enabled();
                     dup2(fd, 1);
                     dup2(fd, 2);
-                    /* more.com doesn't support CSI sequence */
-                    usage(progname, 1, 0, columns);
+                    usage(progname, 1, tty, columns);
                     fflush(stdout);
                     dup2(oldout, 1);
                     dup2(olderr, 2);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]