Esempio n. 1
0
get_termcap()
{
  static char termbuf[50];
  extern char *tgetstr(), *getenv();
  char *loc = termbuf;
  char entry[1024];

  if ((term = getenv("TERM")) == NULL) {
	Error("$TERM not defined");
  }
  if (tgetent(entry, term) <= 0) {
	Error("Unknown terminal.");
  }
  if (tgetent(buffer, term) != 1) {
	Error("No termcap definition for $TERM");
  }
  if ((tgetstr("cl", &p)) == NULL) {
	Error("No clear (cl) entry for $TERM");
  }
  SO = tgetstr("so", &loc);
  SE = tgetstr("se", &loc);
  CD = tgetstr("cd", &loc);

  if (CD == (char *) 0) CD = "             \r";

}
Esempio n. 2
0
int
terminit()
{
  char *term;
  
  if ((term = getenv("TERM")) == NULL)
    {
      perror("can't determine terminal\n");
      exit(1);
    }
  if (tgetent(termbuf, term) != 1)
    {
      perror("problem with tgetent\n");
      exit(1);
    }

#ifdef unix
  /* Here we assume that an explicit termbuf
     was provided to tgetent.  */
  bp = (char *) malloc (strlen (termbuf));
#else
  bp = NULL;
#endif
  upstr = tgetstr("up", &bp);
  mrstr = tgetstr("mr", &bp);
  mestr = tgetstr("me", &bp);
  clstr = tgetstr("cl", &bp);
  dcstr = tgetstr("dc", &bp);
}
Esempio n. 3
0
int termcap() {
	char *term;
	char *p;
	char *tmp;

	term = getenv("TERM");
	if (term == NULL) {
		return -1;
	}

	if (tgetent(tent, term) == -1) {
		return -1;
	}

	p = tent;
	if ((tmp = tgetstr("cl", &p)) != NULL) {
		PC = *tmp;
	}
	CL = tgetstr("cl", &p);
	CM = tgetstr("cm", &p);
	UP = tgetstr("up", &p);
	SR = tgetstr("sr", &p);
	HO = tgetstr("ho", &p);
	RC = tgetstr("rc", &p);
	SC = tgetstr("sc", &p);
	CE = tgetstr("ce", &p);

	return 0;
}
Esempio n. 4
0
void	init_term_data(t_entlist *l)
{
	char	*termtype;
	int		success;
	char	*term_buffer;

	term_buffer = NULL;
	if (!isatty(l->fd))
	{
		ft_putendl_fd("Not a terminal device", 2);
		exit(EXIT_FAILURE);
	}
	termtype = getenv("TERM");
	if (termtype == 0)
	{
		ft_putendl_fd("Error: No TERM variable.", 2);
		exit(EXIT_FAILURE);
	}
	success = tgetent(term_buffer, termtype);
	if (success < 0)
	{
		ft_putstr_fd("The termtype ", 2);
		ft_putstr_fd(termtype, 2);
		ft_putendl_fd(" is not a valid.", 2);
		exit(EXIT_FAILURE);
	}
}
Esempio n. 5
0
int		control_size(t_elem *l)
{
	char	*termtype;
	int		lin;

	termtype = getenv("TERM");
	if (!termtype)
		ft_env_error();
	tgetent(NULL, termtype);
	tputs(tgetstr("cl", NULL), 1, int_char);
	lin = tgetnum("li");
	l->len = ft_list_len(l);
	if (l->len > lin - 1)
	{
		tputs(tgetstr("cl", NULL), 1, int_char);
		ft_putendl_red("Please Resize window");
		return (0);
	}
	else
	{
		tputs(tgetstr("cl", NULL), 1, int_char);
		display_list(l);
	}
	return (1);
}
Esempio n. 6
0
wi_terminal_t * wi_terminal_init_with_type(wi_terminal_t *terminal, wi_string_t *type) {
	char		*env;
	int			err, co, li;
	
	err = tgetent(NULL, wi_string_cstring(type));
	
	if(err <= 0) {
		if(err == 0)
			wi_error_set_lib_error(WI_ERROR_TERMCAP_NOSUCHENTRY);
		else
			wi_error_set_lib_error(WI_ERROR_TERMCAP_TERMINFONOTFOUND);

		wi_release(terminal);
		
		return NULL;
	}

	env = getenv("COLUMNS");
	co = env ? strtol(env, NULL, 10) : tgetnum("co");
	terminal->co = (co <= 0) ? 80 : co;

	env = getenv("LINES");
	li = env ? strtol(env, NULL, 10) : tgetnum("li");
	terminal->li = (li <= 0) ? 24 : li;

	terminal->ce = (char *) tgetstr("ce", NULL);
	terminal->cl = (char *) tgetstr("cl", NULL);
	terminal->cm = (char *) tgetstr("cm", NULL);
	terminal->cs = (char *) tgetstr("cs", NULL);
	
	terminal->scroll = wi_make_range(0, terminal->li);
	terminal->buffers = wi_array_init_with_capacity(wi_array_alloc(), 10);
	
	return terminal;
}
Esempio n. 7
0
File: main.c Progetto: Glordim/Topy
int	init_tty()
{
	int		ret;
	char*		term;
	struct termios	new_term;

	term = getenv("TERM");
	if (term == 0)
		return fatal(2, "TERM is not defined in env", 1);

	ret = tgetent(0, term);
	if (ret != 1)
		return fatal(2, "tgtent fail", 1);

	tcgetattr(0, &gl_old_term);
	new_term = gl_old_term;
	new_term.c_lflag &= ~(ECHO | ICANON);

	tcsetattr(0, TCSANOW, &new_term);
	tputs(tgetstr("vi", 0), 1, id_print_char);

	if (signal(SIGINT, signal_interrup) == SIG_ERR)
		return fatal(2, "Can't configure the signal SIGINT", 1);

	return 0;
}
Esempio n. 8
0
void		init_term(t_area *ar, char **argv, int argc)
{
  extern char	**environ;

  ar->term = cpy_from_env(environ, "TERM=");
  if (ar->term == NULL)
    {
      my_put_error(ERR_TERM);
      exit(EXIT_FAILURE);
    }
  x_tgetent(tgetent(ar->bp, ar->term));
  ar->area = ar->t;
  ar->clstr = xtgetstr("cl", &(ar->area));
  ar->cmstr = xtgetstr("cm", &(ar->area));
  ar->sostr = xtgetstr("so", &(ar->area));
  ar->sestr = xtgetstr("se", &(ar->area));
  ar->usstr = xtgetstr("us", &(ar->area));
  ar->uestr = xtgetstr("ue", &(ar->area));
  ar->li = tgetnum("li");
  ar->co = tgetnum("co");
  tputs(ar->clstr, 1, my_outc);
  argc = make_argc(ar, argc);
  ar->ac = argc - 1;
  ar->res = malloc(argc * sizeof(*(ar->res)));
  x_malloc(ar->res, argc);
  init_size(ar, argv);
  my_arg_cpy(ar, argv, argc);
}
Esempio n. 9
0
void	set_color(int bgcolor, int fgcolor)
{
  char	*afstr;
  char	*abstr;
  char	t[4096];
  char	*area;
  char	*term;
  char	bp[1024];
  
  if ((term = my_get_env("TERM")) == NULL)
    {
      my_putstr_error("can't determine terminal\n");
      exit(-1);
    }
  if (tgetent(bp, term) != 1)
    {
      my_putstr_error("problem with tgetent\n");
      exit(-1);
    }
  area = t;
  afstr = xtgetstr("AF", &area);
  abstr = xtgetstr("AB", &area);
  if (tputs(tparm(afstr, fgcolor), 1, my_outc) == ERR)
    exit(-1);
  if (bgcolor != 0)
    if (tputs(tparm(abstr, bgcolor), 1, my_outc) ==  ERR)
      exit(-1);
}
Esempio n. 10
0
int				main(int ac, char **av)
{
	t_env	env;

	if (!(isatty(0)))
		error_quit("Invalid stdin, please run from terminal");
	g_env = &env;
	env.old_width = 0;
	env.old_height = 0;
	env.list_size = ac - 1;
	env.items = NULL;
	get_tty_fd(&env);
	build_list(&env, ac, av);
	env.curr = env.items;
	init_signals();
	tgetent(0, getenv("TERM"));
	if (!(env.caps = malloc(sizeof(*env.caps))))
		error_quit("Failed to malloc env caps");
	init_caps(env.caps);
	key_codes_init(&env);
	terminal_catch();
	env.fd = 2;
	while (1)
	{
		draw_list(&env);
		read_stdin(&env);
	}
}
Esempio n. 11
0
t_caps_str	*get_variables(char **area, char **term, char bp[1024])
{
  t_caps_str	*vars;

  vars = malloc(sizeof(*vars));
  if ((*term = getenv("TERM")) == NULL)
    {
      my_printf("can't determine terminal\n");
      exit(1);
    }
  if (tgetent(bp, *term) != 1)
    {
      my_printf("problem with tgetent\n");
      exit(1);
    }
  vars->cm = xtgetstr("cm", area);
  vars->clr_scr = xtgetstr("cl", area);
  vars->cr = xtgetstr("cr", area);
  vars->up = xtgetstr("up", area);
  vars->doi = xtgetstr("do", area);
  vars->dl = xtgetstr("dl", area);
  vars->vi = xtgetstr("vi", area);
  vars->ve = xtgetstr("ve", area);
  return (vars);
}
Esempio n. 12
0
void		init(t_allum *s, int pvp)
{
  int		a;

  s->nbr_allum = 1;
  a = 1;
  if (s->nbr_lines > 53)
    {
      my_printf("Enter less than 53 lines\n");
      exit(0);
    }
  if (tgetent(NULL, s->term) == -1)
    error("Tgetent");
  while (a <= s->nbr_lines)
    {
      s->allum[a - 1] = s->nbr_allum;
      s->nbr_allum += 2;
      a += 1;
    }
  s->allum[a - 1] = -1;
  s->clean = tgetstr("cl", NULL);
  if (s->clean == NULL)
    error("Tgetstr");
  aff_allum(s);
  while (42)
    allum(s, pvp);
}
Esempio n. 13
0
int		ft_main_init(int argc, char **argv)
{
	t_list			*l_a;
	int				i;
	char			buf[2048];
	struct termios	new_term_config;

	if (tgetent(buf, getenv("TERM")) < 1)
		return (-1);
	new_term_config = ft_termios_init();
	signal(SIGTSTP, ft_take_signal);
	signal(SIGCONT, ft_take_signal);
	signal(SIGINT, ft_take_signal);
	signal(SIGWINCH, ft_take_signal);
	i = 1;
	if (argc == 1)
	{
		ft_putstr("missing arguments");
		return (0);
	}
	l_a = *ft_create_double_circular();
	while (i < argc)
	{
		ft_push_back_doub_cir(ft_create_double_circular(), argv[i]);
		i++;
	}
	return (0);
}
Esempio n. 14
0
LineEditor::LineEditor() : file(historyFile)
{
	TaskMaster::logger.Debug("new");
	std::string line;
	history.reserve(100);
	if (!file.is_open())
		file.open(historyFile, std::fstream::out);
	else
		while (file.good())
		{
			if (!std::getline(file, line).good())
				break;
			history.push_back(line);
		}
	tgetent(NULL, getenv("TERM"));
	tputs(tgetstr((char *)"im", NULL), 1, putonterm);
	tcgetattr(0, &(old));
	tcgetattr(0, &(termios_p));
	termios_p.c_lflag &= ~(ECHO | ICANON);
	tcsetattr(0, TCSADRAIN, &(termios_p));
	error = 0;
	// initscr();
	// cbreak();
	// keypad(stdscr, TRUE);
	// noecho();
	sizeX = tgetnum((char *)"co");
	std::cout << sizeX << std::endl;
	// getmaxyx(stdscr, sizeY, sizeX);
	TaskMaster::logger.Debug("x = %d, y = %d", sizeX, sizeY);
	numLine = 0;
}
Esempio n. 15
0
int
main (int argc, char **argv)
{
  char *term;
  char *buf;

  term = argv[1];
  printf ("TERM: %s\n", term);

  buf = (char *) tgetent (0, term);
  if ((int) buf <= 0)
    {
      printf ("No entry.\n");
      return 0;
    }

  printf ("Entry: %s\n", buf);

  tprint ("cm");
  tprint ("AL");

  printf ("co: %d\n", tgetnum ("co"));
  printf ("am: %d\n", tgetflag ("am"));

  return 0;
}
Esempio n. 16
0
int			init_term(void)
{
	int				k;
	int				result;
	char			*error;
	char			*type;

	k = 0;
	type = getenv("TERM");
	if (type == NULL && (k = 1))
		ft_init_deleg("Please specify terminal (setenv TERM).");
	if (k)
		result = 0;
	else
		result = tgetent(NULL, type);
	if (result < 0 && (k = 1))
		ft_init_deleg("failed to access the termcap database.");
	if (result == 0 && (k = ft_init_deleg(NULL)))
	{
		error = ft_strdup("undefined terminal type.\n");
		ft_putstr_fd(error, 2);
		free(error);
	}
	return (k);
}
Esempio n. 17
0
static void _initkeys(void)
{
  int i;
  static char *cbuf, *tbuf;
  char *term;

  if (_tptr == NULL) {
    if ((tbuf = (char *)malloc(512)) == NULL ||
        (cbuf = (char *)malloc(2048)) == NULL) {
      write(2, _("Out of memory.\n"), 15);
      exit(1);
    }
    term = getenv("TERM");
    switch (tgetent(cbuf, term)) {
      case 0:
        write(2, _("No termcap entry.\n"), 18);
        exit(1);
      case -1:
        write(2, _("No /etc/termcap present!\n"), 25);
        exit(1);
      default:
        break;
    }
    _tptr = tbuf;
  }
  /* Initialize codes for special keys */
  for (i = 0; func_key[i]; i++) {
    if ((_keys[i].cap = tgetstr(func_key[i], &_tptr)) == NULL)
      _keys[i].cap = "";
    _keys[i].len = strlen(_keys[i].cap);
  }
#if KEY_KLUDGE
  isconsole = testconsole();
#endif
}
Esempio n. 18
0
int		main(int ac, char **av)
{
	char			*name_term;
	struct termios	term;
	t_dlist			*arg;

	if (ac == 1)
		return (0);
	arg = ft_dlist_new();
	ft_init_arg(arg, av, ac);
	if ((name_term = getenv("TERM")) == NULL)
		return (-1);
	if (tgetent(NULL, name_term) == -1)
		return (-1);
	if (tcgetattr(0, &term) == -1)
		return (-1);
	tputs(tgetstr("ti", NULL), 1, ft_putchar);
	term.c_lflag &= ~(ICANON | ECHO);
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	if (tcsetattr(0, TCSADRAIN, &term) == -1)
		return (-1);
	if ((arg->fd = open("/dev/tty", O_RDWR) == -1))
		return (-1);
	ft_select(arg, term);
	close(arg->fd);
	return (0);
}
Esempio n. 19
0
int				init_termios(t_term *term, char **env)
{
	term->fd = STDIN_FILENO;
	if (!isatty(STDIN_FILENO))
		return (-1);
	term->term_name = find_env(env, "TERM");
	if (!term->term_name)
		term->term_name = "xterm-256color";
	if (tgetent(NULL, term->term_name) < 1)
	{
		term->term_name = NULL;
		return (-1);
	}
	if ((tcgetattr(term->fd, &(term)->term) == -1)
			|| (tcgetattr(term->fd, &(term)->term_bak) == -1))
	{
		ft_putendl_fd("Termios failed to init", 3);
		return (-1);
	}
	term->term.c_cc[VMIN] = 1;
	term->term.c_cc[VTIME] = 0;
	term->term.c_lflag &= ~(ICANON | ECHO);
	ioctl(term->fd, TIOCGWINSZ, &(term)->ws);
	if (tcsetattr(term->fd, 0, &(term)->term) == -1)
		return (-1);
	return (0);
}
Esempio n. 20
0
int			init_shell(void)
{
	char			*name;
	struct termios	term;
	t_term			*t;

	t = ft_get_term();
	if ((name = getenv("TERM")) == NULL)
		name = ft_strdup("xterm-256color");
	if (tgetent(NULL, name) == ERR)
	{
		ft_putendl_fd("jush: tcgetent failed", 2);
		exit(-1);
	}
	if (tcgetattr(0, &term) == -1)
		return (-1);
	t->cpy_term = term;
	term.c_lflag = term.c_lflag & (~ICANON & ~ECHO);
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	if (tcsetattr(0, 0, &term))
	{
		ft_putendl_fd("jush: tcsetattr failed", 2);
		exit(-1);
	}
	return (1);
}
Esempio n. 21
0
void init(int *rows)
{
	char  *term;
	static char   buffer[TC_BUFFER], strings[TC_STRINGS];
	char *s = strings, *v;

	*rows = 0;

	if(!(term = getenv("TERM"))) {
		fprintf(stderr, "No TERM set\n");
		exit(1);
	}

	if ( tgetent( buffer, term ) != 1 ) {
		fprintf(stderr, "tgetent failed for term %s\n", term);
		exit(1);
	}

	if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )
		Tclr_all = "\f";

	if((v = tgetstr ("li", &s)) != NULL)
		sscanf(v, "%d", rows);
	if(*rows < 1) *rows = 24;
	if(!initscr()) {
		fprintf(stderr, "initscr() failed\n");
		exit(1);
	}
	cbreak();
	nl();
}
Esempio n. 22
0
File: tty.c Progetto: rclasen/dudlc
void tty_init( const char *name, const char *prompt )
{

	if( isatty(STDOUT_FILENO)){
		char *term;
		char *area = tent;

		if( NULL == (term = getenv("TERM") )){
			term="dumb";
		}

		if( 0 <= tgetent( tent, term ) ){
			tcap.clreol = tgetstr("ce", &area );
			tcap.abold = tgetstr("md", &area );
			tcap.anorm = tgetstr("me", &area );
		}
	}

	dmsg_msg_cb = tty_vmsg;
	dfmt_bf = tcap.abold;
	dfmt_nf = tcap.anorm;

	rl_readline_name = name;
	rl_attempted_completion_function = tty_completer;

	rl_callback_handler_install( prompt, tty_executor );
}
Esempio n. 23
0
void	ft_display_menu(t_elem *l)
{
	struct termios	term;
	char			buff[5];
	int				flag;

	flag = 0;
	tgetent(NULL, getenv("TERM"));
	tcgetattr(0, &term);
	term.c_lflag &= ~(ICANON | ECHO);
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	tcsetattr(0, TCSANOW, &term);
	tputs(tgetstr("vi", NULL), 1, int_char);
	control_size(l);
	while (42)
	{
		ft_bzero(buff, 5);
		read(0, buff, 4);
		if ((buff[0] == 27 && buff[1] == 0) || buff[0] == 4)
			ft_unset_canon();
		if (control_size(l))
			l = ft_get_input(buff, l, &flag);
		else
			flag = 1;
	}
}
Esempio n. 24
0
void			ft_init(void)
{
    char		buf[1024];
    char		histo_path[1024] = {0};

    ioctl(1, TIOCGWINSZ, &g_ws);
    signal(SIGWINCH, ft_resize);
    g_env.alias_lst = NULL;
    g_env.quote_wait = 0;
    signal(SIGINT, SIG_IGN);
    g_env.pid_list = NULL;
    g_env.cut = NULL;
    g_env.histo = NULL;
    ft_get_alias_list();
    if (tgetent(buf, ft_getenv(g_env.env, "TERM")) == -1)
        exit(EXIT_FAILURE);
    tcgetattr(0, &g_env.term);
    g_env.term.c_lflag &= ~(ICANON | ECHO | ISIG);
    g_env.term.c_cc[VMIN] = 1;
    g_env.term.c_cc[VTIME] = 0;
    tcsetattr(0, 0, &g_env.term);
    ft_strcpy(histo_path, ft_getenv(g_env.env, "HOME"));
    ft_strcat(histo_path, "/.42sh_histo");
    g_env.histo_fd = open(histo_path, O_CREAT | O_RDWR, 0777);
    ft_get_history();
}
Esempio n. 25
0
/*
 * This function gets called once, to set up
 * the terminal channel. 
 */
ttopen() {
#ifdef TCCONIO
	gettextinfo(&tinfo);
	oldmode = tinfo.currmode;
#if TCCONIOMODE
	textmode(TCCONIOMODE);
#endif
	directvideo = 0;
#else
	register char *tv_stype;
	char *getenv(), tcbuf[1024], err_str[72];

/* do this the REAL way */
	if ((tv_stype = getenv("TERM")) == NULL)
	{
		puts("Environment variable TERM not defined!");
		exit(1);
	}

	if((tgetent(tcbuf, tv_stype)) != 1)
	{
		(void) sprintf(err_str, "Unknown terminal type %s!", tv_stype);
		puts(err_str);
		exit(1);
	}
#endif	/* TCCONIO */
	if (ttraw() == FALSE)
		panic("aborting due to terminal initialize failure");

#ifdef FEPCTRL	/* 90.11.26  by K.Takano */
	fepmode_init();
#endif
}
Esempio n. 26
0
main()
{
	char *cp = getenv("TERM");
	char clbuf[20];
	char pcbuf[20];
	char *clbp = clbuf;
	char *pcbp = pcbuf;
	char *clear;
	char buf[1024];
	char *pc;
	struct sgttyb tty;

	gtty(1, &tty);
	ospeed = tty.sg_ospeed;
	if (cp == (char *) 0)
		exit(1);
	if (tgetent(buf, cp) != 1)
		exit(1);
	pc = tgetstr("pc", &pcbp);
	if (pc)
		PC = *pc;
	clear = tgetstr("cl", &clbp);
	if (clear)
		tputs(clear, tgetnum("li"), putchar);
	exit (clear == (char *) 0);
}
Esempio n. 27
0
CAMLprim value caml_terminfo_setup (value vchan)
{
  value result;
  static char buffer[1024];
  char *term;

  chan = Channel (vchan);

  term = getenv ("TERM");
  if (term == NULL) return Bad_term;
  if (tgetent(buffer, term) != 1) return Bad_term;

  num_lines = tgetnum ("li");
  up = tgetstr ("up", &area_p);
  down = tgetstr ("do", &area_p);
  standout = tgetstr ("us", &area_p);
  standend = tgetstr ("ue", &area_p);
  if (standout == NULL || standend == NULL){
    standout = tgetstr ("so", &area_p);
    standend = tgetstr ("se", &area_p);
  }
  Assert (area_p <= area + 1024);
  if (num_lines == -1 || up == NULL || down == NULL
      || standout == NULL || standend == NULL){
    return Bad_term;
  }
  result = caml_alloc_small (1, Good_term_tag);
  Field (result, 0) = Val_int (num_lines);
  return result;
}
Esempio n. 28
0
/*
**      Initiate termcaps data base. If TERM environnement var is not set
**      => initiate data base with "xterm" terminal name [enable by default]
**	Remove cursor and launch raw mode.
**	If launched with reinit = 1 => set save => reinit termios.
*/
int			init_termios(char **env, int reinit)
{
  static t_termios	save;
  t_termios		t;
  char			*t_name;
  int			ret;

  if (reinit == 1)
    {
      launch_termcap(ENABLE_CURSOR);
      launch_termcap(CLEAR);
      return (tcsetattr(0, 0, &save));
    }
  t_name = my_find_in_env(env, "TERM");
  if (t_name == NULL)
    t_name = "xterm";
  ret = tgetent(NULL, t_name);
  if (ret == 0 || ret == -1 || tcgetattr(0, &t) == -1)
    return (FAILURE);
  save = t;
  t.c_lflag &= ~(ICANON | ECHO);
  t.c_cc[VMIN] = 1;
  launch_termcap("vi");
  if (tcsetattr(0, 0, &t) == -1)
    return (FAILURE);
  return (SUCCESS);
}
Esempio n. 29
0
int		ft_init_terminal_mode(struct termios tattr)
{
	char			*term_name;

	if (!(term_name = getenv("TERM")))
	{
		ft_putendl_fd("Couldn't find TERM value", 2);
		return (-1);
	}
	if (tgetent(NULL, term_name) != 1)
	{
		ft_putendl_fd("Wrong TERM value", 2);
		return (-1);
	}
	if (tcgetattr(STDIN_FILENO, &tattr) == -1)
		return (-1);
	tattr.c_lflag &= ~(OPOST);
	tattr.c_lflag &= ~(ICANON);
	tattr.c_lflag &= ~(ECHO);
	tattr.c_cc[VMIN] = 1;
	tattr.c_cc[VTIME] = 0;
	if (tcsetattr(STDIN_FILENO, TCSADRAIN, &tattr) == -1)
		return (-1);
	return (0);
}
Esempio n. 30
0
/*
 * TODO: Implement method of setting TERM env var to xterm-256color. When I do
 * this with setenv() it freezes up the terminal after the application closes
 * for some reason.
 */
int t_enable_color()
{
	get_capabilities();

	if (termtype == 0)
		return TUI_NONE_SPECIFIED;

	if (strcasecmp(termtype, "xterm-256color") != 0)
		return TUI_TERM_NOT_SUPPORTED;

	if(has_colors() == FALSE)
		return TUI_COL_NOT_SUPPORTED;

	start_color();

	int status = tgetent(term_buffer, termtype);
	if (status < 0)
		return TUI_NO_TERMCAP_ACCESS;
	if (status == 0)
		return TUI_TERM_NOT_DEFINED;

	if (maxcolors <= 0)
		return TUI_COL_NOT_IN_CAPS;
	if (maxpairs <= 0)
		return TUI_PAIRS_NOT_IN_CAPS;

	COL_MODE = 1;

	return maxcolors;
}