summaryrefslogtreecommitdiff
path: root/compat/terminal.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-12-10 10:41:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-13 00:09:38 (GMT)
commit21aeafceda2382d26bfa73a98ba45a937d65d77a (patch)
tree4fc3156cd44f6889e25dd302c081d7a18558b472 /compat/terminal.h
parent1cb0134f3414be187cc3eb98e9740aeeb07dcb16 (diff)
downloadgit-21aeafceda2382d26bfa73a98ba45a937d65d77a.zip
git-21aeafceda2382d26bfa73a98ba45a937d65d77a.tar.gz
git-21aeafceda2382d26bfa73a98ba45a937d65d77a.tar.bz2
add generic terminal prompt function
When we need to prompt the user for input interactively, we want to access their terminal directly. We can't rely on stdio because it may be connected to pipes or files, rather than the terminal. Instead, we use "getpass()", because it abstracts the idea of prompting and reading from the terminal. However, it has some problems: 1. It never echoes the typed characters, which makes it OK for passwords but annoying for other input (like usernames). 2. Some implementations of getpass() have an extremely small input buffer (e.g., Solaris 8 is reported to support only 8 characters). 3. Some implementations of getpass() will fall back to reading from stdin (e.g., glibc). We explicitly don't want this, because our stdin may be connected to a pipe speaking a particular protocol, and reading will disrupt the protocol flow (e.g., the remote-curl helper). 4. Some implementations of getpass() turn off signals, so that hitting "^C" on the terminal does not break out of the password prompt. This can be a mild annoyance. Instead, let's provide an abstract "git_terminal_prompt" function that addresses these concerns. This patch includes an implementation based on /dev/tty, enabled by setting HAVE_DEV_TTY. The fallback is to use getpass() as before. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/terminal.h')
-rw-r--r--compat/terminal.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/compat/terminal.h b/compat/terminal.h
new file mode 100644
index 0000000..97db7cd
--- /dev/null
+++ b/compat/terminal.h
@@ -0,0 +1,6 @@
+#ifndef COMPAT_TERMINAL_H
+#define COMPAT_TERMINAL_H
+
+char *git_terminal_prompt(const char *prompt, int echo);
+
+#endif /* COMPAT_TERMINAL_H */