Skip to content

Commit

Permalink
Merge pull request #3272 from dscho/fix-duplicated-lines-when-moving-…
Browse files Browse the repository at this point in the history
…in-pager

Fix duplicated lines when scrolling in the pager
  • Loading branch information
dscho committed Jul 5, 2021
2 parents f1590a7 + fe2ee68 commit 8d1cc44
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pager.c
Expand Up @@ -11,6 +11,10 @@
static struct child_process pager_process = CHILD_PROCESS_INIT;
static const char *pager_program;

/* Is the value coming back from term_columns() just a guess? */
static int term_columns_guessed;


static void close_pager_fds(void)
{
/* signal EOF to pager */
Expand Down Expand Up @@ -114,7 +118,8 @@ void setup_pager(void)
{
char buf[64];
xsnprintf(buf, sizeof(buf), "%d", term_columns());
setenv("COLUMNS", buf, 0);
if (!term_columns_guessed)
setenv("COLUMNS", buf, 0);
}

setenv("GIT_PAGER_IN_USE", "true", 1);
Expand Down Expand Up @@ -158,15 +163,20 @@ int term_columns(void)
return term_columns_at_startup;

term_columns_at_startup = 80;
term_columns_guessed = 1;

col_string = getenv("COLUMNS");
if (col_string && (n_cols = atoi(col_string)) > 0)
if (col_string && (n_cols = atoi(col_string)) > 0) {
term_columns_at_startup = n_cols;
term_columns_guessed = 0;
}
#ifdef TIOCGWINSZ
else {
struct winsize ws;
if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col)
if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) {
term_columns_at_startup = ws.ws_col;
term_columns_guessed = 0;
}
}
#endif

Expand Down

0 comments on commit 8d1cc44

Please sign in to comment.