1 #include "git-compat-util.h"
2 #include "compat/terminal.h"
8 static int term_fd = -1;
9 static struct termios old_term;
11 static void restore_term(void)
16 tcsetattr(term_fd, TCSAFLUSH, &old_term);
21 static void restore_term_on_signal(int sig)
28 static int disable_echo(void)
32 term_fd = open("/dev/tty", O_RDWR);
33 if (tcgetattr(term_fd, &t) < 0)
37 sigchain_push_common(restore_term_on_signal);
40 if (!tcsetattr(term_fd, TCSAFLUSH, &t))
49 char *git_terminal_prompt(const char *prompt, int echo)
51 static struct strbuf buf = STRBUF_INIT;
53 FILE *input_fh, *output_fh;
55 input_fh = fopen("/dev/tty", "r");
59 output_fh = fopen("/dev/tty", "w");
65 if (!echo && disable_echo()) {
71 fputs(prompt, output_fh);
74 r = strbuf_getline(&buf, input_fh, '\n');
76 putc('\n', output_fh);
91 char *git_terminal_prompt(const char *prompt, int echo)
93 return getpass(prompt);