Newbie Question: Getting User Input

41 views
Skip to first unread message

David Palmer

unread,
Dec 7, 2014, 1:03:51 PM12/7/14
to ooc-...@googlegroups.com
I've only been playing around with ooc for about a week, but I feel like I'm blind to what should be an outrageously simple use case. How do I get input from the user in the terminal? All I want to do is pause execution while the user types in a line of text, and capture that text when he or she hits the return key. Is there an out of the box solution?

Thanks,
DP

Amos Wenger

unread,
Dec 7, 2014, 1:20:37 PM12/7/14
to David Palmer, ooc-...@googlegroups.com
Hey David,

Here's a simple solution that should work everywhere (tested on OSX, I'm sure it works on Linux, less sure on Windows):

import io/FileReader

"> " print()
line := stdin readLine()
"Read line: %s" printfln(line)

`stdin` is a file descriptor, and `readline` is a function on FileDescriptor if I recall correctly.

That said, if you want proper console output I'd recommend looking into readline:


Or linenoise:


Cheers,
- Amos


--
You received this message because you are subscribed to the Google Groups "ooc-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ooc-lang+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Palmer

unread,
Dec 7, 2014, 3:07:02 PM12/7/14
to ooc-...@googlegroups.com, thed...@gmail.com, amosw...@gmail.com
That was simple! Thanks for the quick reply, it works just fine. (On OSX. I haven't tested it on Windows.)

DP
Reply all
Reply to author
Forward
0 new messages