Michael Pasternak has uploaded a new change for review.

Change subject: cli: do not align to middle multi-lined text
......................................................................

cli: do not align to middle multi-lined text

Change-Id: Ib90316a466fead5b9a888ced72e3c6b0a097f64d
Signed-off-by: Michael pasternak <[email protected]>
---
M src/ovirtcli/format/format.py
1 file changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/64/21264/1

diff --git a/src/ovirtcli/format/format.py b/src/ovirtcli/format/format.py
index 967cb81..4aec4de 100644
--- a/src/ovirtcli/format/format.py
+++ b/src/ovirtcli/format/format.py
@@ -23,7 +23,7 @@
     def format(self, context, result, scope=None):
         raise NotImplementedError
 
-    def format_terminal(self, text, border, termwidth, newline="\n\n", 
header=None):
+    def format_terminal(self, text, border, termwidth, newline="\n\n", 
header=None, offsettext=True):
         """
         formats (pretty) screen width adapted messages with border
         
@@ -32,21 +32,28 @@
         @param termwidth: terminal width
         @param newline: new line separator (default is '\n\n')
         @param header: upper border header (default is None)
+        @param offsettext: align the text to middle of the screen (default 
True)
         """
+
+        linlebreak = '\r\n'
         offset = "  "
         space = " "
-
         introoffset = (termwidth / 2 - (len(text) / 2))
         borderoffset = (termwidth - 4)
+
+        # align multilined output
+        if text.find(linlebreak) <> -1 :
+            offsettext = False
+            text = offset + text.replace(linlebreak, (linlebreak + offset))
 
         if (header):
             headeroffset = (borderoffset / 2 - ((len(header) / 2)))
             oddoffset = 0 if termwidth & 1 != 0 else 1
             return offset + headeroffset * border + space + header + space + \
                    (headeroffset - len(offset) - oddoffset) * border + newline 
+ \
-                   introoffset * space + text + newline + \
+                   ((introoffset * space)  if offsettext else "") + text + 
newline + \
                    offset + borderoffset * border + newline
         return offset + borderoffset * border + newline + \
-               introoffset * space + text + newline + \
+               ((introoffset * space) if offsettext else "") + text + newline 
+ \
                offset + borderoffset * border + newline
 


-- 
To view, visit http://gerrit.ovirt.org/21264
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib90316a466fead5b9a888ced72e3c6b0a097f64d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Michael Pasternak <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to