code: def write(
      self, msg: str, *, flush: bool = False, **markup: bool
  ) -> None:
      if msg:
          current_line = msg.rsplit("\n", 1)[-1]
          if "\n" in msg:
              self._current_line = current_line
          else:
              self._current_line += current_line
  
          msg = self.markup(msg, **markup)
  
          try:
              self._file.write(msg)
          except UnicodeEncodeError:
              # Some environments don't support printing general Unicode
              # strings, due to misconfiguration or otherwise; in that case,
              # print the string escaped to ASCII.
              # When the Unicode situation improves we should consider
              # letting the error propagate instead of masking it (see #7475
              # for one brief attempt).
              msg = msg.encode("unicode-escape").decode("ascii")
              self._file.write(msg)
  
          if flush:
              self.flush()
  
imports: import os
  import shutil
  import sys
  from typing import Optional
  from typing import Sequence
  from typing import TextIO
  from .wcwidth import wcswidth
  from _pytest.compat import final
label_desc: Use image node_id 7 for calling the TerminalWriter obj's underlying member method code with example usage: obj.write(msg) without return types