Add a new clear method in the Output class
authorNikos Skalkotos <skalkoto@grnet.gr>
Wed, 8 Aug 2012 13:13:57 +0000 (16:13 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Wed, 8 Aug 2012 13:13:57 +0000 (16:13 +0300)
In the cli output classes this method will clear terminal screen if
the standard output is a terminal.

image_creator/dialog_wizard.py
image_creator/output/__init__.py
image_creator/output/cli.py

index 8e122a8..e26975e 100644 (file)
@@ -177,7 +177,7 @@ def extract_image(session):
     device.out = out
     image_os.out = out
 
     device.out = out
     image_os.out = out
 
-    out.output()
+    out.clear()
 
     #Sysprep
     device.mount(False)
 
     #Sysprep
     device.mount(False)
index 99653d3..3992846 100644 (file)
@@ -48,6 +48,9 @@ class Output(object):
     def cleanup(self):
         pass
 
     def cleanup(self):
         pass
 
+    def clear(self):
+        pass
+
     def _get_progress(self):
         progress = self._Progress
         progress.output = self
     def _get_progress(self):
         progress = self._Progress
         progress.output = self
index c7b5a55..37022d5 100644 (file)
@@ -58,6 +58,12 @@ def success(msg, new_line=True, colored=True):
     output(msg, new_line, color)
 
 
     output(msg, new_line, color)
 
 
+def clear():
+    #clear the page
+    if sys.stderr.isatty():
+        sys.stderr.write('\033[H\033[2J')
+
+
 class SilentOutput(Output):
     pass
 
 class SilentOutput(Output):
     pass
 
@@ -78,6 +84,9 @@ class SimpleOutput(Output):
     def output(self, msg='', new_line=True):
         output(msg, new_line)
 
     def output(self, msg='', new_line=True):
         output(msg, new_line)
 
+    def clear(self):
+        clear()
+
 
 class OutputWthProgress(SimpleOutput):
     class _Progress(Bar):
 
 class OutputWthProgress(SimpleOutput):
     class _Progress(Bar):