309 lines
6.1 KiB
C
309 lines
6.1 KiB
C
#include "git-compat-util.h"
|
|
#include "config.h"
|
|
#include "editor.h"
|
|
#include "pager.h"
|
|
#include "run-command.h"
|
|
#include "sigchain.h"
|
|
#include "alias.h"
|
|
|
|
int pager_use_color = 1;
|
|
|
|
#ifndef DEFAULT_PAGER
|
|
#define DEFAULT_PAGER "less"
|
|
#endif
|
|
|
|
static struct child_process pager_process;
|
|
static char *pager_program;
|
|
static int old_fd1 = -1, old_fd2 = -1;
|
|
|
|
/* 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 */
|
|
close(1);
|
|
if (old_fd2 != -1)
|
|
close(2);
|
|
}
|
|
|
|
static void finish_pager(void)
|
|
{
|
|
fflush(stdout);
|
|
fflush(stderr);
|
|
close_pager_fds();
|
|
finish_command(&pager_process);
|
|
}
|
|
|
|
static void wait_for_pager_atexit(void)
|
|
{
|
|
if (old_fd1 == -1)
|
|
return;
|
|
|
|
finish_pager();
|
|
}
|
|
|
|
void wait_for_pager(void)
|
|
{
|
|
if (old_fd1 == -1)
|
|
return;
|
|
|
|
finish_pager();
|
|
sigchain_pop_common();
|
|
unsetenv("GIT_PAGER_IN_USE");
|
|
dup2(old_fd1, 1);
|
|
close(old_fd1);
|
|
old_fd1 = -1;
|
|
if (old_fd2 != -1) {
|
|
dup2(old_fd2, 2);
|
|
close(old_fd2);
|
|
old_fd2 = -1;
|
|
}
|
|
}
|
|
|
|
static void wait_for_pager_signal(int signo)
|
|
{
|
|
if (old_fd1 == -1)
|
|
return;
|
|
|
|
close_pager_fds();
|
|
finish_command_in_signal(&pager_process);
|
|
sigchain_pop(signo);
|
|
raise(signo);
|
|
|