terminalwriter: inline function _update_chars_on_current_line
This commit is contained in:
parent
8e04d35a33
commit
d9b43647b7
|
@ -157,7 +157,13 @@ class TerminalWriter:
|
||||||
|
|
||||||
def write(self, msg: str, **kw: bool) -> None:
|
def write(self, msg: str, **kw: bool) -> None:
|
||||||
if msg:
|
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:
|
if self.hasmarkup and kw:
|
||||||
markupmsg = self.markup(msg, **kw)
|
markupmsg = self.markup(msg, **kw)
|
||||||
|
@ -166,15 +172,6 @@ class TerminalWriter:
|
||||||
self._file.write(markupmsg)
|
self._file.write(markupmsg)
|
||||||
self._file.flush()
|
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:
|
def line(self, s: str = "", **kw: bool) -> None:
|
||||||
self.write(s, **kw)
|
self.write(s, **kw)
|
||||||
self.write("\n")
|
self.write("\n")
|
||||||
|
|
Loading…
Reference in New Issue