Rebol Programming/input
Appearance
USAGE:
[edit | edit source]INPUT /hide
DESCRIPTION:
[edit | edit source]Inputs a string from the console. New-line character is removed.
INPUT is a function value.
REFINEMENTS:
[edit | edit source]- /hide -- Mask input with a * character
SOURCE CODE
[edit | edit source]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 ] ]