Ejemplo n.º 1
0
static const char *
gettermname(void)
{
	char *tname;
	static const char **tnamep = NULL;
	static const char **next;
	int err;

	if (resettermname) {
		resettermname = 0;
		if (tnamep && tnamep != unknown)
			free(tnamep);
		if ((tname = env_getvalue("TERM")) &&
				(setupterm(tname, 1, &err) == 0)) {
			tnamep = mklist(termbuf, tname);
		} else {
			if (tname && (strlen(tname) <= 40)) {
				unknown[0] = tname;
				upcase(tname);
			} else
				unknown[0] = name_unknown;
			tnamep = unknown;
		}
		next = tnamep;
	}
	if (*next == NULL)
		next = tnamep;
	return(*next++);
}
Ejemplo n.º 2
0
void
sial_setofile(void * f)
{
int out;
int ret;
char *term;

	ofile=(FILE *)f;

	bold_on="";
	bold_off="";
	cols=80;

	out=fileno(ofile);
        if(isatty(out))
        {

        	if(!(term = getenv ("TERM"))) term="dumb";
        	if(setupterm(term, out, &ret)!=ERR)
        	{
                	bold_on=tigetstr("bold");
			if(!bold_on) bold_on="";
                	bold_off=tigetstr("sgr0");
			if(!bold_off) bold_off="";
        	}
		sial_getwinsize();
        }
}
Ejemplo n.º 3
0
gboolean wsh_client_has_colors(void) {
	if (_wsh_client_colors != colors_undecided)
		return (gboolean)_wsh_client_colors;

	g_mutex_lock(&client_mtx);

	// if we were blocked, we were probably waiting on deciding if we had
	// colors so check again
	if (_wsh_client_colors != colors_undecided)
		goto out;

	// Use error here so we don't output a message on failure
	gint err = 0;
	if (setupterm(NULL, fileno(stdout), &err) == ERR) {
		_wsh_client_colors = colors_unavail;
		goto out;
	}

	if (has_colors()) {
		_wsh_client_colors = colors_avail;
		goto out;
	}

	_wsh_client_colors = colors_unavail;

out:
	g_mutex_unlock(&client_mtx);
	return (gboolean)_wsh_client_colors;
}
Ejemplo n.º 4
0
/*
 * TermInfo#setupterm(term, fd) => int
 *
 * TermInfo#setupterm initializes TermInfo object.
 *
 * term is a string of nil.
 * If nil is given, the environment variable $TERM is used.
 *
 * fd is a file descriptor for target terminal.
 */
static VALUE
rt_setupterm(VALUE self, VALUE v_term, VALUE v_fd)
{
  char *term;
  int fd;
  int err;
  int ret;
  if (check_rt(self) != NULL) { rb_raise(eTermInfoError, "terminfo object already initialized"); }

  if (v_term == Qnil)
    term = NULL;
  else
    term = StringValueCStr(v_term);
  fd = NUM2INT(v_fd);

  ret = setupterm(term, fd, &err);
  if (ret == ERR) {
    if (err == 1) rb_raise(eTermInfoError, "hardcopy terminal");
    else if (err == 0) rb_raise(eTermInfoError, "terminal could not be found");
    else if (err == -1) rb_raise(eTermInfoError, "terminfo database could not be found");
    else rb_raise(eTermInfoError, "unexpected setupterm error");
  }

  DATA_PTR(self) = cur_term;

  return INT2NUM(err);
}
Ejemplo n.º 5
0
/* ARGSUSED */
int
tgetent(__unused char *bp, const char *name)
{
	int errret;
	static TERMINAL *last = NULL;

	_DIAGASSERT(name != NULL);

	/* Free the old term */
	if (cur_term != NULL) {
		if (last != NULL && cur_term != last)
			del_curterm(last);
		last = cur_term;
	}
	errret = -1;
	if (setupterm(name, STDOUT_FILENO, &errret) != 0)
		return errret;

	if (last == NULL)
		last = cur_term;

	if (pad_char != NULL)
		PC = pad_char[0];
	UP = __UNCONST(cursor_up);
	BC = __UNCONST(cursor_left);
	return 1;
}
Ejemplo n.º 6
0
/*
** Builds termcaps sequences
** @params self, env
** @return bool; Success => TRUE, Error => FALSE
*/
bool		line_editor_build_sequences(t_line_editor *self, char **env)
{
  int		ret;
  char		*key_pad;

  setupterm(get_term(env), 1, &ret);
  if (ret <= 0)
    return (false);
  if ((key_pad = tigetstr("smkx")) == NULL)
    return (false);
  putp(key_pad);
  if ((self->keys[L_KEY_LEFT].sequence = dup_key("kcub1")) == NULL)
    return (false);
  self->keys[L_KEY_LEFT].handle = line_editor_handle_left;
  if ((self->keys[L_KEY_RIGHT].sequence = dup_key("kcuf1")) == NULL)
    return (false);
  self->keys[L_KEY_RIGHT].handle = line_editor_handle_right;
  if ((self->keys[L_KEY_UP].sequence = dup_key("kcuu1")) == NULL)
    return (false);
  self->keys[L_KEY_UP].handle = line_editor_handle_up;
  if ((self->keys[L_KEY_DOWN].sequence = dup_key("kcud1")) == NULL)
    return (false);
  self->keys[L_KEY_DOWN].handle = line_editor_handle_down;
  if (line_editor_build_second_sequences(self) == false)
    return (false);
  return (true);
}
Ejemplo n.º 7
0
int main(int argc, const char *argv[])
{
  setupterm("unlist", fileno(stdout), (int *)0);
  printf("Done.\n");

  return 0;
}
Ejemplo n.º 8
0
int FocusClient::init ()
{
	rts2core::Configuration *config;
	int ret;

	ret = rts2core::Client::init ();
	if (ret)
		return ret;

	setupterm (NULL, 2, NULL);

	signal (SIGWINCH, signal_winch);

	config = rts2core::Configuration::instance ();
	ret = config->loadFile (configFile);
	if (ret)
	{
		std::cerr << "Cannot load configuration file '"
			<< (configFile ? configFile : "/etc/rts2/rts2.ini")
			<< ")" << std::endl;
		return ret;
	}
	addTimer (CHECK_TIMER, new rts2core::Event (EVENT_EXP_CHECK));
	return 0;
}
Ejemplo n.º 9
0
void
init_tty(void)
{
	struct termios	 new_attributes;
	int		 i;

	if ((tty_in = fopen("/dev/tty", "r")) == NULL) {
		err(1, "fopen");
	}

	tcgetattr(fileno(tty_in), &original_attributes);
	new_attributes = original_attributes;
	new_attributes.c_lflag &= ~(ICANON | ECHO);
	tcsetattr(fileno(tty_in), TCSANOW, &new_attributes);

	if ((tty_out = fopen("/dev/tty", "w")) == NULL)
		err(1, "fopen");

	setupterm((char *)0, fileno(tty_out), (int *)0);

	if (use_alternate_screen)
		tty_putp(enter_ca_mode);

	/* Emit enough lines to fit all choices. */
	for (i = 0; i < (ssize_t)choices.length && i < lines - 1; ++i)
		tty_putp(cursor_down);
	for (; i > 0; --i)
		tty_putp(cursor_up);
	tty_putp(save_cursor);

	signal(SIGINT, handle_sigint);
}
Ejemplo n.º 10
0
static void init_terminal(struct setterm_control *ctl)
{
	int term_errno;

	if (!ctl->opt_te_terminal_name) {
		ctl->opt_te_terminal_name = getenv("TERM");
		if (ctl->opt_te_terminal_name == NULL)
			errx(EXIT_FAILURE, _("$TERM is not defined."));
	}

	/* Find terminfo entry. */
	if (setupterm(ctl->opt_te_terminal_name, STDOUT_FILENO, &term_errno))
		switch (term_errno) {
		case -1:
			errx(EXIT_FAILURE, _("terminfo database cannot be found"));
		case 0:
			errx(EXIT_FAILURE, _("%s: unknown terminal type"), ctl->opt_te_terminal_name);
		case 1:
			errx(EXIT_FAILURE, _("terminal is hardcopy"));
		}

	/* See if the terminal is a virtual console terminal. */
	ctl->vcterm = (!strncmp(ctl->opt_te_terminal_name, "con", 3) ||
		       !strncmp(ctl->opt_te_terminal_name, "linux", 5));
}
Ejemplo n.º 11
0
int input_init()
{
	if( is_init )
		return 1;
	
	is_init = 1;

	input_common_init( &interrupt_handler );

	if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
	{
		debug( 0, _( L"Could not set up terminal" ) );
		exit(1);
	}
	output_set_term( env_get( L"TERM" ) );
	
	input_terminfo_init();

	/*
	  If we have no keybindings, add a few simple defaults
	*/
	if( !al_get_count( &mappings ) )
	{
		input_mapping_add( L"", L"self-insert" );
		input_mapping_add( L"\n", L"execute" );
		input_mapping_add( L"\t", L"complete" );
		input_mapping_add( L"\x3", L"commandline \"\"" );
		input_mapping_add( L"\x4", L"exit" );
		input_mapping_add( L"\x5", L"bind" );
	}

	return 1;
}
Ejemplo n.º 12
0
void
term_init(void)
{
        setupterm(NULL, 1, NULL);
        if (tcgetattr(0, &term_init_termios) < 0)
                epanic("failed to get terminal attributes");

        // Handle terminal resize
        struct sigaction act = {
                .sa_handler = term_on_sigwinch
        };
        if (sigaction(SIGWINCH, &act, NULL) < 0)
                epanic("failed to install SIGWINCH handler");

        atexit(term_reset);
        term_initialized = true;

        // Enter cursor mode
        putp(enter_ca_mode);
        // Enter invisible mode
        putp(cursor_invisible);
        // Disable echo and enter canonical (aka cbreak) mode so we
        // get input without waiting for newline
        struct termios tc = term_init_termios;
        tc.c_lflag &= ~(ICANON | ECHO);
        tc.c_iflag &= ~ICRNL;
        tc.c_lflag |= ISIG;
        tc.c_cc[VMIN] = 1;
        tc.c_cc[VTIME] = 0;
        if (tcsetattr(0, TCSAFLUSH, &tc) < 0)
                epanic("failed to set terminal attributes");
}
Ejemplo n.º 13
0
int getchoice(char *greet, char *choices[], FILE *in, FILE *out)
{
	int chosen = 0;
	int selected;
	char **option;
	
	int screenrow = 0, screencol = 10;
	char *cursor, *clear;


	output_stream = out;


	setupterm(NULL, fileno(out), (int *)0);
	cursor = tigetstr("cup");
	clear = tigetstr("clear");

	screenrow = 4;
	tputs(clear, 1, (int *) char_to_terminal);
	tputs(tparm(cursor, screenrow, screencol), 1, char_to_terminal);
	fprintf(out, "Choice: %s", greet);

	screenrow += 2;
	option = choices;
	while(*option){
		tputs(tparm(cursor, screenrow, screencol), 1, char_to_terminal);
		fprintf(out, "%s", *option);
		screenrow ++;
		option ++;
	}
	
	fprintf(out, "\n");

	do{
		fflush(out);
		selected = fgetc(in);
		option = choices;
	
		while(*option){
			if(selected == *option[0]){
				chosen = 1;
				break;
			}

			option ++;
		}

		if(!chosen){
			tputs(tparm(cursor, screenrow, screencol), 1, char_to_terminal);
			fprintf(out, "Incorrect choice, select again\n");
		}

	}while(!chosen);
		
	tputs(clear, 1, char_to_terminal);
		
	return selected;

}
Ejemplo n.º 14
0
static int setup_terminal(char *term)
{
	int ret;

	if (setupterm(term, STDOUT_FILENO, &ret) != OK || ret != 1)
		return -1;
	return 0;
}
Ejemplo n.º 15
0
int main(void)
{
   int nrows, ncols; 
   setupterm(NULL, fileno(stdout), (int *)0);
   nrows = tigetnum("lines");
   ncols = tigetnum("cols");
   printf("This terminal has %d columns and %d rows\n", ncols, nrows);
   exit(0);
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
/**
 * Detect if we can generate colored output
 */
bool detect_colors() {
	int erret = 0;
	if(setupterm(NULL, 1, &erret) == ERR) {
		return false;
	}

	// colorize if the terminal supports colors and we're writing to a terminal
	return has_colors() && isatty(STDOUT_FILENO);
}
Ejemplo n.º 18
0
int main() {
  setupterm(NULL, 1, NULL);
  const char* setf = tigetstr("setaf");
  //  putp(setf);
  const char* red = tparm(setf, 1);
  putp(red);
  printf("whooo!\n");
  return 1;
}
Ejemplo n.º 19
0
void mcurses_init()
{
    if(setupterm(NULL, STDOUT_FILENO, (int*) 0) == ERR) {
        fprintf(stderr, "invalid TERM setting");
        exit(1);
    }

    gMCTtyFd = open("/dev/tty", O_RDWR);
}
Ejemplo n.º 20
0
static void initputvar() {
    if (putvarc)
        free(putvarc);
    putvarc=(char *)calloc(256, sizeof(char));
    putvari=0;

    if (!istermsetup)
        istermsetup = (OK == setupterm(NULL, STDERR_FILENO, NULL));
}
Ejemplo n.º 21
0
static int setup_terminal(char *term)
{
#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW)
	int ret;

	if (setupterm(term, STDOUT_FILENO, &ret) != OK || ret != 1)
		return -1;
#endif
	return 0;
}
Ejemplo n.º 22
0
int
sc_isAvailable ()
{
  int err;

  if (setupterm((char *)0, 1, &err) == ERR)
    return FALSE;

  return tigetstr("cup") != NULL;
}
 void cls()
 {
     if (!cur_term)
     {
         int result;
         setupterm( NULL, STDOUT_FILENO, &result );
         if (result <= 0) return;
     }
     putp( tigetstr( "clear" ) );
 }
Ejemplo n.º 24
0
int
restartterm(char *name, int fd, int *err)
{
	const termio_desc_t *otdp = tdp;
	int status;

	if ((status = setupterm(name, fd, err)) != OK)
		tdp = otdp; /* restore old terminal settings */

	return (status);
}
Ejemplo n.º 25
0
void voce_perdeu(){
	setupterm(NULL, STDOUT_FILENO, NULL);
	putp(tparm(set_a_foreground, 1));
	printf("\n");
	printf("#            #######   ##########   #########\n");
	printf("#           ##     ##   #           #        \n");
	printf("#          ##       ##   #          #        \n");
	printf("#         ##         ##    ####     #####    \n");
	printf("#          ##       ##          #   #        \n");
	printf("#           ##     ##          #    #        \n");
	printf("#######      #######     ######     #########\n");
}
Ejemplo n.º 26
0
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;
	}
}
Ejemplo n.º 27
0
static void
_O_st_init()
{
	char termn[Z_WORDLEN];
#ifdef M_TERMCAP
	static	char entry[1024];
#endif

	/*
	**	see if standard out is a terminal
	*/
	if (!isatty(1))
	{
		_O_need_init = 0;
		_O_st_ok = 0;
		return;
	}

	if (NULL == (_O_st_tmp = (char*) getenv("TERM")))
	{
		Z_complain("can't find TERM entry in environment\n");
		_O_need_init = 0;
		_O_st_ok = 0;
		return;
	}
	(void) strcpy(termn,_O_st_tmp);

#ifdef M_TERMCAP
	if (1 != tgetent(entry,termn))
	{
		Z_complain("can't get TERMCAP info for terminal\n");
		_O_need_init = 0;
		_O_st_ok = 0;
		return;
	}

	_O_st_tmp = _O_startline;
	_O_startline[0] = '\0';
	tgetstr("so",&_O_st_tmp);

	_O_st_tmp = _O_endline;
	_O_endline[0] = '\0';
	tgetstr("se",&_O_st_tmp);

	_O_st_ok = (strlen(_O_startline) > 0) && (strlen(_O_endline) > 0);
#endif

#ifdef M_TERMINFO
	setupterm(termn,1,&_O_st_ok);
#endif
	_O_need_init = 0;
}
Ejemplo n.º 28
0
static void
test_setupterm(NCURSES_CONST char *name)
{
    int rc;
    int err = -99;

    if (r_opt) {
	rc = restartterm(name, 0, f_opt ? NULL : &err);
    } else {
	rc = setupterm(name, 0, f_opt ? NULL : &err);
    }
    test_rc(name, rc, err);
}
Ejemplo n.º 29
0
int init_ncurses(void){
	if(isatty(STDOUT_FILENO)){
		int errret;

		// If NULL is passed, $TERM is used
		if(setupterm(NULL,STDOUT_FILENO,&errret) != OK){
			bitch("Couldn't set up terminfo(5) database (errret %d)\n",errret);
			return -1;
		}
		use_terminfo = 1;
	}
	return 0;
}
Ejemplo n.º 30
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);
}