static void showports(void) { struct pitem *p; struct servent *sp; for (p = ports; p < ports+nports; p++) { sp = getservbyport(p->port, protos == (TCP|UDP) ? 0 : protos == TCP ? "tcp" : "udp"); if (!p->onoff) addch('!'); if (sp) printw("%s ", sp->s_name); else printw("%d ", p->port); } }
int main(void) { int line; int i; char c; initscr(); refresh(); for(line=0;line<LINES;line++){ move(line,line); c=line+'0'; addch(c); usleep(200000); refresh(); } endwin(); }
APIRET16 APIENTRY16 VioWrtCharStr (PCCH pchStr, USHORT cb, USHORT usRow, USHORT usColumn, HVIO hvio) { SAVEENV; int x, y; VioInitCurses(); getyx(stdscr, y, x); /* this is a macro in curses */ move((int)usRow, (int)usColumn); while (cb > 0) { addch(*pchStr); cb--; pchStr++; } move(y, x); RESTOREENV_RETURN(NO_ERROR); }
/* * get_line: * Reads the next line up to '\n' or EOF. Multiple spaces are * compressed to one space; a space is inserted before a ',' */ char * get_line(void) { size_t pos; int c, oy, ox; WINDOW *oscr; oscr = stdscr; stdscr = Msgwin; getyx(stdscr, oy, ox); refresh(); /* loop reading in the string, and put it in a temporary buffer */ for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) { if (c == erasechar()) { /* process erase character */ if (pos > 0) { int i; pos--; for (i = strlen(unctrl(linebuf[pos])); i; i--) addch('\b'); } continue; } else if (c == killchar()) { /* process kill * character */ pos = 0; move(oy, ox); continue; } else if (pos == 0 && c == ' ') continue; if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' ')) putchar(CTRL('G')); else { if (islower(c)) c = toupper(c); linebuf[pos++] = c; addstr(unctrl(c)); Mpos++; } } linebuf[pos] = '\0'; stdscr = oscr; return (linebuf); }
static void draw_activity(gchar *title, gboolean act, gboolean det) { WINDOW_REC *window; GList *tmp; gchar str[MAX_INT_STRLEN]; gboolean first, is_det; set_color(stdscr, sbar_color_normal); addstr(title); first = TRUE; for (tmp = activity_list; tmp != NULL; tmp = tmp->next) { window = tmp->data; is_det = window->new_data >= NEWDATA_HILIGHT; if (is_det && !det) continue; if (!is_det && !act) continue; if (first) first = FALSE; else { set_color(stdscr, sbar_color_dim); addch(','); } ltoa(str, window->refnum); switch (window->new_data) { case NEWDATA_TEXT: set_color(stdscr, sbar_color_dim); break; case NEWDATA_MSG: set_color(stdscr, sbar_color_bold); break; case NEWDATA_HILIGHT: if (window->last_color > 0) set_color(stdscr, sbar_color_background | mirc_colors[window->last_color]); else set_color(stdscr, sbar_color_act_highlight); break; } addstr(str); } }
void drawTrisGame() { int i; switch(state) { case mainMenu: mainMenuDraw(videoBuffer0); break; case inGame: playTrisDraw(videoBuffer0); break; } #ifndef _WIN32 move(0,0); #endif for(i = 0; i < VIDEOBUFFER_SIZE-1; i++) { #ifdef _WIN32 int row = i / consoleBase, column = i % consoleBase; if(videoBuffer0[i] != videoBuffer1[i]) { DWORD writenChar; COORD coord; coord.Y = row; coord.X = column; SetConsoleCursorPosition(outHandle, coord); WriteFile(outHandle, videoBuffer0 + i, 1, &writenChar, NULL); } #else addch(*(videoBuffer0 + i)); #endif } //scambio videoBuffer swapVideoBuffer(); #ifndef _WIN32 refresh(); #endif }
// Draw a box void print_box(int x, int y, int w, int h, char *label, int bold) { int i, j; if (bold > 0) attron(A_BOLD); move(y, x); addch(ACS_ULCORNER); for (i=0; i<w-2; i++) addch(ACS_HLINE); addch(ACS_URCORNER); for (i=0; i<h-2; i++) { move(y + i + 1, x); addch(ACS_VLINE); for (j=0; j<w-2; j++) printw(" "); addch(ACS_VLINE); } move(y + h - 1, x); addch(ACS_LLCORNER); for (i=0; i<w-2; i++) addch(ACS_HLINE); addch(ACS_LRCORNER); if (bold > 0) attron(A_REVERSE); mvprintw(y + (h / 2), x + 1, label); if (bold > 0) { attroff(A_BOLD); attroff(A_REVERSE); } }
extern void tty_print_char(int c) { #ifdef HAVE_SLANG /* We cannot use SLsmg_write_char here because the Debian and Redhat * people thought changing the API of an external project was fun, * especially when it depends on the preprocessor symbol UTF8 being * defined or not. Congratulations! At least, they left the API call * for SLsmg_write_nchars as it has always been. */ char ch; ch = c; SLsmg_write_nchars(&ch, 1); #else addch(c); #endif }
void change_number(int ch) { int x,y,i,j; getyx(stdscr,y,x); for(i=0;i<9;i++) {if(y ==g.top+i+1+i/3) break;} for(j=0; j<9; j++) {if(x==g.left+2+2*(j+j/3)) break;} if(!g.board[i][j]){ {addch(ch); mvaddch(y,x+1,' ');} refresh(); } }
void remove_dash (void) { #ifndef HAVE_X if (!nice_rotating_dash) return; /* Currently, it's much nicer with the CPU to do this instead of calling do_refresh. I should implement a routine called invalidate_region that would send a draw message only to the affected views. But for now this is fine. */ move (0, COLS-1); addch (' '); #endif }
/* Displays bottom status line or current prompt */ void do_bottom_line(void) { move(lines()-1, 2); if (prompt != NULL) { printw("%s: %s", prompt, prompt_val); } else { addch(A_REVERSE | 'D'); addstr("elay "); /* network */ addch(A_REVERSE | 'N'); attr_addstr(show_networks ? COLOR_PAIR(1) : 0, "etworks"); addstr(" "); /* VBDs */ attr_addstr(show_vbds ? COLOR_PAIR(1) : 0, "v"); addch(A_REVERSE | 'B'); attr_addstr(show_vbds ? COLOR_PAIR(1) : 0, "ds"); addstr(" "); /* tmem */ addch(A_REVERSE | 'T'); attr_addstr(show_tmem ? COLOR_PAIR(1) : 0, "mem"); addstr(" "); /* vcpus */ addch(A_REVERSE | 'V'); attr_addstr(show_vcpus ? COLOR_PAIR(1) : 0, "CPUs"); addstr(" "); /* repeat */ addch(A_REVERSE | 'R'); attr_addstr(repeat_header ? COLOR_PAIR(1) : 0, "epeat header"); addstr(" "); /* sort order */ addch(A_REVERSE | 'S'); addstr("ort order "); addch(A_REVERSE | 'Q'); addstr("uit "); } }
void sinsp_cursesui::render_position_info() { if(m_chart == NULL) { return; } int32_t pos; int32_t totlines; float percent; bool truncated; if(m_chart->get_position(&pos, &totlines, &percent, &truncated)) { char prstr[128]; string trs; uint32_t csize = 18; attrset(m_colors[sinsp_cursesui::PROCESS_MEGABYTES]); move(m_screenh - 1, m_screenw - csize); for(uint32_t k = 0; k < csize; k++) { addch(' '); } if(truncated) { trs = "(truncated)"; } if(percent != 0) { sprintf(prstr, "%d/%d(%.1f%%)%s", (int)pos, (int)totlines, percent * 100, trs.c_str()); } else { sprintf(prstr, "%d/%d(0.0%%)%s", (int)pos, (int)totlines, trs.c_str()); } mvaddstr(m_screenh - 1, m_screenw - strlen(prstr), prstr); } }
void read_file(FILE *fp) { int c,x,y; fseek(fp,0,SEEK_SET); while((c=getc(fp))!=EOF) { if(c!='\n') //dont know why I added the check for new line character { addch(c); } else { getyx(stdscr,y,x); move(y+1,0); } } refresh(); }
void snakeclass::putfood() { while (1) { int tmpx = rand() % Map.width+1; int tmpy = rand() % Map.height+1; for (unsigned int i = 0; i < snake.size(); i++) { if (snake[i].x == tmpx && snake[i].y == tmpy) continue; } if (tmpx >= Map.width-2 || tmpy >= Map.height-3) continue; food.x = tmpx; food.y = tmpy; break; } Map.map[food.x][food.y] = foo; move(food.y, food.x); addch(foo); refresh(); }
/* * Flag the current-file in the display (i.e., when leaving the current * line for the work-area). */ void markC(RING * gbl, int on) { int col = gbl->cmdcol[CCOL_CMD] - gbl->Xbase; if (col >= 0) { int y, x; (void) move2row(gbl->curfile, col); if (!on || (gbl->mrkfile < 0)) { gbl->mrkfile = on ? (int) gbl->curfile : -1; getyx(stdscr, y, x); addch((chtype) (on ? '*' : ' ')); (void) move(y, x); } } }
static void placeship(int b, ship_t *ss, int vis) { int l; for(l = 0; l < ss->length; ++l) { int newx = ss->x + l * xincr[ss->dir]; int newy = ss->y + l * yincr[ss->dir]; board[b][newx][newy] = ss->symbol; if (vis) { pgoto(newy, newx); (void) addch((chtype)ss->symbol); } } ss->hits = 0; }
void afiseazaGranita(void) { int i, j, muta; attrset(COLOR_PAIR(COL_GRANITA)); for (i=0; i<HLIN; i++) { muta = 1; for (j=0; j<HCOL; j++) if (liniiHarta[i][j] == '#') { if (muta) move(i+START_LIN, j+START_COL); addch(' '); muta = 0; } else muta = 1; } CAPAT(); refresh(); }
/* initializes curses routines */ void init_curses() { int i, y, x; (void) ioctl(0, TCGETA, (char *)&save_termio); if (initscr() == NULL) { (void) printf("Error allocating screen in curses package.\n"); exit(1); } if (LINES < 24 || COLS < 80) /* Check we have enough screen. -CJS- */ { (void) printf("Screen too small for moria.\n"); exit (1); } #ifdef SIGTSTP (void) signal (SIGTSTP, suspend); #endif if ((savescr = newwin (0, 0, 0, 0)) == NULL) { (void) printf ("Out of memory in starting up curses.\n"); exit_game(); } (void) clear(); (void) refresh(); moriaterm (); /* check tab settings, exit with error if they are not 8 spaces apart */ (void) move(0, 0); for (i = 1; i < 10; i++) { (void) addch('\t'); getyx(stdscr, y, x); if (y != 0 || x != i*8) break; } if (i != 10) { msg_print("Tabs must be set 8 spaces apart."); exit_game(); } }
/** * Renders the interior of horizontal bar namely the rrrrrrrqqqqhhh #% part from * data set in updateInputData() method. * where the rrrrqqqhhh is obtained by adding running,queued,held jobs into a total * the rrrqqqhhh is then rendered based on a percentage of each of these values divided * by the total. The #% is the percentLoad value. If this value is negative NA is * printed, if this value is greater then 999 only 999 is printed. */ void HorizontalJobBar::update(){ //lets get the total value std::string rqhstr; mp_pColors->setColorPair(CursesColors::GREENBLACK); int availableWidth = mp_Width-(mp_LeftBracket.length()+mp_RightBracket.length()+7); //blank out data rqhstr = std::string(availableWidth+4,' '); mvaddstr(mp_StartY,mp_StartX+mp_LeftBracket.length(),rqhstr.c_str()); //lets convert the mp_PercentLoad into number of characters to render by //taking availableWidth x (mp_PercentLoad x 0.1) values to a max value of //availableWidth //The color of the bar will be blue if load is below 50% //yellow will be the color at 50-75% //red will be the color above 75% int barWidth = (int)round((float)availableWidth * ((float)mp_PercentLoad*0.01)); if (barWidth > availableWidth){ barWidth = availableWidth; } if (mp_PercentLoad >= 50 && mp_PercentLoad < 75){ mp_pColors->setColorPair(CursesColors::YELLOWBLACK); } if (mp_PercentLoad >= 75){ mp_pColors->setColorPair(CursesColors::REDBLACK); } if (barWidth > 0){ move(mp_StartY,mp_StartX+mp_LeftBracket.length()); for (int i = 0; i < barWidth;i++){ addch(ACS_BLOCK); } } char buff[4]; snprintf(buff,4,"%d",mp_PercentLoad); std::string loadstr = (buff); loadstr = std::string(4-loadstr.length(),' ')+loadstr; mvaddstr(mp_StartY,mp_StartX+mp_LeftBracket.length()+availableWidth+1,loadstr.c_str()); mp_pColors->unsetColorPair(CursesColors::CYANBLACK); mp_pColors->unsetColorPair(CursesColors::YELLOWBLACK); mp_pColors->unsetColorPair(CursesColors::REDBLACK); }
static void writeText (const wchar_t *buffer, int columns) { int column; for (column=0; column<columns; column++) { wchar_t c = buffer[column]; #ifdef HAVE_ICONV_H char *pc = (char*) &c; size_t sc = sizeof(wchar_t); char d[MB_MAX_LEN+1]; char *pd = d; size_t sd = MB_MAX_LEN; if (iconv(conversionDescriptor, &pc, &sc, &pd, &sd) >= 0) { *pd = 0; addstr(d); } else #endif /* HAVE_ICONV_H */ addch(c); } }
void global_help(char *args) { int col, len; struct mode *p; char *name, *prev; move(CMDLINE, col = 0); name = prev = NULL; for (p = modes; p->c_name; p++) { if ((name = shortname(args, p->c_name)) == NULL) continue; if (name && prev && strcmp(name, prev) == 0) { free(name); name = NULL; continue; } len = strlen(name); if (col + len > COLS) break; addstr(name); col += len + 1; if (col + 1 < COLS) addch(' '); if (prev) free(prev); prev = name; name = NULL; } if (col == 0 && args) { standout(); if ((int)strlen(args) < COLS - 25) printw("help: no matches for `%s.*'", args); else printw("help: no matches"); standend(); } clrtoeol(); if (name) free(name); if (prev) free(prev); }
// do the business with curses void render_line (int linenum, const char *legend, double barpercent, int bar_colour, int bg_colour, const char *shownrate) { int startpos, graphcols, graphlimit; int barchar; int i; // are we below what is visible or above? // first return if not this many lines on the screen if(linenum < start_row || linenum > (start_row+(screen_max_rows-1))) { mvprintw(linenum, 0, "linenum=%d, < start_row = %d name=%s percent %f %s\n", linenum, start_row,legend, barpercent, shownrate); return; } linenum -= start_row; // displaying this section on screen startpos = 0; graphcols = screen_max_cols - startpos; graphlimit = int(graphcols * (barpercent/100)); // hack for mono terminals - translate bar colour if(bar_colour == COLOR_GREEN) barchar = ACS_HLINE; if(bar_colour == COLOR_YELLOW) barchar = ACS_BOARD; if(bar_colour == COLOR_RED) barchar = ACS_BLOCK; mvprintw(linenum,0,"%s", legend); clrtoeol(); if(!has_colors()) { // need the line of whatever character is appropriate for(i = 0; i < graphlimit;i++) addch(barchar); } // now the rate - put on top of the bar in the case of the no color version mvprintw(linenum, 35, "%d", graphlimit); mvprintw(linenum, 40 + ((screen_max_cols-startpos)/2-strlen((const char *)shownrate)),(const char *)shownrate); if(has_colors()) { // whole line background mvchgat(linenum,0,screen_max_cols,A_NORMAL,bg_colour,NULL); // show the graph part as a colour if possible mvchgat(linenum,startpos,graphlimit, A_NORMAL,bar_colour, NULL ); } }
void lprintf(int dtype, char *fmt, ...) { va_list args; char str[1024]; char *p; chtype ch; va_start(args, fmt); vsnprintf(str, 1024, fmt, args); va_end(args); if (color) { for (p = str; *p != '\0'; p++) { ch = *p; if (sevenbit && ch > 127) ch = '.'; if ((ch > 127 && ch < 160) && ibmhack) ch = ibm_map[ch - 128] | A_BOLD; else if ((ch < 32) && (ch != '\n')) ch = (ch + 64) | A_REVERSE; if ((dtype == T_ADDR) || (dtype == T_PROTOCOL) || (dtype == T_AXHDR) || (dtype == T_IPHDR) || (dtype == T_ROSEHDR) || (dtype == T_PORT) || (dtype == T_TIMESTAMP)) ch |= A_BOLD; ch |= COLOR_PAIR(dtype); addch(ch); } } else { for (p = str; *p != '\0'; p++) if ((*p < 32 && *p != '\n') || (*p > 126 && *p < 160 && sevenbit)) *p = '.'; fputs(str, stdout); fflush(stdout); } }
static void draw_activity(gchar *title, gboolean act, gboolean det) { WINDOW_REC *window; GList *tmp; gchar str[MAX_INT_STRLEN]; gboolean first, is_det; set_color((1 << 4)+7); addstr(title); first = TRUE; for (tmp = activity_list; tmp != NULL; tmp = tmp->next) { window = tmp->data; is_det = window->new_data == NEWDATA_MSG_FORYOU; if (is_det && !det) continue; if (!is_det && !act) continue; if (first) first = FALSE; else { set_color((1 << 4)+3); addch(','); } ltoa(str, window->refnum); switch (window->new_data) { case NEWDATA_TEXT: set_color((1 << 4)+3); break; case NEWDATA_MSG: set_color((1 << 4)+15); break; case NEWDATA_MSG_FORYOU: set_color((1 << 4)+13); break; } addstr(str); } }
void write_file(FILE *fp, bool overtype_mode,int c, int curr, int end) { long y,x; char * buffer=NULL; if(overtype_mode) // Insert mode where you overwrite a character in existing location { buffer = (char*) malloc(sizeof(char) * (end+1-curr)); if(buffer !=NULL) { fseek(fp,curr, SEEK_SET);//fseek to position if(end-curr-1>0) { fread(buffer, sizeof(char) , end-curr-1, fp);//fread (end - curr) into buffer fputc(c, fp);//write the character and it is a char pointer fputs(buffer, fp);//fwrite the buffer /* Update the map according to the file offset */ free(buffer); buffer=NULL; erase(); read_file(fp); getbegyx(stdscr,y,x); move(y,x-end+curr); refresh(); } /* For potential bug when the curser is at the end of the file buffer allocation fails*/ else { free(buffer); buffer=NULL; } } } else { getyx(stdscr,y,x); addch(c); refresh(); fputc(mvinch(y,x) & A_CHARTEXT,fp); move(y,x+1); fseek(fp,0,SEEK_CUR); } }
int main(void) { int r,x,row,col; initscr(); srandom((unsigned)time(NULL)); r = random(); r %= 300; for(x=0;x<r;x++) addch('*'); getyx(stdscr,row,col); printw("\nThe cursor ended up at location %d, %d.\n",\ row,col); refresh(); getch(); endwin(); return 0; }
main() { int i, j, c; size_t len; char id[100]; FILE *fp; char *s; initscr(); /* Always call initscr() first */ signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */ crmode(); /* We want cbreak mode */ noecho(); /* We want to have control of chars */ delwin(stdscr); /* Create our own stdscr */ stdscr = newwin(YSIZE, XSIZE, 10, 35); flushok(stdscr, TRUE); /* Enable flushing of stdout */ scrollok(stdscr, TRUE); /* Enable scrolling */ erase(); /* Initially, clear the screen */ standout(); move(0,0); while (1) { c = getchar(); switch(c) { case 'q': /* Quit on 'q' */ quit(); break; case 's': /* Go into standout mode on 's' */ standout(); break; case 'e': /* Exit standout mode on 'e' */ standend(); break; case 'r': /* Force a refresh on 'r' */ wrefresh(curscr); break; default: /* By default output the character */ addch(c); refresh(); } } }
display() { int i, j, p, row; char c; static int indx; while (page > x) up(); i = j = 0; for (p = page; ; p++) { if (x == p) { row = i; col = j; } if ((p >= x && i >= LINES-1) || p == ebuf + gap - egap) break; c = buf[p < gap ? p : p + egap - gap]; if (c != '\r' && c != '\n') { j += (c == '\t') ? 8-(j&7) : 1; // XXX tab issues } if (c == '\n') { i++; j = 0; } } while (i < LINES-1 && page) { i++; row++; up(); } while (row >= LINES) { row--; down(); } if (col < ind) ind = 0; while (col - ind >= COLS) ind += 8; if (pagex != page || indx != ind) { pagex = page; indx = ind; clear(); mvprintw(i=0,j=0,"[%04d] ", line); for (p = page; ; p++) { if (i == LINES || p == ebuf + gap - egap) break; c = buf[p < gap ? p : p + egap - gap]; if (c != '\r' && c != '\n' && j < ind + COLS) { if (j >= ind) addch(c); j += (c == '\t') ? 8-(j&7) : 1; // XXX insert spaces cause of word wrap issues } if (c == '\n') { if (++i < LINES) mvprintw(i, j=0, "[%04d] ", line + i); } } } move(row, col - ind + 7); refresh(); }
static void brsh_init(void) { /* handle window resize */ signal(SIGWINCH, &resized_); /* initalize curses */ initscr(); cbreak(); noecho(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); /* enable cursor keys and others */ /* create the output window */ win_output = newwin(LINES - g_brsh_input_display_lines - 1, COLS, 0, 0); scrollok(win_output, TRUE); /* create the input field */ fld_input = new_field(g_brsh_input_display_lines, COLS, LINES - g_brsh_input_display_lines, 0, g_brsh_input_maximum_lines - g_brsh_input_display_lines, 1); static FIELD *fields[2] = { NULL, NULL }; /* not sure if it needs this to hang around or not, so we'll make it static anyway */ fields[0] = fld_input; frm_input = new_form(fields); post_form(frm_input); /* draw a line */ move(LINES - g_brsh_input_display_lines - 1, 0); for (int i = 0; i < COLS; i++) addch(ACS_HLINE); if (g_brsh_show_instructions) mvprintw(LINES - g_brsh_input_display_lines - 1, COLS - 15, " F1 = Help "); refresh(); move(LINES - g_brsh_input_display_lines, 0); /* post welcome banner */ brsh_print(BRSH_NAME " " BRSH_VERSION "\n"); }
static void initwin(void){ int t_line, t_col, i, j; char ses[] = "-[ Seasion ]-"; initscr(); nocbreak(); refresh(); start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); getmaxyx(stdscr, t_line, t_col); printw("+%s",ses); for(i = 0; i < (t_col - strlen(ses)) - 2; i++){ addch('-'); } addch('+'); for(i = 0; i < (t_line - MINPUT) - 1; i++){ addch('|'); for (j = 0; j < t_col - 2; j++) addch(' '); printw("|"); } addch('+'); for(i = 0; i < (t_col - strlen(ses)) - 2; i++){ addch('-'); } printw("%s+", ses); attron(COLOR_PAIR(1)); printw("[ UDP Local Chat ] - Remote 192.168.0.10, Duration MM:SS"); use_default_colors(); printw("\n>"); wrefresh(stdscr); winses = newwin(t_line - (MINPUT + 2), t_col - 4, 0, 0); mvwin(winses, 2, 2); scrollok(winses, TRUE); wrefresh(winses); refresh(); winmsg = newwin(1, t_col-3, 0, 0); mvwin(winmsg, t_line - 1, 2); scrollok(winmsg, TRUE); wrefresh(winmsg); }