Skip to content

Commit ad68103

Browse files
committed
FEAT: implemented ASK/HIDE (which prevents echoing user input)
It is implemented using standard ANSI escape sequences CONCEAL/REVEAL, which are now emulated on Windows using `SetConsoleMode`. Fixes: metaeducation/rebol-issues#1400 metaeducation/rebol-issues#1388 Partially fixes (as there is still no INPUT/HIDE): metaeducation/rebol-issues#476
1 parent 9989527 commit ad68103

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/mezz/mezz-files.r

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ input: function [
8080
ask: func [
8181
"Ask the user for input."
8282
question [series!] "Prompt to user"
83-
/hide "mask input with *"
83+
/hide "Turns off echoing inputs"
84+
/local tmp
8485
][
8586
prin question
86-
trim either hide [input/hide] [input]
87+
trim either hide [
88+
prin "^[[8m" ; ANSI conceal command
89+
tmp: input
90+
print "^[[28m" ; ANSI reveal command
91+
tmp
92+
][ input ]
8793
]
8894

8995
confirm: func [

src/os/win32/dev-stdio.c

+11
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ BOOL WINAPI Handle_Break(DWORD dwCtrlType)
108108
return TRUE; // We handled it
109109
}
110110

111+
void Set_Echo_Mode(boolean set) {
112+
DWORD mode = 0;
113+
GetConsoleMode(Std_Inp, &mode);
114+
if (set)
115+
SetConsoleMode(Std_Inp, mode | ENABLE_ECHO_INPUT);
116+
else
117+
SetConsoleMode(Std_Inp, mode & (~ENABLE_ECHO_INPUT));
118+
}
119+
111120
#ifdef DEBUG_METHOD
112121
// Because this file deals with stdio, we must avoid using stdio for debug.
113122
// This funtion is of use wne needed.
@@ -528,8 +537,10 @@ DEFINE_DEV(Dev_StdIO, "Standard IO", 1, Dev_Cmds, RDC_MAX, 0);
528537
case 4: attribute = attribute | COMMON_LVB_UNDERSCORE; break;
529538
case 7: tmp = (attribute & 0xFFF0) >> 4;
530539
attribute = ((attribute & 0xFF0F) << 4) | tmp; break; //reverse
540+
case 8: Set_Echo_Mode(FALSE); break; //Conceal (turn off echo)
531541
case 22: attribute = attribute & 0xFFF7; break; //FOREGROUND_INTENSITY reset
532542
case 24: attribute = attribute & 0x7FFF; break; //reset underscore
543+
case 28: Set_Echo_Mode(TRUE); break; //Reveal (Conceal off)
533544
case 30: attribute = attribute & 0xFFF8; break;
534545
case 31: attribute = (attribute & 0xFFF8) | FOREGROUND_RED; break;
535546
case 32: attribute = (attribute & 0xFFF8) | FOREGROUND_GREEN; break;

0 commit comments

Comments
 (0)