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
);
20 static void restore_term_on_signal(int sig
)
27 char *git_terminal_prompt(const char *prompt
, int echo
)
29 static struct strbuf buf
= STRBUF_INIT
;
33 fh
= fopen("/dev/tty", "w+");
40 if (tcgetattr(fileno(fh
), &t
) < 0) {
47 sigchain_push_common(restore_term_on_signal
);
50 if (tcsetattr(fileno(fh
), TCSAFLUSH
, &t
) < 0) {
60 r
= strbuf_getline(&buf
, fh
, '\n');
76 char *git_terminal_prompt(const char *prompt
, int echo
)
78 return getpass(prompt
);