def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) oldcolors = None if self.hasmarkup and kw: handle = GetStdHandle(STD_OUTPUT_HANDLE) oldcolors = GetConsoleInfo(handle).wAttributes default_bg = oldcolors & 0x00F0 attr = default_bg if kw.pop('bold', False): attr |= FOREGROUND_INTENSITY if kw.pop('red', False): attr |= FOREGROUND_RED elif kw.pop('blue', False): attr |= FOREGROUND_BLUE elif kw.pop('green', False): attr |= FOREGROUND_GREEN elif kw.pop('yellow', False): attr |= FOREGROUND_GREEN | FOREGROUND_RED else: attr |= oldcolors & 0x0007 SetConsoleTextAttribute(handle, attr) write_out(self._file, msg) if oldcolors: SetConsoleTextAttribute(handle, oldcolors)
def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) oldcolors = None if self.hasmarkup and kw: handle = GetStdHandle(STD_OUTPUT_HANDLE) oldcolors = GetConsoleInfo(handle).wAttributes default_bg = oldcolors & 0x00F0 attr = default_bg if kw.pop('bold', False): attr |= FOREGROUND_INTENSITY if kw.pop('red', False): attr |= FOREGROUND_RED elif kw.pop('blue', False): attr |= FOREGROUND_BLUE elif kw.pop('green', False): attr |= FOREGROUND_GREEN elif kw.pop('yellow', False): attr |= FOREGROUND_GREEN|FOREGROUND_RED else: attr |= oldcolors & 0x0007 SetConsoleTextAttribute(handle, attr) write_out(self._file, msg) if oldcolors: SetConsoleTextAttribute(handle, oldcolors)
def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) oldcolors = None if self.hasmarkup and kw: handle = GetStdHandle(STD_OUTPUT_HANDLE) oldcolors = GetConsoleInfo(handle).wAttributes default_bg = oldcolors & 0x00F0 attr = default_bg if kw.pop('bold', False): attr |= FOREGROUND_INTENSITY if kw.pop('red', False): attr |= FOREGROUND_RED elif kw.pop('blue', False): attr |= FOREGROUND_BLUE elif kw.pop('green', False): attr |= FOREGROUND_GREEN elif kw.pop('yellow', False): attr |= FOREGROUND_GREEN|FOREGROUND_RED else: attr |= oldcolors & 0x0007 SetConsoleTextAttribute(handle, attr) try: self._file.write(msg) except UnicodeEncodeError: msg = msg.encode("unicode-escape").decode("ascii") self._file.write(msg) self._file.flush() if oldcolors: SetConsoleTextAttribute(handle, oldcolors)
def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) oldcolors = None if self.hasmarkup and kw: handle = GetStdHandle(STD_OUTPUT_HANDLE) oldcolors = GetConsoleInfo(handle).wAttributes default_bg = oldcolors & 0x00F0 attr = default_bg if kw.pop('bold', False): attr |= FOREGROUND_INTENSITY if kw.pop('red', False): attr |= FOREGROUND_RED elif kw.pop('blue', False): attr |= FOREGROUND_BLUE elif kw.pop('green', False): attr |= FOREGROUND_GREEN elif kw.pop('yellow', False): attr |= FOREGROUND_GREEN | FOREGROUND_RED else: attr |= oldcolors & 0x0007 SetConsoleTextAttribute(handle, attr) try: self._file.write(msg) except UnicodeEncodeError: msg = msg.encode("unicode-escape").decode("ascii") self._file.write(msg) self._file.flush() if oldcolors: SetConsoleTextAttribute(handle, oldcolors)
def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) if self.hasmarkup and kw: markupmsg = self.markup(msg, **kw) else: markupmsg = msg write_out(self._file, markupmsg)
def write(self, msg, **kw): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) if self.hasmarkup and kw: markupmsg = self.markup(msg, **kw) else: markupmsg = msg try: self._file.write(markupmsg) except UnicodeEncodeError: msg = msg.encode("unicode-escape").decode("ascii") self._file.write(msg) self._file.flush()