Skip to content

Commit 66ff763

Browse files
committed
Merge branch 'lm/squelch-bg-progress'
Many long-running operations show progress eye-candy, even when they are later backgrounded. Hide the eye-candy when the process is sent to the background instead. * lm/squelch-bg-progress: compat/mingw: stubs for getpgid() and tcgetpgrp() progress: no progress in background
2 parents cedeffe + 9a9a41d commit 66ff763

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

compat/mingw.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static inline unsigned int alarm(unsigned int seconds)
9898
{ return 0; }
9999
static inline int fsync(int fd)
100100
{ return _commit(fd); }
101-
static inline pid_t getppid(void)
102-
{ return 1; }
103101
static inline void sync(void)
104102
{}
105103
static inline uid_t getuid(void)
@@ -121,6 +119,12 @@ static inline int sigaddset(sigset_t *set, int signum)
121119
#define SIG_UNBLOCK 0
122120
static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
123121
{ return 0; }
122+
static inline pid_t getppid(void)
123+
{ return 1; }
124+
static inline pid_t getpgid(pid_t pid)
125+
{ return pid == 0 ? getpid() : pid; }
126+
static inline pid_t tcgetpgrp(int fd)
127+
{ return getpid(); }
124128

125129
/*
126130
* simple adaptors

progress.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ static void clear_progress_signal(void)
7272
progress_update = 0;
7373
}
7474

75+
static int is_foreground_fd(int fd)
76+
{
77+
return getpgid(0) == tcgetpgrp(fd);
78+
}
79+
7580
static int display(struct progress *progress, unsigned n, const char *done)
7681
{
7782
const char *eol, *tp;
@@ -98,16 +103,21 @@ static int display(struct progress *progress, unsigned n, const char *done)
98103
unsigned percent = n * 100 / progress->total;
99104
if (percent != progress->last_percent || progress_update) {
100105
progress->last_percent = percent;
101-
fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
102-
progress->title, percent, n,
103-
progress->total, tp, eol);
104-
fflush(stderr);
106+
if (is_foreground_fd(fileno(stderr)) || done) {
107+
fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
108+
progress->title, percent, n,
109+
progress->total, tp, eol);
110+
fflush(stderr);
111+
}
105112
progress_update = 0;
106113
return 1;
107114
}
108115
} else if (progress_update) {
109-
fprintf(stderr, "%s: %u%s%s", progress->title, n, tp, eol);
110-
fflush(stderr);
116+
if (is_foreground_fd(fileno(stderr)) || done) {
117+
fprintf(stderr, "%s: %u%s%s",
118+
progress->title, n, tp, eol);
119+
fflush(stderr);
120+
}
111121
progress_update = 0;
112122
return 1;
113123
}

0 commit comments

Comments
 (0)