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); }
static void TI_SETCOLOUR( int f, int b ) { // an array of colour brightnesses static char colorpri[] = { 0, 1, 4, 2, 6, 5, 3, 7 }; if( TCAP_MONOCHROME ) { // simulate colour using reverse (this assumes background is // darker than foreground). if( colorpri[f % 8] < colorpri[b % 8] ) { QNXDebugPrintf0( "[<enter_reverse_mode-vvvvvvvvvvvv>]" ); QNXDebugPrintf1( "\n%s\n", enter_reverse_mode ); QNXDebugPrintf0( "[<enter_reverse_mode-^^^^^^^^^^^^>]" ); TIARev = 1; TI_FillColourSet = false; } else { TIARev = 0; TI_FillColourSet = true; } TI_SETATTR(); } else { TI_SETATTR(); TI_FillColourSet = ( b == 0 ) || back_color_erase; // If we can set a colour pair then do so if( set_color_pair[0] != '\0' ) { putp( tparm( set_color_pair, f * 10 + b ) ); } else { // else try to set colors individually putp( tparm( set_background, b ) ); putp( tparm( set_foreground, f ) ); } } }
void show_line() { char *p = line; char *s = syntax; int cur_col = 0; // putp(tparm(set_a_foreground, 0)); while(*p) { if(*s != 127 && *s != cur_col) { putp(tparm(set_a_foreground, *s)); cur_col = *s; } s++; putchar(*p++); col++; if(col == width) { col = 0; row++; } } // If we ended on the end of a row, then if we eat newlines then // we need to move to the right place // output a space and then go back to get us in the right place if(col == 0 && auto_right_margin && eat_newline_glitch) { putp(carriage_return); putp(cursor_down); } if(cur_col != 0) putp(tparm(set_a_foreground, 0)); }
/* Move cursor from a known position */ static void _move_relative(TERM_REC *term, int oldx, int oldy, int x, int y) { if (oldx == 0 && x == 0 && y == oldy+1) { /* move to beginning of next line - hope this works everywhere */ tput("\r\n"); return; } if (oldx > 0 && y == oldy) { /* move cursor left/right */ if (x == oldx-1 && term->TI_cub1) { tput(tparm(term->TI_cub1)); return; } if (x == oldx+1 && y == oldy && term->TI_cuf1) { tput(tparm(term->TI_cuf1)); return; } } /* fallback to absolute positioning */ if (term->TI_cup) { tput(tparm(term->TI_cup, y, x)); return; } if (oldy != y) tput(tparm(term->TI_vpa, y)); if (oldx != x) tput(tparm(term->TI_hpa, x)); }
/* ** funkey_local(test_list, status, ch) ** ** Test program local function keys (pfloc) */ static void funkey_local( struct test_list *t, int *state, int *ch) { int fk; fk = 1; if (pkey_local) { /* test local function key */ sprintf(temp, "(pfloc) Set function key %d to execute a clear and print \"Done!\"", fk); ptextln(temp); sprintf(temp, "%sDone!", liberated(clear_screen)); tc_putp(tparm(pkey_local, fk, temp)); sprintf(temp, "Hit function key %d. Then hit return.", fk); ptextln(temp); (void) wait_here(); flush_input(); if (key_f1 && pkey_xmit) { tc_putp(tparm(pkey_xmit, fk, key_f1)); } } else { ptextln("Function key execute local (pfloc), not present."); } generic_done_message(t, state, ch); }
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; }
static void curboth(rl_t *rl, int n) { int curx=rl->curpos%rl->width; int cury=rl->curpos/rl->width; int newx=(rl->curpos+n)%rl->width; int newy=(rl->curpos+n)/rl->width; if(newy > cury) cliPutStr(rl->cliIdx,tparm(downN, newy-cury)); else if(cury > newy) cliPutStr(rl->cliIdx,tparm(upN, cury-newy)); if(newx > curx) cliPutStr(rl->cliIdx,tparm(rightN, newx-curx)); else if(curx > newx) cliPutStr(rl->cliIdx,tparm(leftN, curx-newx)); rl->curpos+=n; }
static void set_foreground_color(int fg, int (*outc)(int)) { if (set_a_foreground) { TPUTS_TRACE("set_a_foreground"); tputs(tparm(set_a_foreground, fg), 1, outc); } else { TPUTS_TRACE("set_foreground"); tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); } }
static void set_background_color(int bg, int (*outc)(int)) { if (set_a_background) { TPUTS_TRACE("set_a_background"); tputs(tparm(set_a_background, bg), 1, outc); } else { TPUTS_TRACE("set_background"); tputs(tparm(set_background, toggled_colors(bg)), 1, outc); } }
/* Setup colors - if force is set, use ANSI-style colors if terminal capabilities don't contain color codes */ void terminfo_setup_colors(TERM_REC *term, int force) { static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; const char *bold, *blink; int i; terminfo_colors_deinit(term); term->has_colors = term->TI_setf || term->TI_setaf; if (term->TI_setf) { for (i = 0; i < 8; i++) term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0)); } else if (term->TI_setaf) { for (i = 0; i < 8; i++) term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, ansitab[i], 0)); } else if (force) { for (i = 0; i < 8; i++) term->TI_fg[i] = g_strdup_printf("\033[%dm", 30+ansitab[i]); } if (term->TI_setb) { for (i = 0; i < 8; i++) term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0)); } else if (term->TI_setab) { for (i = 0; i < 8; i++) term->TI_bg[i] = g_strdup(tparm(term->TI_setab, ansitab[i], 0)); } else if (force) { for (i = 0; i < 8; i++) term->TI_bg[i] = g_strdup_printf("\033[%dm", 40+ansitab[i]); } if (term->TI_setf || term->TI_setaf || force) { term->set_fg = _set_fg; term->set_bg = _set_bg; /* bold fg, blink bg */ bold = term->TI_bold ? term->TI_bold : ""; for (i = 0; i < 8; i++) term->TI_fg[i+8] = g_strconcat(bold, term->TI_fg[i], NULL); blink = term->TI_blink ? term->TI_blink : ""; for (i = 0; i < 8; i++) term->TI_bg[i+8] = g_strconcat(blink, term->TI_bg[i], NULL); } else { /* no colors */ term->set_fg = term->set_bg = _ignore_parm; } }
int init_pair(short pair, short f, short b) { int code = ERR; if (pair < 0 || max_pairs <= pair || f < 0 || max_colors <= f || b < 0 || max_colors <= b) goto error; /* Remember color-pair settings for future queries. */ cur_term->_pair[pair][0] = f; cur_term->_pair[pair][1] = b; code = OK; /* Set color-pair (foreground-background). */ if (initialize_pair != (char *) 0) { code = tputs(tparm(initialize_pair, (long) cur_term->_color[f][0], (long) cur_term->_color[f][1], (long) cur_term->_color[f][2], (long) cur_term->_color[b][0], (long) cur_term->_color[b][1], (long) cur_term->_color[b][2], 0L, 0L, 0L), 1, __m_outc); } error: return (code); }
/* * TermInfo#tparm(str, ...) => str * * TermInfo#tparm expands parameters in str returned by tigetstr. */ static VALUE rt_tparm(int argc, VALUE *argv, VALUE self) { char *capname, *ret; setup(self); VALUE v_capname, v1, v2, v3, v4, v5, v6, v7, v8, v9; long p1, p2, p3, p4, p5, p6, p7, p8, p9; setup(self); if (rb_scan_args(argc, argv, "19", &v_capname, &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9) == 0) { rb_raise(rb_eArgError, "capname required"); } capname = StringValueCStr(v_capname); #define conv(p, v) do { if (v == Qnil) p = 0; else p = NUM2LONG(v); } while(0) conv(p1, v1); conv(p2, v2); conv(p3, v3); conv(p4, v4); conv(p5, v5); conv(p6, v6); conv(p7, v7); conv(p8, v8); conv(p9, v9); ret = tparm(capname, p1, p2, p3, p4, p5, p6, p7, p8, p9); if (ret == NULL) { rb_raise(eTermInfoError, "tparm failed"); } return rb_str_new2(ret); }
/* ** tt_putparm(string, reps, arg1, arg2, ...) ** ** Send tt_tputs(tparm(string, args...), reps) ** Use this function inside timing tests. */ void tt_putparm( NCURSES_CONST char *string, int reps, int arg1, int arg2) { int i; if (string) { for (i = 0; i < TT_MAX; i++) { if (i >= ttp) { tt_cap[i] = string; tt_affected[i] = reps; tt_count[i] = 1; tt_delay[i] = msec_cost(string, reps); ttp++; break; } if (string == tt_cap[i] && reps == tt_affected[i]) { tt_count[i]++; tt_delay_used += tt_delay[i]; break; } } (void) tputs(tparm((NCURSES_CONST char *)string, arg1, arg2), reps, tc_putch); } }
/* * 端末の描画領域をstartからendに設定する */ void put_change_scroll_region(int start, int end) { const char *tmp = tparm(change_scroll_region, start, end); my_putp(tmp); s_cursor.row = s_cursor.col = 0; debug(("<region %d %d>", start, end)); }
/* ** funkey_label(test_list, status, ch) ** ** Test labels (nlab) (smln) (pln) (rmln) (lw) (lh) */ static void funkey_label( struct test_list *t, int *state, int *ch) { int i; char outbuf[256]; if (num_labels == -1) { ptextln("Your terminal has no labels. (nlab)"); } else { sprintf(temp, "Your terminal has %d labels (nlab) that are %d characters wide (lw) and %d lines high (lh)", num_labels, label_width, label_height); ptext(temp); ptextln(" Testing (smln) (pln) (rmln)"); if (label_on) { tc_putp(label_on); } if (label_width <= 0) { label_width = sizeof(outbuf) - 1; } for (i = 1; i <= num_labels; i++) { sprintf(outbuf, "L%d..............................", i); outbuf[label_width] = '\0'; tc_putp(tparm(plab_norm, i, outbuf)); } if (label_off) { ptext("Hit any key to remove the labels: "); (void) wait_here(); tc_putp(label_off); } } generic_done_message(t, state, ch); }
int init_color(short color, short r, short g, short b) { T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); if (initialize_color == NULL) returnCode(ERR); if (color < 0 || color >= COLORS) returnCode(ERR); if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) returnCode(ERR); if (hue_lightness_saturation) rgb2hls(r, g, b, &SP->_color_table[color].red, &SP->_color_table[color].green, &SP->_color_table[color].blue); else { SP->_color_table[color].red = r; SP->_color_table[color].green = g; SP->_color_table[color].blue = b; } if (initialize_color) { TPUTS_TRACE("initialize_color"); putp(tparm(initialize_color, color, r, g, b)); } returnCode(OK); }
static void TI_SETATTR( void ) { // we have to reset attributes as some terminals can't turn off // attributes with "set_attribues" putp( exit_attribute_mode ); if( set_attributes[0]!='\0' ){ char *x; putp( x=tparm( set_attributes, 0, // standout TIAULine, // underline TIARev, // reverse TIABlink, // blink 0, // half intensity TIABold, // bold 0, // invisible 0, // protected TIAACS ) ); // alt. char set QNXDebugPrintf0("\n[******]"); QNXDebugPrintf1("%s", set_attributes); QNXDebugPrintf1("%s",x); QNXDebugPrintf0("[~~~~~~]\n"); } else { // Believe it or not, some terminals don't have the set_attributes // code in the database, so we have to simulate it occasionally if( TIAULine ) putp( enter_underline_mode ); if( TIARev ) putp( enter_reverse_mode ); if( TIABlink ) putp( enter_blink_mode ); if( TIABold ) putp( enter_bold_mode ); if( TIAACS ) putp( enter_alt_charset_mode ); } }
int init_color(short color, short r, short g, short b) { int code = ERR; if (!can_change || color < 0 || max_colors <= color || r < 0 || 1000 < r || g < 0 || 1000 < g || b < 0 || 1000 < b) goto error; /* Remember color settings for future queries. */ cur_term->_color[color][0] = r; cur_term->_color[color][1] = g; cur_term->_color[color][2] = b; code = OK; /* Set the color. */ if (initialize_color != (char *) 0) { code = tputs(tparm(initialize_color, (long) color, (long) r, (long) g, (long) b, 0L, 0L, 0L, 0L, 0L), 1, __m_outc); } error: return (code); }
/* ** display_basic() ** ** display the basic terminal definitions */ void display_basic(void) { put_str("Name: "); putln(ttytype); report_cap("\\r ^M (cr)", carriage_return); report_cap("\\n ^J (ind)", scroll_forward); report_cap("\\b ^H (cub1)", cursor_left); report_cap("\\t ^I (ht)", tab); /* report_cap("\\f ^L (ff)", form_feed); */ if (newline) { /* OK if missing */ report_cap(" (nel)", newline); } report_cap(" (clear)", clear_screen); if (!cursor_home && cursor_address) { report_cap("(cup) (home)", tparm(cursor_address, 0, 0)); } else { report_cap(" (home)", cursor_home); } #ifdef user9 report_cap("ENQ (u9)", user9); #endif #ifdef user8 report_cap("ACK (u8)", user8); #endif sprintf(temp, "\nTerminal size: %d x %d. Baud rate: %u. Frame size: %d.%d", columns, lines, tty_baud_rate, tty_frame_size >> 1, (tty_frame_size & 1) * 5); putln(temp); }
/// Detect whether the escape sequence sets one of the terminal attributes that affects how text is /// displayed other than the color. static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length) { if (!cur_term) return false; const char *const esc2[] = { enter_bold_mode, exit_attribute_mode, enter_underline_mode, exit_underline_mode, enter_standout_mode, exit_standout_mode, flash_screen, enter_subscript_mode, exit_subscript_mode, enter_superscript_mode, exit_superscript_mode, enter_blink_mode, enter_italics_mode, exit_italics_mode, enter_reverse_mode, enter_shadow_mode, exit_shadow_mode, enter_standout_mode, exit_standout_mode, enter_secure_mode, enter_dim_mode, enter_blink_mode, enter_protected_mode, enter_alt_charset_mode, exit_alt_charset_mode}; for (size_t p = 0; p < sizeof esc2 / sizeof *esc2; p++) { if (!esc2[p]) continue; // Test both padded and unpadded version, just to be safe. Most versions of tparm don't // actually seem to do anything these days. size_t esc_seq_len = std::max(try_sequence(tparm((char *)esc2[p]), code), try_sequence(esc2[p], code)); if (esc_seq_len) { *resulting_length = esc_seq_len; return true; } } return false; }
/* ** subtest_mir(test_list, status, ch) ** ** (mir) move in insert mode */ static void subtest_mir( struct test_list *t, int *state, int *ch) { int i; char *s; if (enter_insert_mode && exit_insert_mode && cursor_address) { put_clear(); i = line_count; put_str("\nXXX\nXXX\nXXX\nXXX"); tc_putp(enter_insert_mode); s = tparm(cursor_address, i + 1, 0); tputs(s, lines, tc_putch); putchp('X'); s = tparm(cursor_address, i + 2, 1); tputs(s, lines, tc_putch); putchp('X'); s = tparm(cursor_address, i + 3, 2); tputs(s, lines, tc_putch); putchp('X'); s = tparm(cursor_address, i + 4, 3); tputs(s, lines, tc_putch); putchp('X'); tc_putp(exit_insert_mode); put_newlines(2); ptextln("If you see a 4 by 4 block of X's then (mir) should be true."); sprintf(temp, "(mir) Move-in-insert-mode is %s in the data base", move_insert_mode ? "true" : "false"); ptextln(temp); } else { ptext("(mir) Move-in-insert-mode not tested, "); if (!enter_insert_mode) { ptext("(smir) "); } if (!exit_insert_mode) { ptext("(rmir) "); } if (!cursor_address) { ptext("(cup) "); } ptext("not present. "); } generic_done_message(t, state, ch); }
/* ** subtest_msgr(test_list, status, ch) ** ** (msgr) move in sgr mode */ static void subtest_msgr( struct test_list *t, int *state, int *ch) { int i; if (cursor_address && ((enter_standout_mode && exit_standout_mode) || (enter_alt_charset_mode && exit_alt_charset_mode))) { put_crlf(); i = line_count + 1; tputs(tparm(cursor_address, i, 0), lines, tc_putch); put_mode(enter_alt_charset_mode); put_crlf(); /* some versions of the wy-120 can not clear lines or screen when in alt charset mode. If (el) and (ed) are defined then I can test them. If they are not defined then they can not break (msgr) */ tc_putp(clr_eos); tc_putp(clr_eol); put_mode(exit_alt_charset_mode); put_mode(enter_standout_mode); putchp('X'); tputs(tparm(cursor_address, i + 2, 1), lines, tc_putch); putchp('X'); tputs(tparm(cursor_address, i + 3, 2), lines, tc_putch); putchp('X'); tputs(tparm(cursor_address, i + 4, 3), lines, tc_putch); putchp('X'); put_mode(exit_standout_mode); put_crlf(); tc_putp(clr_eos); /* OK if missing */ put_crlf(); ptextln("If you see a diagonal line of standout X's then (msgr) should be true. If any of the blanks are standout then (msgr) should be false."); sprintf(temp, "(msgr) Move-in-SGR-mode is %s in the data base", move_standout_mode ? "true" : "false"); ptextln(temp); } else { ptextln("(smso) (rmso) (smacs) (rmacs) missing; (msgr) Move-in-SGR-mode not tested."); } generic_done_message(t, state, ch); }
/* Clear screen (delete_line / dl1) */ static void _clear_del_1(TERM_REC *term) { int i; term->move(term, 0, 0); for (i = 0; i < term->height; i++) tput(tparm(term->TI_dl1)); }
/* Scroll (change_scroll_region+parm_rindex+parm_index / csr+rin+indn) */ static void _scroll_region(TERM_REC *term, int y1, int y2, int count) { /* setup the scrolling region to wanted area */ scroll_region_setup(term, y1, y2); term->move(term, 0, y1); if (count > 0) { term->move(term, 0, y2); tput(tparm(term->TI_indn, count, count)); } else if (count < 0) { term->move(term, 0, y1); tput(tparm(term->TI_rin, -count, -count)); } /* reset the scrolling region to full screen */ scroll_region_setup(term, 0, term->height-1); }
char * tparm_p0(char *instring) { long p[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; return (tparm(instring, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8])); }
void zterp_os_set_style(int style, int fg, int bg) { /* If the terminal cannot be reset, nothing can be used. */ if(none == NULL) return; putp(none); if((style & STYLE_ITALIC) && ital != NULL) putp(ital); if((style & STYLE_REVERSE) && rev != NULL) putp(rev); if((style & STYLE_BOLD) && bold != NULL) putp(bold); if(have_colors) { if(fg > 1) putp(tparm(fg_string, fg - 2, 0, 0, 0, 0, 0, 0, 0, 0)); if(bg > 1) putp(tparm(bg_string, bg - 2, 0, 0, 0, 0, 0, 0, 0, 0)); } }
void mbackspace_head_of_line_immediately() { const int maxx = mgetmaxx(); write_escape_suqence(tigetstr("cuu1")); write_escape_suqence(tparm(tigetstr("cuf"), maxx)); write_escape_suqence(tigetstr("dch1")); }
static void reset_scroll_region(void) /* Set the scroll-region to a known state (the default) */ { if (change_scroll_region) { TPUTS_TRACE("change_scroll_region"); putp(tparm(change_scroll_region, 0, screen_lines - 1)); } }
static char * set_attribute_9(TERMTYPE *tp, int flag) { const char *result; if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0) result = ""; return strdup(result); }
static int term_restore(lua_State *L) { int rc; rc = tcsetattr(0, TCSANOW, &saved_termios); putp(tparm(keypad_local)); if (rc != 0) luaL_error(L, "unable to tcsetattr: %d", rc); return 0; }