]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pager.c
Merge branch 'rs/pull-leakfix'
[thirdparty/git.git] / pager.c
diff --git a/pager.c b/pager.c
index 92b23e6cd1d44a26c86afeeb748ddc0aee3f9154..41446d4f0543df18fb2430188d886ed1975a55d9 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "alias.h"
 
 #ifndef DEFAULT_PAGER
 #define DEFAULT_PAGER "less"
@@ -99,6 +100,7 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
        argv_array_push(&pager_process->args, pager);
        pager_process->use_shell = 1;
        setup_pager_env(&pager_process->env_array);
+       pager_process->trace2_child_class = "pager";
 }
 
 void setup_pager(void)
@@ -109,10 +111,15 @@ void setup_pager(void)
                return;
 
        /*
-        * force computing the width of the terminal before we redirect
-        * the standard output to the pager.
+        * After we redirect standard output, we won't be able to use an ioctl
+        * to get the terminal size. Let's grab it now, and then set $COLUMNS
+        * to communicate it to any sub-processes.
         */
-       (void) term_columns();
+       {
+               char buf[64];
+               xsnprintf(buf, sizeof(buf), "%d", term_columns());
+               setenv("COLUMNS", buf, 0);
+       }
 
        setenv("GIT_PAGER_IN_USE", "true", 1);
 
@@ -170,6 +177,26 @@ int term_columns(void)
        return term_columns_at_startup;
 }
 
+/*
+ * Clear the entire line, leave cursor in first column.
+ */
+void term_clear_line(void)
+{
+       if (is_terminal_dumb())
+               /*
+                * Fall back to print a terminal width worth of space
+                * characters (hoping that the terminal is still as wide
+                * as it was upon the first call to term_columns()).
+                */
+               fprintf(stderr, "\r%*s\r", term_columns(), "");
+       else
+               /*
+                * On non-dumb terminals use an escape sequence to clear
+                * the whole line, no matter how wide the terminal.
+                */
+               fputs("\r\033[K", stderr);
+}
+
 /*
  * How many columns do we need to show this number in decimal?
  */