jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] improvements for user interface

- make ABCUIC.flush() an abstract method
- define flush() for buffer_interface.UI which just calls clear()
- remove terminal_interface_base.UI.argvu() which is the same as in ABCUIC
- make UnixUI.make_unix_bg_color() a static method
- remove UnixUI._write() which is the same as in terminal_interface_base.UI

Change-Id: Ia5a695aa2dfb21815e5b8f3e4ead5f0e577d3d3a
---
M pywikibot/userinterfaces/_interface_base.py
M pywikibot/userinterfaces/buffer_interface.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/terminal_interface_unix.py
4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/pywikibot/userinterfaces/_interface_base.py b/pywikibot/userinterfaces/_interface_base.py
index 14eb2b6..914f382 100644
--- a/pywikibot/userinterfaces/_interface_base.py
+++ b/pywikibot/userinterfaces/_interface_base.py
@@ -31,6 +31,7 @@
"""
return list(sys.argv)

+ @abstractmethod
def flush(self) -> None:
"""Flush cached output.

diff --git a/pywikibot/userinterfaces/buffer_interface.py b/pywikibot/userinterfaces/buffer_interface.py
index 0c1b675..b12ba02 100755
--- a/pywikibot/userinterfaces/buffer_interface.py
+++ b/pywikibot/userinterfaces/buffer_interface.py
@@ -26,6 +26,10 @@
self.log_handler = logging.handlers.QueueHandler(self._buffer)
self.log_handler.setLevel(VERBOSE if config.verbose_output else INFO)

+ def flush(self) -> None:
+ """Flush cached output."""
+ self.clear()
+
def init_handlers(self, root_logger, *args, **kwargs) -> None:
"""Initialize the handlers for user output."""
root_logger.addHandler(self.log_handler)
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 7417155..21c4c87 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -130,7 +130,7 @@
warnings_logger.addHandler(warning_handler)

def encounter_color(self, color, target_stream):
- """Handle the next color encountered."""
+ """Abstract method to handle the next color encountered."""
raise NotImplementedError('The {} class does not support '
'colors.'.format(self.__class__.__name__))

@@ -507,10 +507,6 @@
editor = gui.EditBoxWindow()
return editor.edit(text, jumpIndex=jumpIndex, highlight=highlight)

- def argvu(self):
- """Return copy of argv."""
- return list(self.argv)
-

class TerminalHandler(logging.StreamHandler):

diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py b/pywikibot/userinterfaces/terminal_interface_unix.py
index 4174ea5..27cd70a 100755
--- a/pywikibot/userinterfaces/terminal_interface_unix.py
+++ b/pywikibot/userinterfaces/terminal_interface_unix.py
@@ -38,7 +38,8 @@
"""Return that the target stream supports colors."""
return True

- def make_unix_bg_color(self, color):
+ @staticmethod
+ def make_unix_bg_color(color):
"""Obtain background color from foreground color."""
code = re.search(r'(?<=\[)\d+', color).group()
return chr(27) + '[' + str(int(code) + 10) + 'm'
@@ -51,7 +52,3 @@
if bg is not None:
bg = unixColors[bg]
self._write(self.make_unix_bg_color(bg), target_stream)
-
- def _write(self, text, target_stream) -> None:
- """Optionally encode and write the text to the target stream."""
- target_stream.write(text)

To view, visit change 769669. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia5a695aa2dfb21815e5b8f3e4ead5f0e577d3d3a
Gerrit-Change-Number: 769669
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged