From: lars.schneider@autodesk.com
To: git@vger.kernel.org
Cc: gitster@pobox.com, sbeller@google.com, sunshine@sunshineco.com,
kaartic.sivaraam@gmail.com, sandals@crustytoothpaste.net,
peff@peff.net, Lars Schneider <larsxschneider@gmail.com>
Subject: [PATCH v5 1/2] refactor "dumb" terminal determination
Date: Thu, 7 Dec 2017 16:16:40 +0100 [thread overview]
Message-ID: <20171207151641.75065-2-lars.schneider@autodesk.com> (raw)
In-Reply-To: <20171207151641.75065-1-lars.schneider@autodesk.com>
From: Lars Schneider <larsxschneider@gmail.com>
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 <larsxschneider@gmail.com>
---
cache.h | 1 +
color.c | 3 +--
editor.c | 9 +++++++--
sideband.c | 5 ++---
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/cache.h b/cache.h
index 89f5d24579..3842fc097c 100644
--- a/cache.h
+++ b/cache.h
@@ -1469,6 +1469,7 @@ extern const char *ident_default_name(void);
extern const char *ident_default_email(void);
extern const char *git_editor(void);
extern const char *git_pager(int stdout_is_tty);
+extern int is_terminal_dumb(void);
extern int git_ident_config(const char *, const char *, void *);
extern void reset_ident_date(void);
diff --git a/color.c b/color.c
index 9a9261ac16..d48dd947c9 100644
--- a/color.c
+++ b/color.c
@@ -329,8 +329,7 @@ static int check_auto_color(void)
if (color_stdout_is_tty < 0)
color_stdout_is_tty = isatty(1);
if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
- char *term = getenv("TERM");
- if (term && strcmp(term, "dumb"))
+ if (!is_terminal_dumb())
return 1;
}
return 0;
diff --git a/editor.c b/editor.c
index 7519edecdc..c65ea698eb 100644
--- a/editor.c
+++ b/editor.c
@@ -7,11 +7,16 @@
#define DEFAULT_EDITOR "vi"
#endif
+int is_terminal_dumb(void)
+{
+ const char *terminal = getenv("TERM");
+ return !terminal || !strcmp(terminal, "dumb");
+}
+
const char *git_editor(void)
{
const char *editor = getenv("GIT_EDITOR");
- const char *terminal = getenv("TERM");
- int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
+ int terminal_is_dumb = is_terminal_dumb();
if (!editor && editor_program)
editor = editor_program;
diff --git a/sideband.c b/sideband.c
index 1e4d684d6c..6d7f943e43 100644
--- a/sideband.c
+++ b/sideband.c
@@ -20,13 +20,12 @@
int recv_sideband(const char *me, int in_stream, int out)
{
- const char *term, *suffix;
+ const char *suffix;
char buf[LARGE_PACKET_MAX + 1];
struct strbuf outbuf = STRBUF_INIT;
int retval = 0;
- term = getenv("TERM");
- if (isatty(2) && term && strcmp(term, "dumb"))
+ if (isatty(2) && !is_terminal_dumb())
suffix = ANSI_SUFFIX;
else
suffix = DUMB_SUFFIX;
--
2.15.1
next prev parent reply other threads:[~2017-12-07 15:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 15:16 [PATCH v5 0/2] launch_editor(): indicate that Git waits for user input lars.schneider
2017-12-07 15:16 ` lars.schneider [this message]
2017-12-07 15:16 ` [PATCH v5 2/2] " lars.schneider
2017-12-07 15:43 ` Junio C Hamano
2017-12-07 15:48 ` Lars Schneider
2017-12-07 16:16 ` Lars Schneider
2017-12-07 16:30 ` Junio C Hamano
2017-12-07 16:36 ` Lars Schneider
2017-12-07 17:37 ` Kaartic Sivaraam
2017-12-07 17:56 ` Lars Schneider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171207151641.75065-2-lars.schneider@autodesk.com \
--to=lars.schneider@autodesk.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=larsxschneider@gmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
--cc=sbeller@google.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).