Thanks to MD XF's recent challenge, we can now read passwords in many different languages! The problem is, now we need to port our applications to mobile devices, and they do password entry a little differently.
Challenge
- Read a string from the keyboard.
- Each time a character
k
is entered, display it for a short time interval. - After the time interval has passed OR the user has entered another character, replace
k
with some characterc
.
Rules
c
must be constant; it must be the same character.c
can be any visible character (i.e. it cannot be a newline, space, tab, or unprintable).c
can't be based on any inputtedk
;c
must be defined/constant before the firstk
is read.c
must be the same every time the program is run.c
can be one of the values given ask
if by accident, as long as all other rules are followed.- You must print
k
in realtime. As soon as the user enters a newk
, you must display it immediately. k
should be visible to the end user before being changed toc
; the time interval shall not be less than 0.5 seconds.k
should be replaced byc
within a reasonable time; the time interval shall not exceed 5 seconds.- As soon as a new character is entered, whether or not the time interval has expired, you should replace
k
withc
and use the entered key as the newk
immediately. - It is acceptable to clear and redraw the screen each time you need to change a character.
- You may use any reasonable methods of input and output as long as all other rules are followed.
- You may assume that the number of characters inputted is never longer than the terminal/graphical window width.
- If using a terminal, your program should terminate after a newline is entered or EOF is reached.
- Your program should function as outlined here on both mobile and other environments.
- Your program may assume that the input will only contain printable characters (letters, numbers, symbols) and possibly a terminating newline (no backspace, arrow keys, delete, etc).
- Your program may terminate when Ctrl+C is pressed.
- You may terminate your program by closing a window, if your program launches one.
Scoring
This is code-golf, so the shortest answer in each language wins!
Example
Here is an example of what it should look like. Note this is recorded on a mobile platform, but should also work on a desktop platform.