Re: [PATCH] compat: add a getpass() compatibility function
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 19, 2011, 17:27 UTC
- Message-ID
- <7v62p68ut0.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <EC81F772-7149-40A0-891A-973C886AB052@gieschke.de>
Rafael Gieschke <rafael@gieschke.de> writes:
Show 6 quoted lines
>> Windows doesn't have /dev/tty, but the logic in this version handles >> that by using stdin/stderr instead. The signal-stuff has a comment >> that indicates it might not even be correct. tcgetattr/tcsetattr isn't >> supported on Windows, but it's not needed if we use getch (as the >> version in compat/mingw.c does). POSIX/curses getch respects the >> echo-setting, while Windows getch never echo.
Probably a properly abstracted common version would look like a function that calls four platform-dependent helper funcions in this order:
0. prompt
1. start "noecho" mode
2. get whole line
3. exit "noecho" modewhere Windows may use stderr for 0, have noop() implementation for 1 and 3, use _getch() that does not echo for 2, while POSIX may write to /dev/tty for 0, use tc[gs]etattr() with perhaps some signal settings sprinkled in for 1 and 3.
So I don't see a need for Windows to emulate tc[g]setattr nor curses in order to get a generic getpass() abstraction between two platforms.