本文整理汇总了C++中setupterm函数的典型用法代码示例。如果您正苦于以下问题:C++ setupterm函数的具体用法?C++ setupterm怎么用?C++ setupterm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setupterm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gettermname
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++);
}
示例2: sial_setofile
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();
}
}
示例3: rt_setupterm
/*
* 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);
}
示例4: tgetent
/* 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;
}
示例5: line_editor_build_sequences
/*
** 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);
}
示例6: main
int main(int argc, const char *argv[])
{
setupterm("unlist", fileno(stdout), (int *)0);
printf("Done.\n");
return 0;
}
示例7: setupterm
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;
}
示例8: init_tty
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);
}
示例9: init_terminal
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));
}
示例10: input_init
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;
}
示例11: term_init
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");
}
示例12: getchoice
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;
}
示例13: setup_terminal
static int setup_terminal(char *term)
{
int ret;
if (setupterm(term, STDOUT_FILENO, &ret) != OK || ret != 1)
return -1;
return 0;
}
示例14: main
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);
}
示例15: detect_colors
/**
* 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);
}