def getinput(): 'a generator function that returns a line or two from an interactive session.' previousline, line = '', '' isloop = False while True: if previousline: prompt = 'more> ' else: if po.color: prompt = ps_lib.eval_str(po.colorprompt) else: prompt = ps_lib.eval_str(po.prompt) ansi.xtermTitle(ps_lib.eval_str(po.title)) try: line = raw_input(prompt) # get input from user except EOFError: # sys.exit(1) or ^Z, ^D raise StopIteration break except KeyboardInterrupt: # ^C ( now caught earlier) print continue if line.isspace(): line = '' # make sure blank line is false if not line and not previousline: continue # just an enter hit, I think # check if we need more input if line: if isloop: #previousline = previousline + ' ' + line + '\n' previousline = previousline + line + '\n' continue if line.split()[0] in pi.branch_words: #ps_lib. isloop = True previousline = previousline + line + '\n' continue if line[-1] == '\\': # get more previousline = previousline + line[:-1] continue else: # line is nada '', and a previous line exists, end extended line isloop = False if previousline: line = previousline + ' ' # keeep from triggering EOF downstream previousline = '' if po.opts.debug: ps_lib.msg('debug', ` line `) if '\n' in line: for item in line.split('\n'): #print 'yielding:', `item` yield item #yield '' else: yield line
def getinput(): 'a generator function that returns a line or two from an interactive session.' previousline, line = '', '' isloop = False while True: if previousline: prompt = 'more> ' else: if po.color: prompt = ps_lib.eval_str(po.colorprompt) else: prompt = ps_lib.eval_str(po.prompt) ansi.xtermTitle(ps_lib.eval_str(po.title)) try: line = raw_input(prompt) # get input from user except EOFError: # sys.exit(1) or ^Z, ^D raise StopIteration break except KeyboardInterrupt: # ^C ( now caught earlier) print; continue if line.isspace(): line = '' # make sure blank line is false if not line and not previousline: continue # just an enter hit, I think # check if we need more input if line: if isloop: #previousline = previousline + ' ' + line + '\n' previousline = previousline + line + '\n' continue if line.split()[0] in pi.branch_words: #ps_lib. isloop = True previousline = previousline + line + '\n' continue if line[-1] == '\\': # get more previousline = previousline + line[:-1] continue else: # line is nada '', and a previous line exists, end extended line isloop = False if previousline: line = previousline + ' ' # keeep from triggering EOF downstream previousline = '' if po.opts.debug: ps_lib.msg('debug', `line`) if '\n' in line: for item in line.split('\n'): #print 'yielding:', `item` yield item #yield '' else: yield line
if sys.platform == 'win32': #os.system('cmd /c title %s' % ps_lib.eval_str(po.title)) # set title (doesnt work - reset on exit of cmd) pass readline = False elif os.name == 'posix': #import curses # term routines import readline # line editor import rlcompleter # tab completion #print 'delims', readline.get_completer_delims() readline.parse_and_bind('tab: complete') readline.set_completer_delims('\r\n`~!@#$%^&*()-=+[{]}\|;:\'",<>? ') readline.set_completer(ps_interactive.ps_completer(po.namespace).complete) ansi.xtermTitle(ps_lib.eval_str(po.title)) # set title, bug! # Register the signal handlers def termsize_change(signum, frame): x, y = ansi.getTermSize() if x: os.environ['COLUMNS'] = str(x) if y: os.environ['LINES'] = str(y) termsize_change(None, None) # once to set environment def sighandler(signum, frame): '''Clean and tidy shutdown when killed.''' if po.opts.debug: ps_lib.msg('debug', 'Signal %s received.' % signum) #print 'removing:', readline.remove_history_item(readline.get_current_history_length()-1) # how to clear the line buffer? there doesn't seem to be a function to do it. print
# set title (doesnt work - reset on exit of cmd) pass readline = False elif os.name == 'posix': #import curses # term routines import readline # line editor import rlcompleter # tab completion #print 'delims', readline.get_completer_delims() readline.parse_and_bind('tab: complete') readline.set_completer_delims('\r\n`~!@#$%^&*()-=+[{]}\|;:\'",<>? ') readline.set_completer( ps_interactive.ps_completer(po.namespace).complete ) ansi.xtermTitle(ps_lib.eval_str(po.title)) # set title, bug! # Register the signal handlers def termsize_change(signum, frame): x, y = ansi.getTermSize() if x: os.environ['COLUMNS'] = str(x) if y: os.environ['LINES'] = str(y) termsize_change(None, None) # once to set environment def sighandler(signum, frame): '''Clean and tidy shutdown when killed.''' if po.opts.debug: ps_lib.msg('debug', 'Signal %s received.' % signum) #print 'removing:', readline.remove_history_item(readline.get_current_history_length()-1) # how to clear the line buffer? there doesn't seem to be a function to do it. print readline.redisplay()