Update of /cvsroot/cvsshell/cvsshell/src
In directory usw-pr-cvs1:/tmp/cvs-serv1547
Modified Files:
interactive_app.py
Log Message:
C-c is now also supported to stop the REPL
Index: interactive_app.py
===================================================================
RCS file: /cvsroot/cvsshell/cvsshell/src/interactive_app.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** interactive_app.py 7 Mar 2002 13:08:49 -0000 1.3
--- interactive_app.py 7 Mar 2002 15:09:26 -0000 1.4
***************
*** 20,84 ****
###############################################################################
! import os
! from app import App, AppError
!
! class InteractiveApp(App):
!
! def __init__(self):
! App.__init__(self)
! self.BREAK_REPL = 'BREAK_REPL'
! try:
! import readline
! except ImportError:
! self.printErr("Could not import readline. History browsing " \
! "and tab completion will not be available.")
! return
! else:
! readline.parse_and_bind("tab: complete")
!
! def setHistoryFile(self,filename):
! self.historyFile = filename
! try:
! import readline
! except ImportError: return
! try:
! readline.read_history_file(self.historyFile)
! except IOError:
! pass
! import atexit
! atexit.register(readline.write_history_file, self.historyFile)
!
! def run(self): # define App.run here
! while 1:
! command = self.readCommand()
! if command == None:
! break
! result = self.evalCommand(command)
! if result is self.BREAK_REPL: break
! elif result is None: continue
! else: self.printMsg(`result`)
!
! def readCommand(self): # subclass hooks + App.start,stop
! return self.prompt(self.getPrompt())
!
! def getPrompt(self):
! return '? '
!
! def prompt(self, msg):
! """Displayes msg and prompts the user for input.
! If input is EOF, None is returned."""
!
! try:
! a = raw_input(msg)
! except EOFError:
! self.printMsg()
! return None
! a = os.path.expandvars(a)
! return a.strip()
!
! def evalCommand(self, command):
! """Subclasses should override this method.
! If BREAK_REPL is returned, the repl is terminated,
! otherwise the return-value is printed (if not None)."""
! raise AppError, 'evalCommand must be redefined!'
!
--- 20,84 ----
###############################################################################
! import os
! from app import App, AppError
!
! class InteractiveApp(App):
!
! def __init__(self):
! App.__init__(self)
! self.BREAK_REPL = 'BREAK_REPL'
! try:
! import readline
! except ImportError:
! self.printErr("Could not import readline. History browsing " \
! "and tab completion will not be available.")
! return
! else:
! readline.parse_and_bind("tab: complete")
!
! def setHistoryFile(self,filename):
! self.historyFile = filename
! try:
! import readline
! except ImportError: return
! try:
! readline.read_history_file(self.historyFile)
! except IOError:
! pass
! import atexit
! atexit.register(readline.write_history_file, self.historyFile)
!
! def run(self): # define App.run here
! while 1:
! command = self.readCommand()
! if command == None:
! break
! result = self.evalCommand(command)
! if result is self.BREAK_REPL: break
! elif result is None: continue
! else: self.printMsg(`result`)
!
! def readCommand(self): # subclass hooks + App.start,stop
! return self.prompt(self.getPrompt())
!
! def getPrompt(self):
! return '? '
!
! def prompt(self, msg):
! """Displayes msg and prompts the user for input.
! If input is EOF, None is returned."""
!
! try:
! a = raw_input(msg)
! except EOFError, KeyboardInterrupt:
! self.printMsg()
! return None
! a = os.path.expandvars(a)
! return a.strip()
!
! def evalCommand(self, command):
! """Subclasses should override this method.
! If BREAK_REPL is returned, the repl is terminated,
! otherwise the return-value is printed (if not None)."""
! raise AppError, 'evalCommand must be redefined!'
!
|