diff --git a/twander.py b/twander.py index fabf5bf..87f5ff0 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.171 2005/01/25 08:08:24 tundra Exp $" +RCSID = "$Id: twander.py,v 3.172 2005/01/25 20:01:32 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -583,9 +583,9 @@ DIRSC = "DIRSC" # Directory Shortcut naming WILDCARD = "WILDCARD" # Wildcard naming reDIRSC = r'^' + DIRSC + r'([1-9]|1[0-2])$' # Regex describing Directory Shortcut names -rePROMPT = r'\[PROMPT:.*?\]' # Regex describing prompt builtin +rePROMPT = r'\+{PROMPT:.*?\}' # Regex describing prompt builtin reVAR = r"\[.+?\]" # Regex describing variable notation -reYESNO = r'\[YESNO:.*?\]' # Regex describing yes or no builtin +reYESNO = r'\{YESNO:.*?\}' # Regex describing yes or no builtin # Create actual regex matching engines @@ -614,10 +614,10 @@ MEM10 = r'[MEM10]' MEM11 = r'[MEM11]' MEM12 = r'[MEM12]' -PROMPT = r'[PROMPT:' +PROMPT = r'{PROMPT:' SELECTION = r'[SELECTION]' SELECTIONS = r'[SELECTIONS]' -YESNO = r'[YESNO:' +YESNO = r'{YESNO:' # Shortcuts to the builtins available in RUNCMD @@ -1546,9 +1546,6 @@ cmdname = fields[1] cmd = " ".join(fields[2:]) - # Process any User-Defined variables - cmd = ProcessVariables(cmd, num, cleanline) - # A null return means there was a problem - abort if not cmd: return @@ -2536,7 +2533,7 @@ # Otherwise, replace config tokens with actual file/dir names if cmd: - ExecuteCommand(cmd, name) + ExecuteCommand(cmd, name, ResolveVars=True) # end of 'KeystrokeHandler()' @@ -3318,9 +3315,17 @@ # Work with a copy of the passed command newcmd = cmd + # Replace references to any Environment or User-Defined variables + # but only when asked to. This needs to be done *before* + # we process the built-ins so that variable references within + # a PROMPT or YESNO are resolved before we handle the prompting. + + if newcmd and ResolveVars: + newcmd = ProcessVariables(newcmd, 0 , name) + # Process references to any Built-In variables if ResolveBuiltIns: - newcmd = ProcessBuiltIns(cmd, name) + newcmd = ProcessBuiltIns(newcmd, name) # A leading REFRESHAFTER in the command string means the user wants # a display refresh after the command returns @@ -3331,16 +3336,6 @@ do_refresh_after = True - # Replace references to any Environment or User-Defined variables - # but only when asked to. - i.e., The command was manually - # entered by the user and may contain unresolved variables. - # (Commands the user defined in the configuration file - # already have their variables dereferenced when that file is - # read and parsed.) - - if newcmd and ResolveVars: - newcmd = ProcessVariables(newcmd, 0 , name) - # Just dump command if we're debugging if DEBUGLEVEL & DEBUGCMDS: @@ -4112,61 +4107,9 @@ def ProcessBuiltIns(cmd, name): - # First do any prompting required - - for promptvar, handler, defaultarg, replace in ((YESNO, askyesno, "default", FALSE), - (PROMPT, askstring, "initialvalue", TRUE)): - - for x in range(cmd.count(promptvar)): - b = cmd.find(promptvar) - e = cmd.find("]", b) - prompt = cmd[b + len(promptvar):e] - - # Pickup default value, if any - - default = {} - prompt = prompt.split(DEFAULTSEP) - prompt.append("") # Guarantee a minimum of two entries - prompt, default[defaultarg] = prompt[0], prompt[1] - - # Condition the default if its a YESNO builtin - - if promptvar == YESNO: - default[defaultarg] = default[defaultarg].strip().lower() - - # YESNO dialogs can only accept two arguments (we just made them case-insensitive above) - - if (default[defaultarg] not in ("yes", "no", "")): - - # Display an error - WrnMsg(wBADYESNODFLT % (default[defaultarg], name)) - - # We're done on an error - return - - # Everything OK - Run the dialog - - # If there is no default argument, then don't pass anything at all - Tk gets confused if we do - - if not default[defaultarg]: - default = {} - - val = handler(name, prompt, **default) - - # Make sure our program gets focus back - UI.DirList.focus() - - if val: - if replace: - cmd = cmd.replace(cmd[b:e+1], QUOTECHAR + val + QUOTECHAR) - else: - cmd = cmd.replace(cmd[b:e+1], '') - - # Null input means the command is being aborted - else: - return - - # Now do files & directories + # Do files & directories first. That way they can be embedded in + # prompting builtins. + # Strip trailing path separators in each case to # give the command author the maximum flexibility possible @@ -4230,6 +4173,60 @@ s += QUOTECHAR + m + QUOTECHAR + " " cmd = cmd.replace(vblref, s) + # Now take care of the prompting + + for promptvar, handler, defaultarg, replace in ((YESNO, askyesno, "default", FALSE), + (PROMPT, askstring, "initialvalue", TRUE)): + + for x in range(cmd.count(promptvar)): + b = cmd.find(promptvar) + e = cmd.find("}", b) + prompt = cmd[b + len(promptvar):e] + + # Pickup default value, if any + + default = {} + prompt = prompt.split(DEFAULTSEP) + prompt.append("") # Guarantee a minimum of two entries + prompt, default[defaultarg] = prompt[0], prompt[1] + + # Condition the default if its a YESNO builtin + + if promptvar == YESNO: + default[defaultarg] = default[defaultarg].strip().lower() + + # YESNO dialogs can only accept two arguments (we just made them case-insensitive above) + + if (default[defaultarg] not in ("yes", "no", "")): + + # Display an error + WrnMsg(wBADYESNODFLT % (default[defaultarg], name)) + + # We're done on an error + return + + # Everything OK - Run the dialog + + # If there is no default argument, then don't pass anything at all - Tk gets confused if we do + + if not default[defaultarg]: + default = {} + + val = handler(name, prompt, **default) + + # Make sure our program gets focus back + UI.DirList.focus() + + if val: + if replace: + cmd = cmd.replace(cmd[b:e+1], QUOTECHAR + val + QUOTECHAR) + else: + cmd = cmd.replace(cmd[b:e+1], '') + + # Null input means the command is being aborted + else: + return + return cmd # End of 'ProcessBuiltIns()' @@ -4305,7 +4302,7 @@ WrnMsg(wBADENVVBL % (num, x, line)) return "" - # Process variable execution + # Process execution variables elif vbl[0] == vbl[-1] == VAREXECUTE: