Search code examples
rebolred-lang

How do I get input from the console in Red language


I'm writing a console program (target MSDOS) in Red language and I need to ask the user to enter a character or a string, then to press Enter.

I can't seem to find how to do it, I've read the docs here (http://www.red-by-example.org/index.html) to no avail.

I tried something like this:

read.red

Red [

]

print "Please make your choice then press Enter"
x: input
print x

It works in the "Red Console" with red read.red but when I compile with red -r -t MSDOS read.red I get an error:

Compiling C:\apps\red-read\read.red ... *** Compilation Error: undefined word input *** in file: C:\apps\red-read\read.red *** near: [ input ]

How do I ask for input from a Red console program?

I'm using Red version: --== Red 0.6.3 ==--.


Solution

  • Okay, I did some testing and got it working on my end. You need 2 things.

    1) You need the latest build, not 0.63. You can grab the automated build from master from the downloads page.

    2) You need a reference in your file to use the console. Here is the updated code which will work on Windows with the latest version.

    Red [
    
    ]
    #include %environment/console/CLI/input.red
    
    print "Please make your choice then press Enter"
    x: input
    print x
    

    This info was buried away in an article on github. Also, you were right about MSDOS.