Jeremy Thurgood avatar Jeremy Thurgood committed 9793a0c

Implement enough extra bits to make pypy REPL and Twisted trial happy.

Comments (0)

Files changed (1)

 
 int setupterm(char *term, int fildes, int *errret);
 
+int tigetflag(char *);
+int tigetnum(char *);
+char *tigetstr(char *);
+char *tparm (char *, ...);
+
 int cbreak(void);
 int nocbreak(void);
 int echo(void);
 
 initscr = Window
 
+_setupterm_called = False
 
-def setupterm(term=ffi.NULL, fd=-1):
+
+def _ensure_setupterm_called():
+    if not _setupterm_called:
+        raise error("must call (at least) setupterm() first")
+
+
+def setupterm(term=None, fd=-1):
+    if term is None:
+        term = ffi.NULL
     if fd < 0:
         import sys
         fd = sys.stdout.fileno()
         else:
             s = "setupterm: unknown error %d" % err[0]
         raise error(s)
+    global _setupterm_called
+    _setupterm_called = True
+
+
+def tigetflag(capname):
+    _ensure_setupterm_called()
+    return lib.tigetflag(capname)
+
+
+def tigetnum(capname):
+    _ensure_setupterm_called()
+    return lib.tigetnum(capname)
+
+
+def tigetstr(capname):
+    _ensure_setupterm_called()
+    out = lib.tigetstr(capname)
+    if out == ffi.NULL:
+        return None
+    return ffi.string(out)
+
+
+def tparm(name, *args):
+    _ensure_setupterm_called()
+    cargs = [ffi.cast("long", arg) for arg in args]
+    return ffi.string(lib.tparm(name, *cargs))
+
 
 def color_pair(n):
     return n << 8
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.