示例#1
0
文件: cap.c 项目: tamo/libfep
const char *
_fep_cap_get_string (const char *name)
{
  int i;
  for (i = 0; i < SIZEOF (caps); i++)
    {
      if (strcmp (name, caps[i].name) == 0)
	return tigetstr (caps[i].capname);
    }
  fprintf (stderr, "unknown terminfo variable %s\n", name);
  return NULL;
}
示例#2
0
文件: lurker.c 项目: wader/lurker
/* use terminfo database to generate a string that clears current line and move
 * cursor to left side of screen */
char *generate_clear_line_string()
{
    char *s, *m, *c;
    
    /* init terminal type */
    if(setupterm(NULL, STDOUT_FILENO, NULL) == ERR)
        return NULL;
    /* carriage return, cursor to left of screen */
    m = tigetstr("cr");
    if(m == NULL)
        return NULL;
    /* clear from cursor to end of line */
    c = tigetstr("el");
    if(c == NULL)
        return NULL;
    /* concatinate */
    if(asprintf(&s, "%s%s", m, c) == -1)
        return NULL;

    return s;
}
示例#3
0
// TODO: this assumes string = byte array vm setup
char *
sc_keySequenceOf(char *keyName)
{
  char *keySequence = tigetstr(keyName);
  if ((int)keySequence == -1 || (int)keySequence == 0)
    return FALSE;

  if (strlen(keySequence) > 1 && keySequence[0] == 27)
    keySequence += 1;

  return keySequence;
}
示例#4
0
文件: cal.c 项目: Kaligule/util-linux
static const char *my_tgetstr(char *ss)
{
	const char *ret = NULL;

#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW)
	if (has_term)
		ret = tigetstr(ss);
#endif
	if (!ret || ret == (char *)-1)
		return "";
	return ret;
}
示例#5
0
int	my_set_term()
{
  int	err;
  int	ret;
  char	*s;

  if ((err = setupterm(NULL, 1, &ret)) == ERR)
    return (1);
  if ((s = tigetstr("smkx")) == (char *)-1)
    return (2);
  putp(s);
  return (0);
}
示例#6
0
/*
 * TermInfo#tigetstr(capname) => str
 *
 * TermInfo#tigetstr returns a string capability specified by capname.
 *
 * The return value should be printed after tputs is applied.
 * Also tparm should be applied if it has parameters.
 *
 *   io.print ti.tputs(ti.tparm(ti.tigetstr("cuf"), 2))
 *
 * Note that "cuf" means "cursor forward".
 */
static VALUE
rt_tigetstr(VALUE self, VALUE v_capname)
{
  char *ret;
  setup(self);
  ret = tigetstr(StringValueCStr(v_capname));
  if (ret == (char*)-1) {
    rb_raise(eTermInfoError, "not a string capability");
  }
  if (ret == 0) {
    rb_raise(eTermInfoError, "canceled or absent string capability");
  }
  return rb_str_new2(ret);
}
示例#7
0
int use_terminfo_color(int ansicolor,int boldp){
	if(use_terminfo){
		const char *attrstr = boldp ? "bold" : "sgr0";
		const char *color,*attr;
		char *setaf;

		if((attr = tigetstr(attrstr)) == NULL){
			bitch("Couldn't get terminfo %s\n",attrstr);
			return -1;
		}
		putp(attr);
		if((setaf = tigetstr("setaf")) == NULL){
			bitch("Couldn't get terminfo setaf\n");
			return -1;
		}
		if((color = tparm(setaf,ansicolor)) == NULL){
			bitch("Couldn't get terminfo color %d\n",ansicolor);
			return -1;
		}
		putp(color);
	}
	return 0;
}
示例#8
0
文件: prstat.c 项目: andreiw/polaris
static void
ldtermcap()
{
	int err;
	if (setupterm(NULL, STDIN_FILENO, &err) == ERR) {
		switch (err) {
		case 0:
			Warn(gettext("failed to load terminal info, "
			    "defaulting to -c option\n"));
			break;
		case -1:
			Warn(gettext("terminfo database not found, "
			    "defaulting to -c option\n"));
			break;
		default:
			Warn(gettext("failed to initialize terminal, "
			    "defaulting to -c option\n"));
		}
		opts.o_outpmode &= ~OPT_TERMCAP;
		t_up = t_eol = t_smcup = t_rmcup = movecur = empty_string;
		t_ulon = t_uloff = empty_string;
		return;
	}
	t_ulon	= tigetstr("smul");
	t_uloff	= tigetstr("rmul");
	t_up	= tigetstr("cuu1");
	t_eol	= tigetstr("el");
	t_smcup	= tigetstr("smcup");
	t_rmcup = tigetstr("rmcup");
	t_home  = tigetstr("home");
	if ((t_up == (char *)-1) || (t_eol == (char *)-1) ||
	    (t_smcup == (char *)-1) || (t_rmcup == (char *)-1)) {
		opts.o_outpmode &= ~OPT_TERMCAP;
		t_up = t_eol = t_smcup = t_rmcup = movecur = empty_string;
		return;
	}
	if (t_up == NULL || t_eol == NULL) {
		opts.o_outpmode &= ~OPT_TERMCAP;
		t_eol = t_up = movecur = empty_string;
		return;
	}
	if (t_ulon == (char *)-1 || t_uloff == (char *)-1 ||
	    t_ulon == NULL || t_uloff == NULL) {
		t_ulon = t_uloff = empty_string;  /* can live without it */
	}
	if (t_smcup == NULL || t_rmcup == NULL)
		t_smcup = t_rmcup = empty_string;
	if (t_home == (char *)-1 || t_home == NULL) {
		opts.o_outpmode &= ~OPT_USEHOME;
		t_home = empty_string;
	}
}
示例#9
0
文件: curses.c 项目: lcurses/lcurses
/***
Fetch terminfo string capability.
@function tigetstr
@string capname
@treturn string content of terminal string capability
@see tigetstr(3x)
@see terminfo(5)
*/
static int
Ptigetstr (lua_State *L)
{
	const char *res;

	strlcpy (ti_capname, luaL_checkstring (L, 1), sizeof (ti_capname));
	res = tigetstr (ti_capname);
	if ((char *) -1 == res)
		return luaL_error (L, "`%s' is not a string capability", ti_capname);
	else if (NULL == res)
		lua_pushnil (L);
	else
		lua_pushstring(L, res);
	return 1;
}
示例#10
0
文件: ui_utils.c 项目: wildj79/tlf
/** lookup key code by capability name
 *
 * ncurses automatically maps extended capabilities (such as kNXT3 or similar)
 * to keycodes. But there is no fixed ordering for that.
 * So we look up the key code by its name on strtup and use that afterwards.
 * \param capability  - capability name
 * \return              keycode or 0 if no associated key found
 */
int lookup_key(char *capability) {
    char *esc_sequence = NULL;
    int keycode = 0;

    if (*capability == '\0') {
	return 0;
    }

    esc_sequence = tigetstr(capability);

    if (esc_sequence == NULL || esc_sequence == (char *)-1) {
	return 0;
    }

    keycode = key_defined(esc_sequence);

    return keycode;
}
示例#11
0
/*
 * Get a particular string capability.
 */
static char *GetStringCap(const char *termcapName, const char *terminfoName)
{
#ifdef IL_USE_TERMCAP
	char *area = termcapBuffer2;
	return tgetstr((char *)termcapName, &area);
#else
	char *str;
	if(!terminfoName)
	{
		return 0;
	}
	str = tigetstr((char *)terminfoName);
	if(!str || str == (char *)(ILNativeInt)(-1))
	{
		return 0;
	}
	return str;
#endif
}
示例#12
0
文件: blue.c 项目: Distrotech/slang
int main(int argc, char *argv[])
{
    (void) signal(SIGINT, die);
    initscr();

    /*
     * We use COLOR_GREEN because COLOR_BLACK is wired to the wrong thing.
     */
    start_color();
    init_pair(COLOR_RED,     COLOR_RED,   COLOR_WHITE);
    init_pair(COLOR_BLUE,    COLOR_BLUE,  COLOR_WHITE);
    init_pair(COLOR_GREEN,   COLOR_BLACK, COLOR_WHITE);

#if defined(__i386__) && defined(A_ALTCHARSET)
    if (tigetstr("smpch"))
	suits = glyphs;
#endif /* __i386__ && A_ALTCHARSET */

    cbreak();

    if (argc == 2)
	srand((unsigned)atoi(argv[1]));
    else
	srand((unsigned)time((time_t *)0));

    init_vars();

    do{
	deal_number++;
	shuffle(deck_size);
	deal_cards();
	display_cards(deal_number);
	play_game();
    }
    while
	((deck_size=collect_discards()) != 0);

    game_finished(deal_number);

    die(SIGINT);
    /*NOTREACHED*/
   return 1;
}
示例#13
0
文件: cursor.c 项目: NicolasC27/42sh
int		cursors_delete(t_edit *line, t_info *info)
{
  char		*s;
  int		i;

  i = 0;
  if (line->cmd == NULL)
    return (EXIT_FAILURE);
  i -= line->len;
  if (i == line->pos)
    return (EXIT_FAILURE);
  if (info->keyleft)
    write(info->fd, info->keyleft, my_strlen(info->keyleft));
  if ((s = tigetstr("el")) != NULL)
    write(info->fd, s, my_strlen(s));
  if (manage_string(line, info, 0, 0) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
示例#14
0
static void
duplicate(WINDOW *win, NCURSES_CONST char *name, int code)
{
    char *value = tigetstr(name);

    if (value != 0) {
	const char *prefix = 0;
	char temp[BUFSIZ];

	if (!strncmp(value, "\033[", 2)) {
	    prefix = "\033O";
	} else if (!strncmp(value, "\033O", 2)) {
	    prefix = "\033[";
	}
	if (prefix != 0) {
	    sprintf(temp, "%s%s", prefix, value + 2);
	    really_define_key(win, temp, code);
	}
    }
}
示例#15
0
文件: terminfo.c 项目: zsh-users/zsh
static HashNode
getterminfo(UNUSED(HashTable ht), const char *name)
{
    int len, num;
    char *tistr, *nameu;
    Param pm = NULL;

    /* This depends on the termcap stuff in init.c */
    if (termflags & TERM_BAD)
	return NULL;
    if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
	return NULL;

    nameu = dupstring(name);
    unmetafy(nameu, &len);

    pm = (Param) hcalloc(sizeof(struct param));
    pm->node.nam = nameu;
    pm->node.flags = PM_READONLY;

    if (((num = tigetnum(nameu)) != -1) && (num != -2)) {
	pm->u.val = num;
	pm->node.flags |= PM_INTEGER;
	pm->gsu.i = &nullsetinteger_gsu;
    } else if ((num = tigetflag(nameu)) != -1) {
	pm->u.str = num ? dupstring("yes") : dupstring("no");
	pm->node.flags |= PM_SCALAR;
	pm->gsu.s = &nullsetscalar_gsu;
    } else if ((tistr = (char *)tigetstr(nameu)) != NULL && tistr != (char *)-1) {
	pm->u.str = dupstring(tistr);
	pm->node.flags |= PM_SCALAR;
	pm->gsu.s = &nullsetscalar_gsu;
    } else {
	/* zwarn("no such capability: %s", name); */
	pm->u.str = dupstring("");
	pm->node.flags |= PM_UNSET;
	pm->gsu.s = &nullsetscalar_gsu;
    }
    return &pm->node;
}
示例#16
0
文件: tput.c 项目: andreiw/polaris
static int
outputcap(char *cap, int argc, char **argv)
{
	int parmset = 0;
	char *thisstr;
	int i;

	if ((i = tigetflag(cap)) >= 0)
		return (1 - i);

	if ((i = tigetnum(cap)) >= -1) {
		(void) printf("%d\n", i);
		return (0);
	}

	if ((thisstr = tigetstr(cap)) != (char *)-1) {
		if (!thisstr) {
			return (1);
		}
		for (parmset = 0; optind < argc; optind++, parmset++)
			if (allnumeric(argv[optind]))
				parm[parmset] = atoi(argv[optind]);
			else
				parm[parmset] = (int)argv[optind];

		if (parmset)
			putp(tparm(thisstr,
			parm[0], parm[1], parm[2], parm[3], parm[4], parm[5],
			parm[6], parm[7], parm[8]));
		else
			putp(thisstr);
		return (0);
	}

	(void) fprintf(stderr,
	    gettext("%s: unknown terminfo capability '%s'\n"), progname, cap);

	exit(4);
	/* NOTREACHED */
}
示例#17
0
文件: terminfo.c 项目: essele/opentik
static int lua_setupterm(lua_State *L) {
	char 	*term = 0;
	int		i;
	char	*name;

	if (!lua_isnoneornil(L, 1)) term = (char *)luaL_checkstring(L, 1);
	setupterm((char *)term, 1, (int *)0);

	/*
	 * Now populate the table with strings, bools and nums
	 */
	lua_rawgeti(L, LUA_REGISTRYINDEX, table_ref);

	// Strings
	for (i=0; (name = strnames[i]); i++) {
		char *strval = tigetstr(name);
		if (strval) {
			lua_pushstring(L, strval);
			lua_setfield(L, -2, strfnames[i]);
		}
	}
	// Bools
	for (i=0; (name = boolnames[i]); i++) {
		if (tigetflag(name)==1) {
			lua_pushboolean(L, true);
			lua_setfield(L, -2, boolfnames[i]);
		}
	}		
	// Nums
	for (i=0; (name = numnames[i]); i++) {
		int val = tigetnum(name);
		if (val >= 0) {
			lua_pushnumber(L, val);
			lua_setfield(L, -2, numfnames[i]);
		}
	}
	return 1;
}
示例#18
0
文件: terminal.c 项目: nysan/alpine
static int
tinfoterminalinfo(int termcap_wins)
{
    char   *_ku, *_kd, *_kl, *_kr,
	   *_kppu, *_kppd, *_kphome, *_kpend, *_kpdel,
	   *_kf1, *_kf2, *_kf3, *_kf4, *_kf5, *_kf6,
	   *_kf7, *_kf8, *_kf9, *_kf10, *_kf11, *_kf12;
    char   *ttnm;

    if (Pmaster) {
	/*
	 *		setupterm() automatically retrieves the value
	 *		of the TERM variable.
	 */
	int err;
	ttnm = getenv("TERM");
	if(!ttnm)
	  return(-1);

	strncpy(term_name, ttnm, sizeof(term_name));
	term_name[sizeof(term_name)-1] = '\0';
	setupterm ((char *) 0, 1, &err);
	if (err != 1) return(err-2);
    }
    else {
	/*
	 *		setupterm() issues a message and exits, if the
	 *		terminfo data base is gone or the term type is
	 *		unknown, if arg2 is 0.
	 */
	setupterm ((char *) 0, 1, (int *) 0);
    }

    _clearscreen	= tigetstr("clear");
    _moveto		= tigetstr("cup");
    _up			= tigetstr("cuu1");
    _down		= tigetstr("cud1");
    _right		= tigetstr("cuf1");
    _left		= tigetstr("cub1");
    _setinverse		= tigetstr("smso");
    _clearinverse	= tigetstr("rmso");
    _setunderline	= tigetstr("smul");
    _clearunderline	= tigetstr("rmul");
    _setbold		= tigetstr("bold");
    _clearallattr	= tigetstr("sgr0");
    _cleartoeoln	= tigetstr("el");
    _cleartoeos		= tigetstr("ed");
    _deletechar		= tigetstr("dch1");
    _insertchar		= tigetstr("ich1");
    _startinsert	= tigetstr("smir");
    _endinsert		= tigetstr("rmir");
    _deleteline		= tigetstr("dl1");
    _insertline		= tigetstr("il1");
    _scrollregion	= tigetstr("csr");
    _scrolldown		= tigetstr("ind");
    _scrollup		= tigetstr("ri");
    _termcap_init	= tigetstr("smcup");
    _termcap_end	= tigetstr("rmcup");
    _startdelete	= tigetstr("smdc");
    _enddelete		= tigetstr("rmdc");
    _ku			= tigetstr("kcuu1");
    _kd			= tigetstr("kcud1");
    _kl			= tigetstr("kcub1");
    _kr			= tigetstr("kcuf1");
    _kppu		= tigetstr("kpp");
    _kppd		= tigetstr("knp");
    _kphome		= tigetstr("khome");
    _kpend		= tigetstr("kend");
    _kpdel		= tigetstr("kdch1");
    _kf1		= tigetstr("kf1");
    _kf2		= tigetstr("kf2");
    _kf3		= tigetstr("kf3");
    _kf4		= tigetstr("kf4");
    _kf5		= tigetstr("kf5");
    _kf6		= tigetstr("kf6");
    _kf7		= tigetstr("kf7");
    _kf8		= tigetstr("kf8");
    _kf9		= tigetstr("kf9");
    _kf10		= tigetstr("kf10");
    _kf11		= tigetstr("kf11");
    _kf12		= tigetstr("kf12");

    _colors		= tigetnum("colors");
    _pairs		= tigetnum("pairs");
    _setaf		= tigetstr("setaf");
    _setab		= tigetstr("setab");
    _setf		= tigetstr("setf");
    _setb		= tigetstr("setb");
    _scp		= tigetstr("scp");
    _op			= tigetstr("op");
    _oc			= tigetstr("oc");
    _bce		= tigetflag("bce");

    _tlines = tigetnum("lines");
    if(_tlines == -1){
	char *er;
	int   rr;

	/* tigetnum failed, try $LINES */
	er = getenv("LINES");
	if(er && (rr = atoi(er)) > 0)
	  _tlines = rr;
    }

    _tcolumns = tigetnum("cols");
    if(_tcolumns == -1){
	char *ec;
	int   cc;

	/* tigetnum failed, try $COLUMNS */
	ec = getenv("COLUMNS");
	if(ec && (cc = atoi(ec)) > 0)
	  _tcolumns = cc;
    }
    
    /*
     * Add default keypad sequences to the trie.
     * Since these come first, they will override any conflicting termcap
     * or terminfo escape sequences defined below.  An escape sequence is
     * considered conflicting if one is a prefix of the other.
     * So, without TERMCAP_WINS, there will likely be some termcap/terminfo
     * escape sequences that don't work, because they conflict with default
     * sequences defined here.
     */
    if(!termcap_wins)
      setup_dflt_esc_seq();

    /*
     * add termcap/info escape sequences to the trie...
     */

    if(_ku != NULL && _kd != NULL && _kl != NULL && _kr != NULL){
	kpinsert(_ku, KEY_UP, termcap_wins);
	kpinsert(_kd, KEY_DOWN, termcap_wins);
	kpinsert(_kl, KEY_LEFT, termcap_wins);
	kpinsert(_kr, KEY_RIGHT, termcap_wins);
    }

    if(_kppu != NULL && _kppd != NULL){
	kpinsert(_kppu, KEY_PGUP, termcap_wins);
	kpinsert(_kppd, KEY_PGDN, termcap_wins);
    }

    kpinsert(_kphome, KEY_HOME, termcap_wins);
    kpinsert(_kpend,  KEY_END, termcap_wins);
    kpinsert(_kpdel,  KEY_DEL, termcap_wins);

    kpinsert(_kf1,  F1, termcap_wins);
    kpinsert(_kf2,  F2, termcap_wins);
    kpinsert(_kf3,  F3, termcap_wins);
    kpinsert(_kf4,  F4, termcap_wins);
    kpinsert(_kf5,  F5, termcap_wins);
    kpinsert(_kf6,  F6, termcap_wins);
    kpinsert(_kf7,  F7, termcap_wins);
    kpinsert(_kf8,  F8, termcap_wins);
    kpinsert(_kf9,  F9, termcap_wins);
    kpinsert(_kf10, F10, termcap_wins);
    kpinsert(_kf11, F11, termcap_wins);
    kpinsert(_kf12, F12, termcap_wins);

    /*
     * Add default keypad sequences to the trie.
     * Since these come after the termcap/terminfo escape sequences above,
     * the termcap/info sequences will override any conflicting default
     * escape sequences defined here.
     * So, with TERMCAP_WINS, some of the default sequences will be missing.
     * This means that you'd better get all of your termcap/terminfo entries
     * correct if you define TERMCAP_WINS.
     */
    if(termcap_wins)
      setup_dflt_esc_seq();

    if(Pmaster)
      return(0);
    else
      return(TRUE);
}
示例#19
0
void tio_gotoxy(int x, int y)
{
	DebugLogV(DEBUGLOG_LEVEL_DEBUG, "<tio_gotoxy> gotoxy(%d, %d)", x, y);
	char *cap = tigetstr("cup");
	putp(tparm(cap, y, x));
}
示例#20
0
文件: ul.c 项目: Romutk/lab3.2n
void initinfo(void)
{
	CURS_UP =		tigetstr("cuu1");
	CURS_RIGHT =		tigetstr("cuf1");
	CURS_LEFT =		tigetstr("cub1");
	if (CURS_LEFT == NULL)
		CURS_LEFT =	"\b";

	ENTER_STANDOUT =	tigetstr("smso");
	EXIT_STANDOUT =		tigetstr("rmso");
	ENTER_UNDERLINE =	tigetstr("smul");
	EXIT_UNDERLINE =	tigetstr("rmul");
	ENTER_DIM =		tigetstr("dim");
	ENTER_BOLD =		tigetstr("bold");
	ENTER_REVERSE =		tigetstr("rev");
	EXIT_ATTRIBUTES =	tigetstr("sgr0");

	if (!ENTER_BOLD && ENTER_REVERSE)
		ENTER_BOLD = ENTER_REVERSE;
	if (!ENTER_BOLD && ENTER_STANDOUT)
		ENTER_BOLD = ENTER_STANDOUT;
	if (!ENTER_UNDERLINE && ENTER_STANDOUT) {
		ENTER_UNDERLINE = ENTER_STANDOUT;
		EXIT_UNDERLINE = EXIT_STANDOUT;
	}
	if (!ENTER_DIM && ENTER_STANDOUT)
		ENTER_DIM = ENTER_STANDOUT;
	if (!ENTER_REVERSE && ENTER_STANDOUT)
		ENTER_REVERSE = ENTER_STANDOUT;
	if (!EXIT_ATTRIBUTES && EXIT_STANDOUT)
		EXIT_ATTRIBUTES = EXIT_STANDOUT;

	/*
	 * Note that we use REVERSE for the alternate character set,
	 * not the as/ae capabilities.  This is because we are modelling
	 * the model 37 teletype (since that's what nroff outputs) and
	 * the typical as/ae is more of a graphics set, not the greek
	 * letters the 37 has.
	 */

	UNDER_CHAR =		tigetstr("uc");
	must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
}
示例#21
0
/* 
	setup terminal characteristics and allocate initial stuff 
*/
void *
rl_init(int cliIdx)
{
char *term;
int ret;
rl_t *rl=calloc(1, sizeof(*rl));

        /* initialize soem of the values */
        rl->maxh=DEF_HIST;       /* number of buffered commands */
        rl->maxl=DEF_LENGTH;     /* maximum command length */
        rl->prompt=">";
        rl->notty=0;
        rl->width=80;
        rl->maxpos=0;
        rl->histoff=0;
        
        /* callbacks */
        rl->cliIdx=cliIdx;
        
        /* sequence matching */
        rl->seqidx=0;
        

	if(!(rl->hist=hist_init(rl->maxh, rl->maxl, cliIdx))) return 0;

	/* allocate a new buffer */
	if(!(rl->buf=malloc(rl->maxl))) return 0;


        /* setup the terminal parameter for 'term '. Do this only once */
        if(!termInit) {
            termInit++;
	    term="xterm";
	    if(setupterm(term, 0, &ret)!=ERR)
	    {
	        bip="\007";
                kwb="\033\177";
                kwf="\033d";
                fw="\033f";
                bw="\033b";
		/* if any of these basics go back to fgets() */
		if(!(upN=tigetstr("cuu")) ||
		   !(downN=tigetstr("cud")) ||
		   !(leftN=tigetstr("cub")) ||
		   !(bol=tigetstr("cr")) ||
		   !(rightN=tigetstr("cuf")) ||
		   !(cod=tigetstr("ed"))) { rl->notty=1; return rl; }

		xenl=tigetflag("xenl");
		home=tigetstr("clear");
		kup=tigetstr("kcuu1");
		kdown=tigetstr("kcud1");
		kleft=tigetstr("kcub1");
		kright=tigetstr("kcuf1");
		kdel=tigetstr("kdch1");
		kbksp=tigetstr("kbs");
	    } else 
	    { 
		    trxdbg(0,0,1,"Unable to initialize 'term'\n");
	    }
        }
#ifdef OVER_TTY
	/* get window size */
	{
	struct winsize w;

		if (ioctl (in, TIOCGWINSZ, &w) == 0)
		{
			width=w.ws_col;
		}
		else /* use ENV */
		{
		char *ewidth;

			if ((ewidth = getenv ("COLUMNS")))
				width = atoi (ewidth);

			/* use what's in terminfo */
			if (width <= 0)
				width = tigetnum ("co");

		}

		if (width <= 1) width = 80;

	}
	/* set ourselves in the proper mode */
	{
		if(ioctl(in, TCGETA, &tio)) { notty=1; return 1;}

		stio=tio;

		tio.c_lflag &= ~(ICANON | ECHO);
		tio.c_iflag &= ~(ICRNL  | INLCR);
		tio.c_cc[VMIN] = 1;
		tio.c_cc[VTIME] = 0;
	}
#endif	
    rlShowPrompt(rl, 1);
    return rl;
}
示例#22
0
文件: getcaps.c 项目: 5HT/mumps
int	getcaps(int fildes)
{
	char	*cap;
	int	status;

	cap = GETENV("TERM");
	if (!cap)
		cap = "unknown";

	SETUPTERM(cap, fildes, &status);

	if (1 == status)
	{

#ifdef __MVS__
#pragma convlit(suspend)
#endif
		AUTO_RIGHT_MARGIN = tigetflag("am");
		CLR_EOS = tigetstr("ed");
		CLR_EOL = tigetstr("el");
		COLUMNS = tigetnum("cols");
		CURSOR_ADDRESS = tigetstr("cup");
		CURSOR_DOWN = tigetstr("cud1");
		CURSOR_LEFT = tigetstr("cub1");
		CURSOR_RIGHT = tigetstr("cuf1");
		CURSOR_UP = tigetstr("cuu1");
		EAT_NEWLINE_GLITCH = tigetflag("xenl");
		KEY_BACKSPACE = tigetstr("kbs");
		KEY_DC = tigetstr("kdch1");
		KEY_DOWN = tigetstr("kcud1");
		KEY_LEFT = tigetstr("kcub1");
		KEY_RIGHT = tigetstr("kcuf1");
		KEY_UP = tigetstr("kcuu1");
		KEY_INSERT = tigetstr("kich1");
		KEYPAD_LOCAL = tigetstr("rmkx");
		KEYPAD_XMIT = tigetstr("smkx");
		GTM_LINES = tigetnum("lines");

#ifdef __MVS__
#pragma convlit(resume)
#endif

		assert(-1 != AUTO_RIGHT_MARGIN);
		if (0 == AUTO_RIGHT_MARGIN)
			AUTO_RIGHT_MARGIN = gtm_auto_right_margin;
		assert((char *)-1L != CLR_EOS);
		if (NULL == CLR_EOS)
			CLR_EOS = gtm_clr_eos;
		assert((char *)-1L != CLR_EOL);
		if (NULL == CLR_EOL)
			CLR_EOL = gtm_clr_eol;
		assert(-2 != COLUMNS);
		if (-1 == COLUMNS)
			COLUMNS = gtm_columns;
		assert((char *)-1L != CURSOR_ADDRESS);
		if (NULL == CURSOR_ADDRESS)
			CURSOR_ADDRESS = gtm_cursor_address;
		assert((char *)-1L != CURSOR_DOWN);
		if (NULL == CURSOR_DOWN)
			CURSOR_DOWN = gtm_cursor_down;
		assert((char *)-1L != CURSOR_LEFT);
		if (NULL == CURSOR_LEFT)
			CURSOR_LEFT = gtm_cursor_left;
		assert((char *)-1L != CURSOR_RIGHT);
		if (NULL == CURSOR_RIGHT)
			CURSOR_RIGHT = gtm_cursor_right;
		assert((char *)-1L != CURSOR_UP);
		if (NULL == CURSOR_UP)
			CURSOR_UP = gtm_cursor_up;
		assert((char *)-1L != KEY_BACKSPACE);
		if (NULL == KEY_BACKSPACE)
			KEY_BACKSPACE = gtm_key_backspace;
		assert((char *)-1L != KEY_DC);
		if (NULL == KEY_DC)
			KEY_DC = gtm_key_dc;
		assert((char *)-1L != KEY_DOWN);
		if (NULL == KEY_DOWN)
			KEY_DOWN = gtm_key_down;
		assert((char *)-1L != KEY_LEFT);
		if (NULL == KEY_LEFT)
			KEY_LEFT = gtm_key_left;
		assert((char *)-1L != KEY_RIGHT);
		if (NULL == KEY_RIGHT)
			KEY_RIGHT = gtm_key_right;
		assert((char *)-1L != KEY_UP);
		if (NULL == KEY_UP)
			KEY_UP = gtm_key_up;
		assert((char *)-1L != KEY_INSERT);
		if (NULL == KEY_INSERT)
			KEY_INSERT = gtm_key_insert;
		assert((char *)-1L != KEYPAD_LOCAL);
		if (NULL == KEYPAD_LOCAL)
			KEYPAD_LOCAL = gtm_keypad_local;
		assert((char *)-1L != KEYPAD_XMIT);
		if (NULL == KEYPAD_XMIT)
			KEYPAD_XMIT = gtm_keypad_xmit;
		assert(-2 != GTM_LINES);
		if (-1 == GTM_LINES)
			GTM_LINES = gtm_lines;
	}
	else
	{
		AUTO_RIGHT_MARGIN = gtm_auto_right_margin;
		CLR_EOS = gtm_clr_eos;
		CLR_EOL = gtm_clr_eol;
		COLUMNS = gtm_columns;
		CURSOR_ADDRESS = gtm_cursor_address;
		CURSOR_DOWN = gtm_cursor_down;
		CURSOR_LEFT = gtm_cursor_left;
		CURSOR_RIGHT = gtm_cursor_right;
		CURSOR_UP = gtm_cursor_up;
		EAT_NEWLINE_GLITCH = gtm_eat_newline_glitch;
		KEY_BACKSPACE = gtm_key_backspace;
		KEY_DC = gtm_key_dc;
		KEY_DOWN = gtm_key_down;
		KEY_LEFT = gtm_key_left;
		KEY_RIGHT = gtm_key_right;
		KEY_UP = gtm_key_up;
		KEY_INSERT = gtm_key_insert;
		KEYPAD_LOCAL = gtm_keypad_local;
		KEYPAD_XMIT = gtm_keypad_xmit;
		GTM_LINES = gtm_lines;
	}
	return status;
}
示例#23
0
char *_t3_tigetstr(const char *name) {
  /* Copy the name into a new buffer, because tigetstr expects a char *
     not a const char *. */
  COPY_BUFFER(name);
  return tigetstr(name_buffer);
}
示例#24
0
static char *my_tgetstr(char *s) {
     return tigetstr(s);
}
示例#25
0
文件: main.c 项目: jgreco/agora
void setup_escape_seqs()
{
	E_KCLR	= tigetstr("clear");	S_KCLR	= strlen(E_KCLR);

	return;
}
示例#26
0
文件: tput.c 项目: BA3IK/node-ncurses
static int
tput(int argc, char *argv[])
{
    NCURSES_CONST char *name;
    char *s;
    int i, j, c;
    int status;
    FILE *f;
#if !PURE_TERMINFO
    bool termcap = FALSE;
#endif

    if ((name = argv[0]) == 0)
	name = "";
    check_aliases(name);
    if (is_reset || is_init) {
	if (init_prog != 0) {
	    system(init_prog);
	}
	FLUSH;

	if (is_reset && reset_1string != 0) {
	    PUTS(reset_1string);
	} else if (init_1string != 0) {
	    PUTS(init_1string);
	}
	FLUSH;

	if (is_reset && reset_2string != 0) {
	    PUTS(reset_2string);
	} else if (init_2string != 0) {
	    PUTS(init_2string);
	}
	FLUSH;

#ifdef set_lr_margin
	if (set_lr_margin != 0) {
	    PUTS(TPARM_2(set_lr_margin, 0, columns - 1));
	} else
#endif
#ifdef set_left_margin_parm
	    if (set_left_margin_parm != 0
		&& set_right_margin_parm != 0) {
	    PUTS(TPARM_1(set_left_margin_parm, 0));
	    PUTS(TPARM_1(set_right_margin_parm, columns - 1));
	} else
#endif
	    if (clear_margins != 0
		&& set_left_margin != 0
		&& set_right_margin != 0) {
	    PUTS(clear_margins);
	    if (carriage_return != 0) {
		PUTS(carriage_return);
	    } else {
		PUTCHAR('\r');
	    }
	    PUTS(set_left_margin);
	    if (parm_right_cursor) {
		PUTS(TPARM_1(parm_right_cursor, columns - 1));
	    } else {
		for (i = 0; i < columns - 1; i++) {
		    PUTCHAR(' ');
		}
	    }
	    PUTS(set_right_margin);
	    if (carriage_return != 0) {
		PUTS(carriage_return);
	    } else {
		PUTCHAR('\r');
	    }
	}
	FLUSH;

	if (init_tabs != 8) {
	    if (clear_all_tabs != 0 && set_tab != 0) {
		for (i = 0; i < columns - 1; i += 8) {
		    if (parm_right_cursor) {
			PUTS(TPARM_1(parm_right_cursor, 8));
		    } else {
			for (j = 0; j < 8; j++)
			    PUTCHAR(' ');
		    }
		    PUTS(set_tab);
		}
		FLUSH;
	    }
	}

	if (is_reset && reset_file != 0) {
	    f = fopen(reset_file, "r");
	    if (f == 0) {
		quit(4 + errno, "Can't open reset_file: '%s'", reset_file);
	    }
	    while ((c = fgetc(f)) != EOF) {
		PUTCHAR(c);
	    }
	    fclose(f);
	} else if (init_file != 0) {
	    f = fopen(init_file, "r");
	    if (f == 0) {
		quit(4 + errno, "Can't open init_file: '%s'", init_file);
	    }
	    while ((c = fgetc(f)) != EOF) {
		PUTCHAR(c);
	    }
	    fclose(f);
	}
	FLUSH;

	if (is_reset && reset_3string != 0) {
	    PUTS(reset_3string);
	} else if (init_3string != 0) {
	    PUTS(init_3string);
	}
	FLUSH;
	return 0;
    }

    if (strcmp(name, "longname") == 0) {
	PUTS(longname());
	return 0;
    }
#if !PURE_TERMINFO
  retry:
#endif
    if ((status = tigetflag(name)) != -1) {
	return exit_code(BOOLEAN, status);
    } else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) {
	(void) printf("%d\n", status);
	return exit_code(NUMBER, 0);
    } else if ((s = tigetstr(name)) == CANCELLED_STRING) {
#if !PURE_TERMINFO
	if (!termcap) {
	    const struct name_table_entry *np;

	    termcap = TRUE;
	    if ((np = _nc_find_entry(name, _nc_get_hash_table(termcap))) != 0) {
		switch (np->nte_type) {
		case BOOLEAN:
		    if (bool_from_termcap[np->nte_index])
			name = boolnames[np->nte_index];
		    break;

		case NUMBER:
		    if (num_from_termcap[np->nte_index])
			name = numnames[np->nte_index];
		    break;

		case STRING:
		    if (str_from_termcap[np->nte_index])
			name = strnames[np->nte_index];
		    break;
		}
		goto retry;
	    }
	}
#endif
	quit(4, "unknown terminfo capability '%s'", name);
    } else if (s != ABSENT_STRING) {
	if (argc > 1) {
	    int k;
	    int popcount;
	    long numbers[1 + NUM_PARM];
	    char *strings[1 + NUM_PARM];
	    char *p_is_s[NUM_PARM];

	    /* Nasty hack time. The tparm function needs to see numeric
	     * parameters as numbers, not as pointers to their string
	     * representations
	     */

	    for (k = 1; k < argc; k++) {
		char *tmp = 0;
		strings[k] = argv[k];
		numbers[k] = strtol(argv[k], &tmp, 0);
		if (tmp == 0 || *tmp != 0)
		    numbers[k] = 0;
	    }
	    for (k = argc; k <= NUM_PARM; k++) {
		numbers[k] = 0;
		strings[k] = 0;
	    }

	    switch (tparm_type(name)) {
	    case Num_Str:
		s = TPARM_2(s, numbers[1], strings[2]);
		break;
	    case Num_Str_Str:
		s = TPARM_3(s, numbers[1], strings[2], strings[3]);
		break;
	    case Numbers:
	    default:
		(void) _nc_tparm_analyze(s, p_is_s, &popcount);
#define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
		s = TPARM_9(s,
			    myParam(1),
			    myParam(2),
			    myParam(3),
			    myParam(4),
			    myParam(5),
			    myParam(6),
			    myParam(7),
			    myParam(8),
			    myParam(9));
		break;
	    }
	}

	/* use putp() in order to perform padding */
	putp(s);
	return exit_code(STRING, 0);
    }
    return exit_code(STRING, 1);
}
示例#27
0
文件: cal.c 项目: apprisi/util-linux
# endif
# include <term.h>

static void my_setupterm(const char *term, int fildes, int *errret)
{
	setupterm((char *)term, fildes, errret);
}

static void my_putstring(char *s)
{
	putp(s);
}

static const char *my_tgetstr(char *s __attribute__((__unused__)), char *ss)
{
	const char *ret = tigetstr(ss);
	if (!ret || ret == (char *)-1)
		return "";

	return ret;
}

#elif defined(HAVE_LIBTERMCAP)
# include <termcap.h>

static char termbuffer[4096];
static char tcbuffer[4096];
static char *strbuf = termbuffer;

static void my_setupterm(const char *term, int fildes __attribute__((__unused__)), int *errret)
{
示例#28
0
// Init terminal and determine color command strings
int terminal_init (void) {
	color_set_monochrome();
	if (!isatty(STDOUT_FILENO)) return 1;

	if (setupterm (NULL, STDOUT_FILENO, NULL)) {
		log_error("Unable to configure terminal\n");
		return 1;
	}

        char *boldstr = NULL;
        if(tigetstr("bold")) boldstr = strdup(tigetstr("bold"));

	if (tigetstr("setaf")) {
		log_debug("Using setaf color definitions\n");
		red	= strdup(tiparm(tigetstr("setaf"), 1));
		green	= strdup(tiparm(tigetstr("setaf"), 2));
		yellow	= strdup(tiparm(tigetstr("setaf"), 3));
                if(boldstr) {
		   blue	= malloc(strlen(boldstr) + strlen(tiparm(tigetstr("setaf"), 4)) + 1);
                   if(!blue) {
                      log_error("malloc failed!\n");
                      exit(1);
                   }
                   strcpy(blue, boldstr);
                   strcat(blue, tiparm(tigetstr("setaf"), 4));
                } else blue = strdup(tiparm(tigetstr("setaf"), 4));
		magenta = strdup(tiparm(tigetstr("setaf"), 5));
		cyan	= strdup(tiparm(tigetstr("setaf"), 6));
		white	= strdup(tiparm(tigetstr("setaf"), 7));
		colors_available = 1;
		atexit(terminal_reset);
	} else if (tigetstr("setf")) {
		log_debug("Using setf color definitions\n");
		red	= strdup(tiparm(tigetstr("setf"), 4));
		green	= strdup(tiparm(tigetstr("setf"), 2));
		yellow	= strdup(tiparm(tigetstr("setf"), 6));
		blue	= strdup(tiparm(tigetstr("setf"), 1));
		magenta = strdup(tiparm(tigetstr("setf"), 5));
		cyan	= strdup(tiparm(tigetstr("setf"), 3));
		white	= strdup(tiparm(tigetstr("setf"), 7));
		colors_available = 1;
		atexit(terminal_reset);
	} else {
		log_warn("Unable to determine color commands for your terminal\n");
		return 1;
	}

	char *r = tigetstr("sgr0");
	if (r) default_color = strdup(r);
	else {
		color_set_monochrome();
		log_error("Unable to get default color string\n");
		return 1;
	}

	return 0;
}
示例#29
0
static void
dumpit(NCURSES_CONST char *cap)
{
    /*
     * One of the limitations of the termcap interface is that the library
     * cannot determine the size of the buffer passed via tgetstr(), nor the
     * amount of space remaining.  This demo simply reuses the whole buffer
     * for each call; a normal termcap application would try to use the buffer
     * to hold all of the strings extracted from the terminal entry.
     */
    const char *str;
    int num;

    if ((str = tigetstr(cap)) != 0 && (str != (char *) -1)) {
	/*
	 * Note that the strings returned are mostly terminfo format, since
	 * ncurses does not convert except for a handful of special cases.
	 */
	printf(FNAME(str), cap);
	while (*str != 0) {
	    int ch = UChar(*str++);
	    switch (ch) {
	    case '\177':
		fputs("^?", stdout);
		break;
	    case '\033':
		fputs("\\E", stdout);
		break;
	    case '\b':
		fputs("\\b", stdout);
		break;
	    case '\f':
		fputs("\\f", stdout);
		break;
	    case '\n':
		fputs("\\n", stdout);
		break;
	    case '\r':
		fputs("\\r", stdout);
		break;
	    case ' ':
		fputs("\\s", stdout);
		break;
	    case '\t':
		fputs("\\t", stdout);
		break;
	    case '^':
		fputs("\\^", stdout);
		break;
	    case ':':
		fputs("\\072", stdout);
		break;
	    case '\\':
		fputs("\\\\", stdout);
		break;
	    default:
		if (isgraph(ch))
		    fputc(ch, stdout);
		else if (ch < 32)
		    printf("^%c", ch + '@');
		else
		    printf("\\%03o", ch);
		break;
	    }
	}
	printf("\n");
    } else if ((num = tigetnum(cap)) >= 0) {
	printf(FNAME(num), cap);
	printf(" %d\n", num);
    } else if ((num = tigetflag(cap)) >= 0) {
	printf(FNAME(flg), cap);
	printf("%s\n", num ? "true" : "false");
    }
    fflush(stdout);
}
示例#30
0
static int
tput(int argc, char *argv[])
{
    NCURSES_CONST char *name;
    char *s;
    int i, j, c;
    int status;
    FILE *f;

    check_aliases(name = argv[0]);
    if (is_reset || is_init) {
        if (init_prog != 0) {
            system(init_prog);
        }
        FLUSH;

        if (is_reset && reset_1string != 0) {
            PUTS(reset_1string);
        } else if (init_1string != 0) {
            PUTS(init_1string);
        }
        FLUSH;

        if (is_reset && reset_2string != 0) {
            PUTS(reset_2string);
        } else if (init_2string != 0) {
            PUTS(init_2string);
        }
        FLUSH;

        if (set_lr_margin != 0) {
            PUTS(tparm(set_lr_margin, 0, columns - 1));
        } else if (set_left_margin_parm != 0
                   && set_right_margin_parm != 0) {
            PUTS(tparm(set_left_margin_parm, 0));
            PUTS(tparm(set_right_margin_parm, columns - 1));
        } else if (clear_margins != 0
                   && set_left_margin != 0
                   && set_right_margin != 0) {
            PUTS(clear_margins);
            if (carriage_return != 0) {
                PUTS(carriage_return);
            } else {
                PUTCHAR('\r');
            }
            PUTS(set_left_margin);
            if (parm_right_cursor) {
                PUTS(tparm(parm_right_cursor, columns - 1));
            } else {
                for (i = 0; i < columns - 1; i++) {
                    PUTCHAR(' ');
                }
            }
            PUTS(set_right_margin);
            if (carriage_return != 0) {
                PUTS(carriage_return);
            } else {
                PUTCHAR('\r');
            }
        }
        FLUSH;

        if (init_tabs != 8) {
            if (clear_all_tabs != 0 && set_tab != 0) {
                for (i = 0; i < columns - 1; i += 8) {
                    if (parm_right_cursor) {
                        PUTS(tparm(parm_right_cursor, 8));
                    } else {
                        for (j = 0; j < 8; j++)
                            PUTCHAR(' ');
                    }
                    PUTS(set_tab);
                }
                FLUSH;
            }
        }

        if (is_reset && reset_file != 0) {
            f = fopen(reset_file, "r");
            if (f == 0) {
                quit(errno, "Can't open reset_file: '%s'", reset_file);
            }
            while ((c = fgetc(f)) != EOF) {
                PUTCHAR(c);
            }
            fclose(f);
        } else if (init_file != 0) {
            f = fopen(init_file, "r");
            if (f == 0) {
                quit(errno, "Can't open init_file: '%s'", init_file);
            }
            while ((c = fgetc(f)) != EOF) {
                PUTCHAR(c);
            }
            fclose(f);
        }
        FLUSH;

        if (is_reset && reset_3string != 0) {
            PUTS(reset_3string);
        } else if (init_2string != 0) {
            PUTS(init_2string);
        }
        FLUSH;
        return 0;
    }

    if (strcmp(name, "longname") == 0) {
        PUTS(longname());
        return 0;
    }
#if !PURE_TERMINFO
    {
        const struct name_table_entry *np;

        if ((np = _nc_find_entry(name, _nc_get_hash_table(1))) != 0)
            switch (np->nte_type) {
            case BOOLEAN:
                if (bool_from_termcap[np->nte_index])
                    name = boolnames[np->nte_index];
                break;

            case NUMBER:
                if (num_from_termcap[np->nte_index])
                    name = numnames[np->nte_index];
                break;

            case STRING:
                if (str_from_termcap[np->nte_index])
                    name = strnames[np->nte_index];
                break;
            }
    }
#endif

    if ((status = tigetflag(name)) != -1) {
        return (status != 0);
    } else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) {
        (void) printf("%d\n", status);
        return (0);
    } else if ((s = tigetstr(name)) == CANCELLED_STRING) {
        quit(4, "%s: unknown terminfo capability '%s'", prg_name, name);
    } else if (s != ABSENT_STRING) {
        if (argc > 1) {
            int k;
            int numbers[10];
            char *strings[10];

            /* Nasty hack time. The tparm function needs to see numeric
             * parameters as numbers, not as pointers to their string
             * representations
             */

            for (k = 1; k < argc; k++) {
                char *tmp = 0;
                strings[k] = argv[k];
                numbers[k] = strtol(argv[k], &tmp, 0);
                if (tmp == 0 || *tmp != 0)
                    numbers[k] = 0;
            }
            for (k = argc; k <= 9; k++) {
                numbers[k] = 0;
                strings[k] = 0;
            }

            switch (tparm_type(name)) {
            case Num_Str:
                s = tparm(s, numbers[1], strings[2]);
                break;
            case Num_Str_Str:
                s = tparm(s, numbers[1], strings[2], strings[3]);
                break;
            default:
                s = tparm(s,
                          numbers[1], numbers[2], numbers[3],
                          numbers[4], numbers[5], numbers[6],
                          numbers[7], numbers[8], numbers[9]);
                break;
            }
        }

        /* use putp() in order to perform padding */
        putp(s);
        return (0);
    }
    return (0);
}