Esempio n. 1
0
    def __init__(self, newbuffer=0):
        if newbuffer:
            self.hout = self.CreateConsoleScreenBuffer(
                GENERIC_READ | GENERIC_WRITE, 0, None, 1, None)
            self.SetConsoleActiveScreenBuffer(self.hout)
        else:
            self.hout = self.GetStdHandle(STD_OUTPUT_HANDLE)
        self.hin = self.GetStdHandle(STD_INPUT_HANDLE)
        self.inmode = DWORD(0)
        self.GetConsoleMode(self.hin, byref(self.inmode))
        self.SetConsoleMode(self.hin, 15)
        info = CONSOLE_SCREEN_BUFFER_INFO()
        self.GetConsoleScreenBufferInfo(self.hout, byref(info))
        self.attr = info.wAttributes
        self.saveattr = info.wAttributes
        self.defaultstate = AnsiState()
        self.defaultstate.winattr = info.wAttributes
        self.ansiwriter = AnsiWriter(self.defaultstate)
        background = self.attr & 240
        for escape in self.escape_to_color:
            if self.escape_to_color[escape] is not None:
                self.escape_to_color[escape] |= background

        log('initial attr=%x' % self.attr)
        self.softspace = 0
        self.serial = 0
        self.pythondll = CDLL('python%s%s' % (sys.version[0], sys.version[2]))
        self.pythondll.PyMem_Malloc.restype = c_size_t
        self.pythondll.PyMem_Malloc.argtypes = [c_size_t]
        self.inputHookPtr = c_void_p.from_address(
            addressof(self.pythondll.PyOS_InputHook)).value
        setattr(Console, 'PyMem_Malloc', self.pythondll.PyMem_Malloc)
        return
Esempio n. 2
0
    def __init__(self, newbuffer=0):
        """Initialize the Console object.

        newbuffer=1 will allocate a new buffer so the old content will be restored
        on exit.
        """
        # Do I need the following line? It causes a console to be created whenever
        # readline is imported into a pythonw application which seems wrong. Things
        # seem to work without it...
        # self.AllocConsole()

        if newbuffer:
            self.hout = self.CreateConsoleScreenBuffer(
                GENERIC_READ | GENERIC_WRITE, 0, None, 1, None
            )
            self.SetConsoleActiveScreenBuffer(self.hout)
        else:
            self.hout = self.GetStdHandle(STD_OUTPUT_HANDLE)

        self.hin = self.GetStdHandle(STD_INPUT_HANDLE)
        self.inmode = DWORD(0)
        self.GetConsoleMode(self.hin, byref(self.inmode))
        self.SetConsoleMode(self.hin, 0xF)
        info = CONSOLE_SCREEN_BUFFER_INFO()
        self.GetConsoleScreenBufferInfo(self.hout, byref(info))
        self.attr = info.wAttributes
        self.saveattr = info.wAttributes  # remember the initial colors
        self.defaultstate = AnsiState()
        self.defaultstate.winattr = info.wAttributes
        self.ansiwriter = AnsiWriter(self.defaultstate)

        background = self.attr & 0xF0
        for escape in self.escape_to_color:
            if self.escape_to_color[escape] is not None:
                self.escape_to_color[escape] |= background
        log("initial attr=%x" % self.attr)
        self.softspace = 0  # this is for using it as a file-like object
        self.serial = 0

        self.pythondll = ctypes.pythonapi
        self.inputHookPtr = c_void_p.from_address(
            addressof(self.pythondll.PyOS_InputHook)
        ).value

        if sys.version_info[:2] > (3, 4):
            self.pythondll.PyMem_RawMalloc.restype = c_size_t
            self.pythondll.PyMem_Malloc.argtypes = [c_size_t]
            setattr(Console, "PyMem_Malloc", self.pythondll.PyMem_RawMalloc)
        else:
            self.pythondll.PyMem_Malloc.restype = c_size_t
            self.pythondll.PyMem_Malloc.argtypes = [c_size_t]
            setattr(Console, "PyMem_Malloc", self.pythondll.PyMem_Malloc)
Esempio n. 3
0
    def __init__(self, newbuffer=0):
        '''Initialize the Console object.

        newbuffer=1 will allocate a new buffer so the old content will be restored
        on exit.
        '''
        #Do I need the following line? It causes a console to be created whenever
        #readline is imported into a pythonw application which seems wrong. Things
        #seem to work without it...
        #self.AllocConsole()

        if newbuffer:
            self.hout = self.CreateConsoleScreenBuffer(
                GENERIC_READ | GENERIC_WRITE, 0, None, 1, None)
            self.SetConsoleActiveScreenBuffer(self.hout)
        else:
            self.hout = self.GetStdHandle(STD_OUTPUT_HANDLE)

        self.hin = self.GetStdHandle(STD_INPUT_HANDLE)
        self.inmode = c_int(0)
        self.GetConsoleMode(self.hin, byref(self.inmode))
        self.SetConsoleMode(self.hin, 0xf)
        info = CONSOLE_SCREEN_BUFFER_INFO()
        self.GetConsoleScreenBufferInfo(self.hout, byref(info))
        self.attr = info.wAttributes
        self.saveattr = info.wAttributes  # remember the initial colors

        self.defaultstate = AnsiState()
        self.defaultstate.winattr = info.wAttributes
        self.ansiwriter = AnsiWriter(self.defaultstate)
        #        self.ansiwriter.defaultstate.bold=False

        background = self.attr & 0xf0
        for escape in self.escape_to_color:
            if self.escape_to_color[escape] is not None:
                self.escape_to_color[escape] |= background
        log('initial attr=%x' % self.attr)
        self.softspace = 0  # this is for using it as a file-like object
        self.serial = 0

        self.pythondll = CDLL('python%s%s' % (sys.version[0], sys.version[2]))
        self.inputHookPtr = c_int.from_address(
            addressof(self.pythondll.PyOS_InputHook)).value
        setattr(Console, 'PyMem_Malloc', self.pythondll.PyMem_Malloc)
Esempio n. 4
0
    def __init__(self, newbuffer=0):
        '''Initialize the Console object.

        newbuffer=1 will allocate a new buffer so the old content will be restored
        on exit.
        '''
        #Do I need the following line? It causes a console to be created whenever
        #readline is imported into a pythonw application which seems wrong. Things
        #seem to work without it...
        #self.AllocConsole()

        if newbuffer:
            self.hout = self.CreateConsoleScreenBuffer(
                GENERIC_READ | GENERIC_WRITE, 0, None, 1, None)
            self.SetConsoleActiveScreenBuffer(self.hout)
        else:
            self.hout = self.GetStdHandle(STD_OUTPUT_HANDLE)

        self.hin = self.GetStdHandle(STD_INPUT_HANDLE)
        self.inmode = DWORD(0)
        self.GetConsoleMode(self.hin, byref(self.inmode))
        self.SetConsoleMode(self.hin, 0xf)
        info = CONSOLE_SCREEN_BUFFER_INFO()
        self.GetConsoleScreenBufferInfo(self.hout, byref(info))
        self.attr = info.wAttributes
        self.saveattr = info.wAttributes  # remember the initial colors
        self.defaultstate = AnsiState()
        self.defaultstate.winattr = info.wAttributes
        self.ansiwriter = AnsiWriter(self.defaultstate)

        background = self.attr & 0xf0
        for escape in self.escape_to_color:
            if self.escape_to_color[escape] is not None:
                self.escape_to_color[escape] |= background
        log('initial attr=%x' % self.attr)
        self.softspace = 0  # this is for using it as a file-like object
        self.serial = 0
        #
        try:
            IMP = sys._mercurial[0]
        except AttributeError:
            IMP = sys._git[0]

        # print('\n\n\npython%s%s' % (sys.version[0], sys.version[2]), "\n\n", IMP)
        if IMP.lower() == "pypy":
            if sys.winver > "3":
                nameLib = "libpypy3-c"
            else:
                nameLib = "libpypy-c"

            self.pythondll = CDLL(nameLib)
        else:
            self.pythondll = ctypes.pythonapi

        if IMP.lower() == "pypy":
            self.inputHookPtr = None
            # print("Falta resolver la vinculación con 'PyOS_InputHook'")
            # setattr(Console, 'PyMem_Malloc', self.pythondll.PyPyMem_Malloc)

            # print("PYPY it´s runing!!!\n\n\n")
            if sys.winver > "3":
                self.pythondll.PyPyMem_Malloc.restype = c_size_t
                self.pythondll.PyPyMem_Malloc.argtypes = [c_size_t]
        elif sys.version_info[:2] > (3, 4):  # Common Python3.4++
            self.pythondll.PyMem_RawMalloc.restype = c_size_t
            self.pythondll.PyMem_Malloc.argtypes = [c_size_t]

            self.inputHookPtr = \
                c_void_p.from_address(addressof(self.pythondll.PyOS_InputHook)).value
            setattr(Console, 'PyMem_Malloc', self.pythondll.PyMem_RawMalloc)
        else:  # Common Python3.4--
            self.pythondll.PyMem_Malloc.restype = c_size_t
            self.pythondll.PyMem_Malloc.argtypes = [c_size_t]

            self.inputHookPtr = \
                c_void_p.from_address(addressof(self.pythondll.PyOS_InputHook)).value
            setattr(Console, 'PyMem_Malloc', self.pythondll.PyMem_Malloc)