Michael Pasternak has uploaded a new change for review. Change subject: cli: move error output to the terminal formatting ......................................................................
cli: move error output to the terminal formatting Change-Id: I2fc445fe4044bf391ace18f72ed043dfba0d283f Signed-off-by: Michael pasternak <[email protected]> --- M src/cli/context.py M src/ovirtcli/format/format.py M src/ovirtcli/shell/engineshell.py 3 files changed, 47 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/62/21262/1 diff --git a/src/cli/context.py b/src/cli/context.py index 40b8262..8845fe1 100644 --- a/src/cli/context.py +++ b/src/cli/context.py @@ -267,20 +267,24 @@ @param e: exception @param header: the error header """ - sys.stderr.write( - ColorHelper.colorize( - '\n++++++++++++++++++ %s ++++++++++++++++++\n%s\n\n' - % - ( - header, - self.__error_to_string(e) - ), + + text = self.formatter.format_terminal( + text=self.__error_to_string(e).strip(), + border='=', + termwidth=self.terminal._get_width(), + newline="\n", + header=header.strip() + ) + + text = ColorHelper.colorize( + text, ColorHelper.RED if self.mode != ExecutionMode.SCRIPT and self.interactive else None - ) ) + sys.stderr.write(text + "\n") + def __pint_warning(self, e): """ prints warning to stdout diff --git a/src/ovirtcli/format/format.py b/src/ovirtcli/format/format.py index 564d78f..967cb81 100644 --- a/src/ovirtcli/format/format.py +++ b/src/ovirtcli/format/format.py @@ -22,3 +22,31 @@ def format(self, context, result, scope=None): raise NotImplementedError + + def format_terminal(self, text, border, termwidth, newline="\n\n", header=None): + """ + formats (pretty) screen width adapted messages with border + + @param text: text to prin + @param border: border to use + @param termwidth: terminal width + @param newline: new line separator (default is '\n\n') + @param header: upper border header (default is None) + """ + offset = " " + space = " " + + introoffset = (termwidth / 2 - (len(text) / 2)) + borderoffset = (termwidth - 4) + + 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 + \ + offset + borderoffset * border + newline + return offset + borderoffset * border + newline + \ + introoffset * space + text + newline + \ + offset + borderoffset * border + newline + diff --git a/src/ovirtcli/shell/engineshell.py b/src/ovirtcli/shell/engineshell.py index 69e05a4..def916b 100644 --- a/src/ovirtcli/shell/engineshell.py +++ b/src/ovirtcli/shell/engineshell.py @@ -209,16 +209,12 @@ @param border: border to use (default is '+') @param newline: new line separator """ - offset = " " - space = " " - - termwidth = self.context.terminal._get_width() - introoffset = (termwidth / 2 - (len(text) / 2)) - borderoffset = (termwidth - 4) - - return offset + borderoffset * border + newline + \ - introoffset * space + text + newline + \ - offset + borderoffset * border + newline + return self.context.formatter.format_terminal( + text=text, + border=border, + termwidth=self.context.terminal._get_width(), + newline=newline + ) def __init_promt(self): self.__set_prompt(mode=PromptMode.Disconnected) -- To view, visit http://gerrit.ovirt.org/21262 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2fc445fe4044bf391ace18f72ed043dfba0d283f 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
