Rebol 编程/输入
外观
< Rebol 编程
INPUT /hide
从控制台输入字符串。 换行符将被移除。
INPUT 是一个函数值。
- /hide -- 用 * 字符遮蔽输入
input: func [
{Inputs a string from the console. New-line character is removed.}
/hide "Mask input with a * character"
/local console-port buffer char ignore ignore-chars
][
either hide [
console-port: open/binary [scheme: 'console]
buffer: make string! 10
ignore: make binary! 10
ignore-chars: charset ["^@^["]
while [
wait console-port
char: to-char first console-port
(char <> newline) and (char <> #"^M")
] [
any [
all [char = #"^H"
either not empty? buffer [
clear back tail buffer
prin ["^H ^H"]
] [true]
true
]
all [find ignore-chars char
read-io console-port ignore 3
true
]
all [append buffer char
prin #"*"
false
]
]
]
prin newline
close console-port
buffer
] [
pick system/ports/input 1
]
]