pike.git / lib / modules / Stdio.pmod / Terminfo.pmod

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:1: - // $Id: Terminfo.pmod,v 1.11 2000/09/28 03:39:13 hubbe Exp $ + // $Id: Terminfo.pmod,v 1.12 2001/10/23 20:10:12 nilsson Exp $   #pike __REAL_VERSION__         #if constant(thread_create)   #define LOCK object m_key = mutex->lock()   #define UNLOCK destruct(m_key)   #define MUTEX static private object(Thread.Mutex) mutex = Thread.Mutex();   #else   #define LOCK   #define UNLOCK
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:136:       string put(string cap, mixed ... args)    {    string str = tgetstr(cap);    string tstr = str && tparam(str, @args);    return tstr && tputs(tstr);    }      }    + //! Termcap terminal description object.   class Termcap {       inherit TermMachine;    -  +  //!    array(string) aliases; -  +     static object(Termcap) parent;    -  +  //! Put termcap string    string tputs(string s)    {    // Delay stuff completely ignored...    sscanf(s, "%*d%s", s);    return s;    }       private static multiset(string) load_cap(string en)    {    string br=":";
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:238:    }    else // wierd    {    // ignore    }    }       return clears;    }    +  //!    void create(string cap, object(TermcapDB)|void tcdb, int|void maxrecurse)    {    int i=0;    while((i=search(cap, "\\\n", i))>=0) {    string capr;    if(2!=sscanf(cap[i..], "\\\n%*[ \t\r]%s", capr))    break;    cap = cap[..i-1]+capr;    }    multiset(string) clears = load_cap(cap);
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:262:    load(map->tc, maxrecurse? (maxrecurse-1):25);    if(!parent)    error("Termcap: can't find parent terminal \"%s\"\n", map->tc);    map = parent->map | map;    }    map |= mkmapping(indices(clears), allocate(sizeof(clears)));    }   }       -  + //! Terminfo terminal description object   class Terminfo {       inherit TermMachine;    -  +  //!    array(string) aliases;       static private constant boolnames =    ({ "bw","am","xb","xs","xn","eo","gn","hc","km","hs","in","da","db","mi",    "ms","os","es","xt","hz","ul","xo","nx","5i","HC","NR","NP","ND","cc",    "ut","hl","YA","YB","YC","YD","YE","YF","YG" });    static private constant numnames =    ({ "co","it","li","lm","sg","pb","vt","ws","Nl","lh","lw","ma","MW","Co",    "pa","NC","Ya","Yb","Yc","Yd","Ye","Yf","Yg","Yh","Yi","Yj","Yk","Yl",    "Ym","Yn","BT","Yo","Yp" });
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:308:    "DI","QD","TO","PU","fh","PA","WA","u0","u1","u2","u3","u4","u5","u6",    "u7","u8","u9","op","oc","Ic","Ip","sp","Sf","Sb","ZA","ZB","ZC","ZD",    "ZE","ZF","ZG","ZH","ZI","ZJ","ZK","ZL","ZM","ZN","ZO","ZP","ZQ","ZR",    "ZS","ZT","ZU","ZV","ZW","ZX","ZY","ZZ","Za","Zb","Zc","Zd","Ze","Zf",    "Zg","Zh","Zi","Zj","Zk","Zl","Zm","Zn","Zo","Zp","Zq","Zr","Zs","Zt",    "Zu","Zv","Zw","Zx","Zy","Km","Mi","RQ","Gm","AF","AB","xl","dv","ci",    "s0","s1","s2","s3","ML","MT","Xy","Zz","Yv","Yw","Yx","Yy","Yz","YZ",    "S1","S2","S3","S4","S5","S6","S7","S8","Xh","Xl","Xo","Xr","Xt","Xv",    "sA","sL" });    +  //! @fixme +  //! Document this function    string tputs(string s)    {    // Delay stuff completely ignored...    string pre, post;    while (3==sscanf(s, "%s$<%*[0-9.]>%s", pre, post))    s = pre+post;    return s;    }       static private string swab(string s)
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:379:    mapping(string:string) tmp = mkmapping(strnames[..sizeof(strarr)-1],    strarr);    foreach (strnames[..sizeof(strarr)-1], string name)    if (!tmp[name])    m_delete(tmp, name);    map += tmp;    }    return 1;    }    +  //!    void create(string filename)    {    object(Stdio.File) f = Stdio.File();    if (!f->open(filename, "r"))    error("Terminfo: unable to open terminfo file \"%s\"\n", filename);    int r = load_cap(f);    f->close();    if (!r)    error("Terminfo: unparsable terminfo file \"%s\"\n", filename);    }
pike.git/lib/modules/Stdio.pmod/Terminfo.pmod:736:      object(TerminfoDB) defaultTerminfoDB()   {    object(TerminfoDB) tidb;    LOCK;    catch { tidb = defterminfo || (defterminfo = TerminfoDB()); };    UNLOCK;    return tidb;   }    + //! Returns the terminal description object for @[term] from the + //! systems termcap database. Returns 0 if not found. + //! + //! @seealso + //! Stdio.Terminfo.getTerm, Stdio.Terminfo.getTerminfo   object(Termcap) getTermcap(string term)   {    object(TermcapDB) tcdb = defaultTermcapDB();    return tcdb && tcdb[term];   }    -  + //! Returns the terminal description object for @[term] from the + //! systems terminfo database. Returns 0 if not found. + //! + //! @seealso + //! Stdio.Terminfo.getTerm, Stdio.Terminfo.getTermcap   object(Terminfo) getTerminfo(string term)   {    object(TerminfoDB) tidb = defaultTerminfoDB();    return tidb && tidb[term];   }    -  + //! Returns an object describing the terminal term. If term is not specified, it will + //! default to @[getenv("TERM")] or if that fails to "dumb". + //! + //! Lookup of terminal information will first be done in the systems terminfo + //! database, and if that fails in the termcap database. If neither database exists, a + //! hardcoded entry for "dumb" will be used. + //! + //! @seealso + //! Stdio.Terminfo.getTerminfo, Stdio.Terminfo.getTermcap, Stdio.getFallbackTerm   object(Termcap) getTerm(string|void term)   {    if (!term) {    object(Termcap) t = defterm;    if (!t)    {    string tc = [string]getenv("TERMCAP");    t = (tc && sizeof(tc) && tc[0]!='/'?    Termcap(tc) : getTerm(getenv("TERM")||"dumb"));    LOCK;    if (!defterm)    defterm = t;    UNLOCK;    }    return t;    }    return getTerminfo(term) || getTermcap(term) || getFallbackTerm(term);   }    -  + //! Returns an object describing the fallback terminal for the terminal + //! @[term]. This is usually equvivalent to @[Stdio.Terminfo.getTerm("dumb")]. + //! + //! @seealso + //! Stdio.Terminfo.getTerm   static object(Termcap) getFallbackTerm(string term)   {    return (term=="dumb"? Termcap("dumb:\\\n\t:am:co#80:do=^J:") :    getTerm("dumb"));   }