Last modified on 31 October 2012, at 11:54

REBOL Programming/input

USAGE:Edit

INPUT /hide 

DESCRIPTION:Edit

Inputs a string from the console. New-line character is removed.

INPUT is a function value.

REFINEMENTS:Edit

  • /hide -- Mask input with a * character

SOURCE CODEEdit

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
    ]
]