aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cache.h1
-rw-r--r--editor.c6
-rw-r--r--pager.c20
3 files changed, 24 insertions, 3 deletions
diff --git a/cache.h b/cache.h
index b4bb2e2c11..5b2cd32bad 100644
--- a/cache.h
+++ b/cache.h
@@ -1759,6 +1759,7 @@ void setup_pager(void);
int pager_in_use(void);
extern int pager_use_color;
int term_columns(void);
+void term_clear_line(void);
int decimal_width(uintmax_t);
int check_pager_config(const char *cmd);
void prepare_pager_args(struct child_process *, const char *pager);
diff --git a/editor.c b/editor.c
index 71547674ab..f079abbf11 100644
--- a/editor.c
+++ b/editor.c
@@ -96,10 +96,10 @@ static int launch_specified_editor(const char *editor, const char *path,
if (print_waiting_for_editor && !is_terminal_dumb())
/*
- * Go back to the beginning and erase the entire line to
- * avoid wasting the vertical space.
+ * Erase the entire line to avoid wasting the
+ * vertical space.
*/
- fputs("\r\033[K", stderr);
+ term_clear_line();
}
if (!buffer)
diff --git a/pager.c b/pager.c
index 4168460ae9..41446d4f05 100644
--- a/pager.c
+++ b/pager.c
@@ -178,6 +178,26 @@ int term_columns(void)
}
/*
+ * 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?
*/
int decimal_width(uintmax_t number)