From: Wurzel Cidermaker Date: 2007-10-31T01:38:21+09:00 Subject: Re: loop until a key (i.e. enter or ESC) is pressed ara.t.howard wrote: > On Oct 30, 2007, at 9:50 AM, Wurzel Cidermaker wrote: > >> then stops and I presume is waiting for the "gets" >> >> To put this into some context; >> >> I have a socket client program that continously reads data from a >> server, the only way I have currently to stop it is to do a CTRL-C, I >> want/would expect a more elegant way of performing an exit on a loop. > > start this before you fire up your socket stuff > > reaper = > Thread.new do > loop do > Kernel.exit if gets == 'exit' > end > end > > if you type exit, your program will exit. check out highline or > search the archives if you want something more elegant - exiting a > loop and accepting cross platform user input is a real can of worms > made complex by the lack of getch() on *nix platforms, the > idiosyncracies of termninal attributes, and buffering issues with pty > vs not. > > regards > > a @ http://codeforpeople.com/ thanks for your response but I struggling to implement it. can you please fix what I have below? # example def loopy loop do puts Time.now sleep 1 end end reaper = Thread.new do loop do Kernel.exit if gets == 'exit' end end loopy -- Posted via http://www.ruby-forum.com/.