import pyreadline,time,msvcrt,pdb

from pyreadline.rlmain import rl

import startup

while 1:
    rl.mode.readline_setup("NON-BLOCKING>")  #Prepare readline for aquiring new line, print prompt
    idx=0
    start=int(time.time())
    line=""
    while 1:
        if start+idx<time.time():
            rl.console.title("NON-BLOCKING: %d"%idx)
            idx+=1
        try:
            if msvcrt.kbhit():
                rl.console.title("Event!!")
                try:
                    if rl.mode._readline_from_keyboard_poll():
                        line=rl.l_buffer.get_line_text() + '\n'
                        rl.console.write('\r\n')
                        rl.add_history(rl.l_buffer.copy())
                        break
                except EOFError:
                    raise##Do what you want when control-d is pressed on empty line
                    break
        except KeyboardInterrupt:
            rl.mode.handle_ctrl_c()  #this is needed to allow ctrl-c to be bound to copy
    print "result: %s"%line,        
