Skip to content

Commit a64f213

Browse files
larsxschneidergitster
authored andcommitted
refactor "dumb" terminal determination
Move the code to detect "dumb" terminals into a single location. This avoids duplicating the terminal detection code yet again in a subsequent commit. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a1f5c3 commit a64f213

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ extern const char *ident_default_name(void);
14381438
extern const char *ident_default_email(void);
14391439
extern const char *git_editor(void);
14401440
extern const char *git_pager(int stdout_is_tty);
1441+
extern int is_terminal_dumb(void);
14411442
extern int git_ident_config(const char *, const char *, void *);
14421443
extern void reset_ident_date(void);
14431444

color.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ static int check_auto_color(void)
329329
if (color_stdout_is_tty < 0)
330330
color_stdout_is_tty = isatty(1);
331331
if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
332-
char *term = getenv("TERM");
333-
if (term && strcmp(term, "dumb"))
332+
if (!is_terminal_dumb())
334333
return 1;
335334
}
336335
return 0;

editor.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
#define DEFAULT_EDITOR "vi"
88
#endif
99

10+
int is_terminal_dumb(void)
11+
{
12+
const char *terminal = getenv("TERM");
13+
return !terminal || !strcmp(terminal, "dumb");
14+
}
15+
1016
const char *git_editor(void)
1117
{
1218
const char *editor = getenv("GIT_EDITOR");
13-
const char *terminal = getenv("TERM");
14-
int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
19+
int terminal_is_dumb = is_terminal_dumb();
1520

1621
if (!editor && editor_program)
1722
editor = editor_program;

sideband.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020

2121
int recv_sideband(const char *me, int in_stream, int out)
2222
{
23-
const char *term, *suffix;
23+
const char *suffix;
2424
char buf[LARGE_PACKET_MAX + 1];
2525
struct strbuf outbuf = STRBUF_INIT;
2626
int retval = 0;
2727

28-
term = getenv("TERM");
29-
if (isatty(2) && term && strcmp(term, "dumb"))
28+
if (isatty(2) && !is_terminal_dumb())
3029
suffix = ANSI_SUFFIX;
3130
else
3231
suffix = DUMB_SUFFIX;

0 commit comments

Comments
 (0)