[CalendarServer-changes] [9122] CalendarServer/trunk/calendarserver/tools/shell/terminal.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 16 13:22:52 PDT 2012


Revision: 9122
          http://trac.macosforge.org/projects/calendarserver/changeset/9122
Author:   wsanchez at apple.com
Date:     2012-04-16 13:22:52 -0700 (Mon, 16 Apr 2012)
Log Message:
-----------
Cleanup.
Don't put reusable logic into key event handlers.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell/terminal.py

Modified: CalendarServer/trunk/calendarserver/tools/shell/terminal.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/terminal.py	2012-04-16 18:58:37 UTC (rev 9121)
+++ CalendarServer/trunk/calendarserver/tools/shell/terminal.py	2012-04-16 20:22:52 UTC (rev 9122)
@@ -187,42 +187,58 @@
         log.startLoggingWithObserver(observer)
 
     def handle_INT(self):
-        """
-        Handle ^C as an interrupt keystroke by resetting the current input
-        variables to their initial state.
-        """
-        self.pn = 0
-        self.lineBuffer = []
-        self.lineBufferIndex = 0
+        return self.resetLine()
 
-        self.terminal.nextLine()
-        self.terminal.write("KeyboardInterrupt")
-        self.terminal.nextLine()
-        self.exit()
-
     def handle_EOF(self):
         if self.lineBuffer:
             if self.emulate == "emacs":
                 self.handle_DELETE()
             else:
-                self.terminal.write('\a')
+                self.terminal.write("\a")
         else:
             self.handle_QUIT()
 
     def handle_FF(self):
         """
-        Handle a 'form feed' byte - generally used to request a screen
+        Handle a "form feed" byte - generally used to request a screen
         refresh/redraw.
         """
+        # FIXME: Clear screen != redraw screen.
+        return self.clearScreen()
+
+    def handle_QUIT(self):
+        return self.exit()
+
+    def handle_TAB(self):
+        return self.completeLine()
+
+    #
+    # Utilities
+    #
+
+    def clearScreen(self):
+        """
+        Clear the display.
+        """
         self.terminal.eraseDisplay()
         self.terminal.cursorHome()
         self.drawInputLine()
 
-    def handle_QUIT(self):
-        self.exit()
+    def resetLine(self):
+        """
+        Reset the current input variables to their initial state.
+        """
+        self.pn = 0
+        self.lineBuffer = []
+        self.lineBufferIndex = 0
+        self.terminal.nextLine()
+        self.drawInputLine()
 
     @inlineCallbacks
-    def handle_TAB(self):
+    def completeLine(self):
+        """
+        Perform auto-completion on the input line.
+        """
         # Tokenize the text before the cursor
         tokens = self.tokenize("".join(self.lineBuffer[:self.lineBufferIndex]))
 
@@ -261,15 +277,13 @@
                 self.terminal.write("%s%s\n" % (word, completion))
             self.drawInputLine()
 
-    #
-    # Utilities
-    #
-
     def exit(self):
+        """
+        Exit.
+        """
         self.terminal.loseConnection()
         self.service.reactor.stop()
 
-
     #
     # Command dispatch
     #
@@ -323,6 +337,10 @@
 
     @staticmethod
     def tokenize(line):
+        """
+        Tokenize input line.
+        @return: an iterable of tokens
+        """
         lexer = shlex(line)
         lexer.whitespace_split = True
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120416/abb5c985/attachment-0001.html>


More information about the calendarserver-changes mailing list