diff --git a/twander.py b/twander.py index 082318f..36d2572 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.162 2005/01/23 11:26:04 tundra Exp $" +RCSID = "$Id: twander.py,v 3.163 2005/01/24 10:43:31 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -579,13 +579,18 @@ 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 reVAR = r"\[.+?\]" # Regex describing variable notation +reYESNO = r'\[YESNO:.*?\]' # Regex describing yes or no builtin + # Create actual regex matching engines -REDIRSC = re.compile(reDIRSC) -REVAR = re.compile(reVAR) -CONDVAR = re.compile(r'^' + reVAR + r'$') +REDIRSC = re.compile(reDIRSC) +REPROMPT = re.compile(rePROMPT) +REVAR = re.compile(reVAR) +REYESNO = re.compile(reYESNO) +CONDVAR = re.compile(r'^' + reVAR + r'$') # Built-In Variables @@ -1146,10 +1151,54 @@ # Strip off leading/trailing spaces cleanline = line.strip() + + # Preserve the contents of PROMPT or YESNO builtins. + + # If we didn't do this, the split() below would trash the + # whitespace within prompts/defaults. The user may + # specifically *want* whitespace formatting in either the + # prompt or the default, so we need to preserve their + # entry exactly as-is. + + # Algorithm: + # + # 1) Find every instance of a PROMPT or YESNO builtin + # 2) Save it in 'saveliteral' + # 3) Replace it with a bogus, *unsplittable* string ending with its 'saveliteral' index + # 4) Split the line + # 5) Replace original content in the appropriate spot(s) - # Split what's left into separate fields again + + # Steps 1-3 + + saveliteral = [] + index = 0 + + for matchtest in (REPROMPT, REYESNO): + for match in matchtest.finditer(cleanline): + found=match.group() + saveliteral.append(found) + cleanline = cleanline.replace(found, PROMPT+str(index)) + index += 1 + + + # Step 4: Split what's left into separate fields again + fields = cleanline.split() + # Step 5: Now restore the strings we want to preserve literally + + if saveliteral: + index = 0 + + while index < len(fields): + + field = fields[index] + if field.startswith(PROMPT): + fields[index] = saveliteral[int(field[-1])] + + index += 1 + # Make a copy of the fields which is guaranteed to have at # least two fields for use in the variable declaration tests. @@ -4026,8 +4075,13 @@ default = {} prompt = prompt.split(DEFAULTSEP) - prompt.append("") - prompt, default[defaultarg] = prompt[0], prompt[1].lower().strip() + 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)