lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, 20 Mar 2014 16:15:16 +0200
steve donovan <steve.j.donovan@gmail.com> wrote:

> On Thu, Mar 20, 2014 at 4:08 PM, Steve Litt
> <slitt@troubleshooters.com> wrote:
> > function getch_unix()
> >         os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
> >         local key = io.read(1)
> >         os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
> >         return(key);
> > end
> 
> That is indeed ingenious! 

Isn't that brilliant (Litt puffs out his chest).

I'd like to thank the guys who documented it, last century. You can see
it by:

man perlfunc

Then search for getc, and you'll see where I learned about it, back in
1999.

But of course, I'm taking complete credit for it :-)

Since then, I've used this same technique to read a single character,
sans newline, in Perl, Python, Ruby, Lua, and maybe even Bash and maybe
C.

Reading a keyhit without requiring a following Enter is a core
requirement for my UMENU software, which I've written in Perl, Python,
Ruby and Lua.

That getch_unix() I posted was copied and pasted out of the Lua
version of UMENU.

I love computers.

Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance