Esempio n. 1
0
def pair_content(pair):
    _ensure_initialised_color()
    f = ffi.new("short *")
    b = ffi.new("short *")
    if lib.pair_content(pair, f, b) == lib.ERR:
        raise error("Argument 1 was out of range. (1..COLOR_PAIRS-1)")
    return (f, b)
Esempio n. 2
0
def pair_content(pair):
    _ensure_initialised_color()
    f = ffi.new("short *")
    b = ffi.new("short *")
    if lib.pair_content(pair, f, b) == lib.ERR:
        raise error("Argument 1 was out of range. (1..COLOR_PAIRS-1)")
    return (f, b)
 def get_wch(self, *args):
     wch = ffi.new("int[1]")
     if len(args) == 0:
         val = lib.wget_wch(self._win, wch)
     elif len(args) == 2:
         val = lib.mvwget_wch(self._win, *args, wch)
     else:
         raise error("get_wch requires 0 or 2 arguments")
     _check_ERR(val, "get_wch")
     return wch[0]
Esempio n. 4
0
    def instr(self, y, x, n=1023):
        n = min(n, 1023)
        buf = ffi.new("char[1024]")  # /* This should be big enough.. I hope */
        if y is None:
            code = lib.winnstr(self._win, buf, n)
        else:
            code = lib.mvwinnstr(self._win, y, x, buf, n)

        if code == lib.ERR:
            return ""
        return ffi.string(buf)
Esempio n. 5
0
    def instr(self, y, x, n=1023):
        n = min(n, 1023)
        buf = ffi.new("char[1024]")  # /* This should be big enough.. I hope */
        if y is None:
            code = lib.winnstr(self._win, buf, n)
        else:
            code = lib.mvwinnstr(self._win, y, x, buf, n)

        if code == lib.ERR:
            return ""
        return ffi.string(buf)
Esempio n. 6
0
    def instr(self, y, x, n=1023):
        n = min(n, 1023)
        if n < 0:
            raise ValueError("'n' must be nonnegative")
        buf = ffi.new("char[1024]")  # /* This should be big enough.. I hope */
        if y is None:
            code = lib.winnstr(self._win, buf, n)
        else:
            code = lib.mvwinnstr(self._win, y, x, buf, n)

        if code == lib.ERR:
            return ""
        return ffi.string(buf)
Esempio n. 7
0
def setupterm(term=None, fd=-1):
    if fd == -1:
        # XXX: Check for missing stdout here?
        fd = sys.stdout.fileno()

    if _initialised_setupterm:
        return None

    if term is None:
        term = ffi.NULL
    err = ffi.new("int *")
    if lib.setupterm(term, fd, err) == lib.ERR:
        err = err[0]
        if err == 0:
            raise error("setupterm: could not find terminal")
        elif err == -1:
            raise error("setupterm: could not find terminfo database")
        else:
            raise error("setupterm: unknown error")

    globals()["_initialised_setupterm"] = True
    return None
Esempio n. 8
0
def setupterm(term=None, fd=-1):
    if fd == -1:
        # XXX: Check for missing stdout here?
        fd = sys.stdout.fileno()

    if _initialised_setupterm:
        return None

    if term is None:
        term = ffi.NULL
    err = ffi.new("int *")
    if lib.setupterm(term, fd, err) == lib.ERR:
        err = err[0]
        if err == 0:
            raise error("setupterm: could not find terminal")
        elif err == -1:
            raise error("setupterm: could not find terminfo database")
        else:
            raise error("setupterm: unknown error")

    globals()["_initialised_setupterm"] = True
    return None
Esempio n. 9
0
 def mousemask(newmask):
     _ensure_initialised()
     oldmask = ffi.new("mmask_t *")
     availmask = lib.mousemask(newmask, oldmask)
     return (availmask, oldmask)
Esempio n. 10
0
 def ungetmouse(id, x, y, z, bstate):
     _ensure_initialised()
     mevent = ffi.new("MEVENT *")
     mevent.id, mevent.x, mevent.y, mevent.z, mevent.bstate = (
         id, x, y, z, bstate)
     return _check_ERR(lib.ungetmouse(mevent), "ungetmouse")
Esempio n. 11
0
 def getmouse():
     _ensure_initialised()
     mevent = ffi.new("MEVENT *")
     _check_ERR(lib.getmouse(mevent), "getmouse")
     return (mevent.id, mevent.x, mevent.y, mevent.z, mevent.bstate)
Esempio n. 12
0
def getsyx():
    _ensure_initialised()
    yx = ffi.new("int[2]")
    lib._m_getsyx(yx)
    return (yx[0], yx[1])
Esempio n. 13
0
def color_content(color):
    _ensure_initialised_color()
    r, g, b = ffi.new("short *"), ffi.new("short *"), ffi.new("short *")
    if lib.color_content(color, r, g, b) == lib.ERR:
        raise error("Argument 1 was out of range. Check value of COLORS.")
    return (r[0], g[0], b[0])
Esempio n. 14
0
 def mousemask(newmask):
     _ensure_initialised()
     oldmask = ffi.new("mmask_t *")
     availmask = lib.mousemask(newmask, oldmask)
     return (availmask, oldmask)
Esempio n. 15
0
 def ungetmouse(id, x, y, z, bstate):
     _ensure_initialised()
     mevent = ffi.new("MEVENT *")
     mevent.id, mevent.x, mevent.y, mevent.z, mevent.bstate = (id, x, y, z,
                                                               bstate)
     return _check_ERR(lib.ungetmouse(mevent), "ungetmouse")
Esempio n. 16
0
 def getmouse():
     _ensure_initialised()
     mevent = ffi.new("MEVENT *")
     _check_ERR(lib.getmouse(mevent), "getmouse")
     return (mevent.id, mevent.x, mevent.y, mevent.z, mevent.bstate)
Esempio n. 17
0
def getsyx():
    _ensure_initialised()
    yx = ffi.new("int[2]")
    lib._m_getsyx(yx)
    return (yx[0], yx[1])
Esempio n. 18
0
def color_content(color):
    _ensure_initialised_color()
    r, g, b = ffi.new("short *"), ffi.new("short *"), ffi.new("short *")
    if lib.color_content(color, r, g, b) == lib.ERR:
        raise error("Argument 1 was out of range. Check value of COLORS.")
    return (r[0], g[0], b[0])