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
;
55 fh
= fopen("/dev/tty", "w+");
59 if (!echo
&& disable_echo()) {
67 r
= strbuf_getline(&buf
, fh
, '\n');
69 fseek(fh
, SEEK_CUR
, 0);
84 char *git_terminal_prompt(const char *prompt
, int echo
)
86 return getpass(prompt
);