Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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()
Exemplo n.º 8
0
 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()