예제 #1
0
def get_console_position(handle):
    try:
        #handle.SetConsoleTextAttribute(FOREGROUND_BLUE)
        csbi = CONSOLE_SCREEN_BUFFER_INFO()
        GetConsoleScreenBufferInfo(handle, byref(csbi))
        cpos = csbi.dwCursorPosition
        #wait for input if this is a brand new console:
        return cpos.X and cpos.Y
    except:
        e = sys.exc_info()[1]
        code = -1
        try:
            code = e.winerror
        except:
            pass
        if code == errno.ENXIO:
            #ignore "no device" errors silently
            #(ie: happens if you redirect the command to a file)
            #we could also re-use the code above from "not_a_console()"
            pass
        else:
            try:
                print("error accessing console %s: %s" %
                      (errno.errorcode.get(e.errno, e.errno), e))
            except:
                print("error accessing console: %s" % e)
        return -1, -1
예제 #2
0
def set_wait_for_input():
    global _wait_for_input
    wfi = os.environ.get("XPRA_WAIT_FOR_INPUT")
    if wfi is not None:
        _wait_for_input = wfi != "0"
        return
    if is_wine():
        #don't wait for input when running under wine
        #(which usually does not popup a new shell window)
        _wait_for_input = False
        return
    if os.environ.get("TERM", "") == "xterm":
        #msys, cygwin and git bash environments don't popup a new shell window
        #and they all set TERM=xterm
        _wait_for_input = False
        return
    try:
        handle = GetStdHandle(STD_OUTPUT_HANDLE)
        #handle.SetConsoleTextAttribute(FOREGROUND_BLUE)
        csbi = CONSOLE_SCREEN_BUFFER_INFO()
        GetConsoleScreenBufferInfo(handle, byref(csbi))
        cpos = csbi.dwCursorPosition
        #wait for input if this is a brand new console:
        _wait_for_input = cpos.X == 0 and cpos.Y == 0
    except:
        e = sys.exc_info()[1]
        code = -1
        try:
            code = e.winerror
        except:
            pass
        if code == errno.ENXIO:
            #ignore "no device" errors silently
            #(ie: happens if you redirect the command to a file)
            #we could also re-use the code above from "not_a_console()"
            pass
        else:
            try:
                print("error accessing console %s: %s" %
                      (errno.errorcode.get(e.errno, e.errno), e))
            except:
                print("error accessing console: %s" % e)