From 4a847a9870e0eebb5efff3012e4eaaf5974735f1 Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Wed, 8 Aug 2012 16:13:57 +0300 Subject: [PATCH] Add a new clear method in the Output class In the cli output classes this method will clear terminal screen if the standard output is a terminal. --- image_creator/dialog_wizard.py | 2 +- image_creator/output/__init__.py | 3 +++ image_creator/output/cli.py | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/image_creator/dialog_wizard.py b/image_creator/dialog_wizard.py index 8e122a8..e26975e 100644 --- a/image_creator/dialog_wizard.py +++ b/image_creator/dialog_wizard.py @@ -177,7 +177,7 @@ def extract_image(session): device.out = out image_os.out = out - out.output() + out.clear() #Sysprep device.mount(False) diff --git a/image_creator/output/__init__.py b/image_creator/output/__init__.py index 99653d3..3992846 100644 --- a/image_creator/output/__init__.py +++ b/image_creator/output/__init__.py @@ -48,6 +48,9 @@ class Output(object): def cleanup(self): pass + def clear(self): + pass + def _get_progress(self): progress = self._Progress progress.output = self diff --git a/image_creator/output/cli.py b/image_creator/output/cli.py index c7b5a55..37022d5 100644 --- a/image_creator/output/cli.py +++ b/image_creator/output/cli.py @@ -58,6 +58,12 @@ def success(msg, new_line=True, colored=True): 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 @@ -78,6 +84,9 @@ class SimpleOutput(Output): def output(self, msg='', new_line=True): output(msg, new_line) + def clear(self): + clear() + class OutputWthProgress(SimpleOutput): class _Progress(Bar): -- 1.7.10.4