changeset 68:e06961ebd035

worked out terminator keeping
author catherine@Elli.myhome.westell.com
date Mon, 23 Jun 2008 20:52:41 -0400
parents a78dff1e7bca
children 824651b4d1b1
files cmd2.py
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Mon Jun 23 17:37:10 2008 -0400
+++ b/cmd2.py	Mon Jun 23 20:52:41 2008 -0400
@@ -119,6 +119,10 @@
             xclipproc = subprocess.Popen('xclip -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
             xclipproc.stdin.write(txt)
             xclipproc.stdin.close()
+            # but we want it in both the "primary" and "mouse" clipboards
+            xclipproc = subprocess.Popen('xclip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+            xclipproc.stdin.write(txt)
+            xclipproc.stdin.close()
     else:
         def getPasteBuffer():
             raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"')
@@ -150,19 +154,19 @@
     processed.ignore(pyparsing.sglQuotedString)
     processed.ignore(pyparsing.dblQuotedString)
     pattern = pyparsing.SkipTo(processed) + processed + pyparsing.restOfLine
-    def parser(self, txt):
+    def parser(txt):
         result = pattern.searchString(txt)
         if result:
             return result[0][0].strip(), result[0][1:-1], result[0][-1].strip()
         else:
             return None
     return parser
-
-        
         
 class Cmd(cmd.Cmd):
     caseInsensitive = True
-    multilineCommands = []
+    terminators = [';','\n']    
+    multilineCommands = []          # commands that need a terminator to be finished
+    terminatorKeepingCommands = []  # commands that expect to process their own terminators (else it will be stripped during parse)
     continuationPrompt = '> '    
     shortcuts = {'?': 'help', '!': 'shell', '@': 'load'}
     excludeFromHistory = '''run r list l history hi ed edit li eof'''.split()   
@@ -179,7 +183,6 @@
                     break
             
     settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive']
-    terminators = [';','\n']
     _TO_PASTE_BUFFER = 1
     def do_cmdenvironment(self, args):
         self.stdout.write("""
@@ -204,16 +207,16 @@
     def __init__(self, *args, **kwargs):        
         cmd.Cmd.__init__(self, *args, **kwargs)
         self.history = History()
+        self.commmand_terminator_finder = punctuationParser(self.terminators)
+        self.output_destination_finder = punctuationParser(['>>', '>'])
+        self.input_source_finder = punctuationParser(['<'])
+        self.pipe_destination_finder = punctuationParser(['|'])
         
     def do_shortcuts(self, args):
         """Lists single-key shortcuts available."""
         result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items())
         self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
 
-    commmand_terminator_finder = punctuationParser(terminators)
-    output_destination_finder = punctuationParser(['>>', '>'])
-    input_source_finder = punctuationParser(['<'])
-    pipe_destination_finder = punctuationParser(['|'])
     def strip_terminators(self, txt):
         termination = self.commmand_terminator_finder(txt)
         if termination:
@@ -385,7 +388,8 @@
         i, n = 0, len(line)
         while i < n and line[i] in self.identchars: i = i+1
         cmd, arg = line[:i], line[i:].strip()
-        arg = self.strip_terminators(arg)
+        if cmd not in self.terminatorKeepingCommands:
+            arg = self.strip_terminators(arg)
         return cmd, arg, line
     
     def showParam(self, param):