terminalwriter: inline function _update_chars_on_current_line

This commit is contained in:
Ran Benita 2020-04-29 17:38:16 +03:00
parent 8e04d35a33
commit d9b43647b7
1 changed files with 7 additions and 10 deletions

View File

@ -157,7 +157,13 @@ class TerminalWriter:
def write(self, msg: str, **kw: bool) -> None:
if msg:
self._update_chars_on_current_line(msg)
current_line = msg.rsplit("\n", 1)[-1]
if "\n" in msg:
self._chars_on_current_line = len(current_line)
self._width_of_current_line = get_line_width(current_line)
else:
self._chars_on_current_line += len(current_line)
self._width_of_current_line += get_line_width(current_line)
if self.hasmarkup and kw:
markupmsg = self.markup(msg, **kw)
@ -166,15 +172,6 @@ class TerminalWriter:
self._file.write(markupmsg)
self._file.flush()
def _update_chars_on_current_line(self, text: str) -> None:
current_line = text.rsplit("\n", 1)[-1]
if "\n" in text:
self._chars_on_current_line = len(current_line)
self._width_of_current_line = get_line_width(current_line)
else:
self._chars_on_current_line += len(current_line)
self._width_of_current_line += get_line_width(current_line)
def line(self, s: str = "", **kw: bool) -> None:
self.write(s, **kw)
self.write("\n")