diff --git a/twander.py b/twander.py index ec1065f..dbe64a4 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.49 2003/01/10 19:26:08 tundra Exp $" +RCSID = "$Id: twander.py,v 2.50 2003/01/11 00:23:48 tundra Exp $" VERSION = RCSID.split()[2] @@ -257,13 +257,14 @@ MENUOFFSET = ROOTBORDER + MENUBORDER + MENUPADX ##### -# Configuration File Related Literals +# Configuration File Related Constants ##### ASSIGN = "=" # Assignment for variable definitions CONF = "" # Config file user selected with -c option COMMENT = r"#" # Comment introducer string ENVVBL = r'$' # Symbol denoting an environment variable +MAXHIST = 32 # Maximum length of command history MAXNESTING = 32 # Maximum depth of nested variable definitions QUOTECHAR = '\"' # Character to use when quoting Built-In Variables @@ -349,6 +350,7 @@ DEBUGCMDS = (1<<4) # Dump command execution string DEBUGKEYS = (1<<5) # Dump key bindings DEBUGDIRS = (1<<6) # Dump directory stack contents as it changes +DEBUGHIST = (1<<7) # Dump contents of Command History stack after command execution # Debug Strings @@ -357,6 +359,7 @@ dDIRSTK = "" dFUNCKEYS = "" dHEADER = "twander Debug Dump Run On: %s\n" +dHIST = "" dINTVAR = "" dKEYBINDS = "" dNULL = "None" @@ -1063,7 +1066,7 @@ # Bind function keys to a common handler for x in range(len(self.FuncKeys)): - self.DirList.bind('' % (x+1), FuncKeypress) + self.DirList.bind('' % (x+1), lambda event, index=x :FuncKeypress(event, index)) # Give the listbox focus so it gets keystrokes @@ -1412,7 +1415,7 @@ # Otherwise,actually execute the command else: - thread.start_new_thread(os.system, (cmd,)) + ExecuteCommand(cmd) # end of 'KeystrokeHandler()' @@ -1708,10 +1711,16 @@ #### def KeyRunCommand(event): + global UI + - cmd = askstring(pRUNCMD, pENCMD) + if UI.CmdHist: + cmd = askstring(pRUNCMD, pENCMD, initialvalue=UI.CmdHist[-1] ) + else: + cmd = askstring(pRUNCMD, pENCMD) + if cmd: - thread.start_new_thread(os.system, (cmd,)) + ExecuteCommand(cmd) UI.DirList.focus() # End of 'KeyRunCommand()' @@ -1791,10 +1800,10 @@ # the selection elsewhere. elif OSNAME == 'nt': - os.startfile(os.path.join(os.path.abspath(UI.CurrentDir), selected)) + ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), UseStartDir=TRUE) elif OSNAME == 'posix': - thread.start_new_thread(os.system, (os.path.join(os.path.abspath(UI.CurrentDir), selected),)) + ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected)) # End of 'DirListHandler()' @@ -1803,9 +1812,8 @@ # Event Handler: Handler Function Keys ##### -def FuncKeypress(event): +def FuncKeypress(event, index): - index = int(event.keysym.split('F')[1]) - 1 dir = UI.FuncKeys[index] if dir: LoadDirList(dir) @@ -1818,6 +1826,35 @@ #-------------- Handler Utility Functions -----------------# +##### +# Execute A Command +##### + +def ExecuteCommand(cmd, UseStartDir=FALSE): + global UI + + # Run the command on Win32 using filename associations + if UseStartDir: + os.startfile(cmd) + + # Normal command execution for both Unix and Win32 + else: + thread.start_new_thread(os.system, (cmd,)) + + # Save command on history stack maintaining max stack depth + + if len(UI.CmdHist) == MAXHIST: + UI.CmdHist = UI.CmdHist[1:] + + UI.CmdHist.append(cmd) + + # Dump Command History stack if requested + + if int(DEBUGLEVEL) & DEBUGHIST: + PrintDebug(dHIST, UI.CmdHist) + +# End of 'ExecuteCommand() + ##### # Load UI With Selected Directory @@ -2325,6 +2362,9 @@ # Initialize list of all directories visited UI.AllDirs = [] +# Initialize command history +UI.CmdHist = [] + # Parse the and store configuration file, if any ParseConfFile(None)