void draw_car(char yes) { // obtain the lock so no other thread can interrupt us pend(draw_lock); // reset the colors reset_color(); // if we are drawing a car make it cyan if (yes) set_color_bold(BG_CYAN); // draw car 0 goto_line(street_loc[1]+car_loc[0][1]-1, street_loc[1]+car_loc[0][0]-1); printf(" "); // draw car 1 goto_line(street_loc[1]+car_loc[1][1]-1, street_loc[1]+car_loc[1][0]-1); printf(" "); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void runTest(test_fn_t test, const char* const test_name) { fprintf(stderr, "\n" _BLUE "[Start Test] %s\n", test_name); reset_color(); test_setup(); test(); test_takedown(); fprintf(stderr, _BLUE "[End Test] %s\n", test_name); reset_color(); }
int get_str_input(char *say_what, char *save_where, int input_size) { printf("%s%s", COLOR_GREEN, say_what); reset_color(); if (fgets(save_where, input_size, stdin) == NULL) { return 1; } strtok(save_where, "\n"); if (strlen(save_where) == input_size - 1) { dump_line(stdin); return 1; } if (!strcmp(save_where, "0")) { return 2; } return 0; }
static void do_new_kmess(void) { /* Kernel wants to print a new message */ struct kmessages *kmess_ptr; /* kmessages structure */ char kernel_buf_copy[_KMESS_BUF_SIZE]; static int prev_next = 0; int next, bytes, copy, restore = 0; tty_t *tp, rtp; assert(_minix_kerninfo); kmess_ptr = _minix_kerninfo->kmessages; /* The kernel buffer is circular; print only the new part. Determine * how many new bytes there are with the help of current and * previous 'next' index. This works fine if less than _KMESS_BUF_SIZE * bytes is new data; else we miss % _KMESS_BUF_SIZE here. Obtain * 'next' only once, since we are operating on shared memory here. * Check for size being positive; the buffer might as well be emptied! */ next = kmess_ptr->km_next; bytes = ((next + _KMESS_BUF_SIZE) - prev_next) % _KMESS_BUF_SIZE; if (bytes > 0) { /* Copy from current position toward end of buffer */ copy = MIN(_KMESS_BUF_SIZE - prev_next, bytes); memcpy(kernel_buf_copy, &kmess_ptr->km_buf[prev_next], copy); /* Copy remainder from start of buffer */ if (copy < bytes) { memcpy(&kernel_buf_copy[copy], &kmess_ptr->km_buf[0], bytes - copy); } tp = line2tty(consoleline); if (tp == NULL) panic("Don't know where to send kernel messages"); if (tp->tty_outleft > 0) { /* Terminal is already printing */ rtp = *tp; /* Make backup */ tp->tty_outleft = 0; /* So do_write is happy */ restore = 1; } if (kernel_msg_color != 0) set_color(tp, kernel_msg_color); do_write(tp->tty_minor, 0, KERNEL, (cp_grant_id_t) kernel_buf_copy, bytes, CDEV_NONBLOCK, 0); if (kernel_msg_color != 0) reset_color(tp); if (restore) { *tp = rtp; } } /* Store 'next' pointer so that we can determine what part of the * kernel messages buffer to print next time a notification arrives. */ prev_next = next; }
void draw_frame(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); clear_screen(); goto_line(0,0); set_color_bold(FG_BLACK); set_color_bold(BG_WHITE); int x, y; for (y = 0; y < FRAME_HEIGHT; y++) { for (x = 0; x < FRAME_WIDTH; x++) { switch (frame[y][x]) { case '-': printf("\u2500"); break; case '|': printf("\u2502"); break; case ' ': printf(" "); break; default: printf("%s", pipes[frame[y][x]-'0']); } } printf("\n"); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
static void colored_fputs(int level, const char *str){ if(use_color<0){ #if defined(_WIN32) && !defined(__MINGW32CE__) CONSOLE_SCREEN_BUFFER_INFO con_info; con = GetStdHandle(STD_ERROR_HANDLE); use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); if (use_color) { GetConsoleScreenBufferInfo(con, &con_info); attr_orig = con_info.wAttributes; background = attr_orig & 0xF0; } #elif HAVE_ISATTY use_color= !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR") && (getenv("TERM") && isatty(2) || getenv("FFMPEG_FORCE_COLOR")); #else use_color= getenv("FFMPEG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); #endif } if(use_color){ set_color(level); } fputs(str, stderr); if(use_color){ reset_color(); } }
void draw_keymap(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); // figure out which x y to draw it at int x = keymap_loc[1]; int y = keymap_loc[0]; // draw the keymapping set_color(FG_BLACK); set_color_bold(BG_WHITE); goto_line(x, y+0); printf("[c] - Car in turn lane"); goto_line(x, y+1); printf("[w] - Press walk button"); goto_line(x, y+2); printf("[b] - Toggle broken"); goto_line(x, y+3); printf("[e] - Emergency for %d seconds", emergency_duration); goto_line(x, y+4); printf(" [-/+] - Inc/Dec"); goto_line(x, y+5); printf("[m] - Toggle manual"); goto_line(x, y+6); printf(" [j/k] - Next/Prev light"); goto_line(x, y+7); printf(" [1/2/3] - Red/Yellow/Green"); goto_line(x, y+8); printf("[r] - Redraw"); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
static void colored_fputs(int level, const char *str) { if (use_color < 0) { #if HAVE_SETCONSOLETEXTATTRIBUTE CONSOLE_SCREEN_BUFFER_INFO con_info; con = GetStdHandle(STD_ERROR_HANDLE); use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR"); if (use_color) { GetConsoleScreenBufferInfo(con, &con_info); attr_orig = con_info.wAttributes; background = attr_orig & 0xF0; } #elif HAVE_ISATTY use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR")); if (getenv("AV_LOG_FORCE_256COLOR")) use_color *= 256; #else use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR"); #endif } if (use_color == 1) { set_color(level); } else if (use_color == 256) set_256color(level); fputs(str, stderr); if (use_color) { reset_color(); } }
static void _hda_log(int level, const char *fmt, va_list ap) { va_list ap2; int i; if (level > log_level) return; if (logfp == stdout) set_color(level); print_prefix(level); va_copy(ap2, ap); vfprintf(logfp, fmt, ap); if (!(log_flags & HDA_LOG_FLAG_NO_ECHO) && logfp != stdout) vprintf(fmt, ap2); va_end(ap2); if (logfp == stdout) reset_color(); if (((i = strlen(fmt)) > 0) && (fmt[i-1] == '\n')) log_previous_prefix = -1; if ((level == HDA_LOG_ERR || level == HDA_LOG_WARN) && hda_log_trap_on_error) raise(SIGTRAP); }
/* * Display percentage * @perct: percentage */ static void text_disp_perct(double perct) { change_color(perct); (void)printf("%*.1f", max.perctused, perct); reset_color(); (void)printf("%%"); }
void display_map(const struct map *map) { int i, j, z; printf("\n "); for(i = 0; i < map->columns; ++i) printf(" %2d ", i); printf("\n +"); for(i = 0; i < map->columns; ++i) printf("---+"); putchar('\n'); for(i = 0; i < map->rows; ++i) { printf("%2d |", i); for(j = 0; j < map->columns; ++j) { #if defined WIN if(!map->Map[i][j].flagged && !map->Map[i][j].visible) { color(FOREGROUND_INTENSITY|FOREGROUND_GREEN|BACKGROUND_BLUE); printf(" ? "); reset_color(); putchar('|'); } else { color(colors_tab[map->Map[i][j].value - '1']); printf(" %c ", map->Map[i][j].value); reset_color(); putchar('|'); } #else if(map->Map[i][j].value == MINE) printf(" ? |"); else printf(" %c |", map->Map[i][j].value); #endif /*}*/ } putchar('\n'); printf(" +"); for(z = 0; z < map->columns; ++z) printf("---+"); putchar('\n'); } printf("\n\n"); }
static void core_assert(int expr, const char * error_msg) { assert_active_test(); if(test_status == 0) { if(expr == 0) { color(SH_FG_RED); printf("Test %s: FAIL. Expected %s\n", current_test, error_msg); test_status=1; reset_color(); } } }
int ask_date(xtime *save_where) { time_t current_time = time(NULL); xtime current_xtime; char current_time_str[MAX_TIME_CHARS]; char actual_time[MAX_TIME_CHARS]; char permited_chars[MAX_TIME_CHARS] = "0123456789/: "; char *c; int i; time_t_to_xtime(¤t_xtime, ¤t_time); time_to_str(¤t_xtime, current_time_str); printf("São agora %s\n", current_time_str); printf("%sInsira a data que prentende, no formato DD/MM/AAAA HH:MM: ", COLOR_GREEN); reset_color(); if (fgets(actual_time, MAX_TIME_CHARS, stdin) == NULL) { return 1; } strtok(actual_time, "\n"); if (!strcmp(actual_time, "0")) { return 2; } if (strlen(actual_time) == MAX_TIME_CHARS - 1) { dump_line(stdin); return 1; } for (i = 0; actual_time[i] != '\0'; i++) { c = strchr(permited_chars, actual_time[i]); if (c == NULL) { return 1; } } sscanf(actual_time, "%d/%d/%d %d:%d", &save_where->day, &save_where->month, &save_where->year, &save_where->hour, &save_where->minute); return 0; }
void menu_show() { int option; for (option = 1; option < N_OPTIONS + 1; option++) { printf("%s%d: %s.\n", COLOR_YELLOW, option, options[option - 1]); } reset_color(); }
int vprinterr(const char * format, va_list vl) { if(state == con_lineedit) { disable_raw(); color(Console::COLOR_LIGHTRED); fprintf(dfout_C,"\x1b[1G"); fprintf(dfout_C,"\x1b[0K"); int ret = vfprintf( dfout_C, format, vl ); reset_color(); enable_raw(); prompt_refresh(); return ret; } else { color(Console::COLOR_LIGHTRED); int ret = vfprintf( dfout_C, format, vl ); reset_color(); return ret; } }
void desenha_tela(int matriz[][col]){ printf("\nRespostas\t\tCerto = 8 / Lugar errado = 7\n"); for(int i=0; i<row; i++){ printf("\n |"); for(int j=0; j<col; j++){ if(j == 4) printf(" |"); set_color(matriz[i][j]); printf(" %2d |", matriz[i][j]); reset_color(); } } printf("\n"); }
void display_map_debug(const struct map *map) { int i, j, z; putchar('+'); for(i = 0; i < map->columns; ++i) printf("---+"); putchar('\n'); for(i = 0; i < map->rows; ++i) { putchar('|'); for(j = 0; j < map->columns; ++j) { #if defined WIN if(map->Map[i][j].value == MINE) { color(BACKGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY); printf(" X "); reset_color(); putchar('|'); } else { color(colors_tab[map->Map[i][j].value - '1']); printf(" %c ", map->Map[i][j].value); reset_color(); putchar('|'); } #else if(map->Map[i][j].value == MINE) printf(" X |"); else printf(" %c |", map->Map[i][j].value); #endif } putchar('\n'); putchar('+'); for(z = 0; z < map->columns; ++z) printf("---+"); putchar('\n'); } purge_buffer(); printf("\n"); }
void draw_lights(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); char light_arrows[6][6] = { "\u2193", // down "\u2191", // up "\u2192", // right "\u2191", // up "\u2193", // down "\u2190" // left }; int i = 0; for (i = 0; i < 6; i++) { // goto light x,y goto_line(street_loc[1]+light_loc[i][1]-1, street_loc[0]+light_loc[i][0]-1); if (manual_mode && i == selected_light) set_color_bold(BG_BLUE); // set it to proper color set_light_color(lights[i]); // draw the arrow for this light printf(light_arrows[i]); reset_color(); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
/* * Display used, available and total correctly formatted * @n: number to print * @perct: percentage (useful for finding which color to use) * @req_width: required width (used for terminal display, otherwise can be 0) */ static void text_disp_uat(double n, double perct, int req_width) { int i; i = 0; if (unitflag == 'h') i = humanize(&n); change_color(perct); (void)printf("%*.1f", req_width - 1, n); /* -1 for the unit symbol */ reset_color(); print_unit(i, 1); }
void tela(int status){ switch(status){ case 0: set_color(4); boas_vindas(); reset_color(); break; case 1: set_color(6); voce_ganhou(); reset_color(); break; case 2: set_color(1); voce_perdeu(); reset_color(); break; case 3: set_color(2); boa_viajem(); reset_color(); break; } }
int end_test_suite() { assert_active_test_suite(); active_test_suite = 0; const char * status; printf("============= END TEST SUITE ===============\n"); if(success_tests == total_tests) { status = "succeeded"; color(SH_FG_GREEN); } else { status = "failed"; color(SH_FG_RED); } printf("Test suite %s. Succesive tests: %d/%d\n", status, success_tests, total_tests); reset_color(); return !(success_tests == total_tests); }
/* * Display header */ static void text_disp_header(void) { int gap; /* use color option if triggered */ if (cflag) (void)printf("\033[;%dm", cnf.chead); (void)printf("%-*s", max.fsname, _("FILESYSTEM")); if (Tflag) (void)printf("%-*s", max.fstype, _("TYPE")); if (!bflag) { (void)printf("%s", _("(=) USED")); gap = max.bar - (int)strlen(_("(=) USED")) - (int)strlen(_("FREE (-)")); (void)printf("%*s", gap, ""); (void)printf("%s", _("FREE (-)")); } (void)printf("%*s", max.perctused + 1, _("%USED")); if (dflag) (void)printf("%*s", max.used, _("USED")); (void)printf("%*s", max.avail, _("AVAILABLE")); (void)printf("%*s", max.total, _("TOTAL")); if (iflag) { (void)printf("%*s", max.nbinodes, _("#INODES")); (void)printf("%*s", max.avinodes, _("AV.INODES")); } /* precedded by a space because previous colum is right aligned */ if (!Mflag) (void)printf(" %-*s", max.mntdir, _("MOUNTED ON")); if (oflag) (void)printf("%-*s", max.mntopts, _("MOUNT OPTIONS")); (void)printf("\n"); reset_color(); }
/* * Display the nice usage bar * @perct: percentage value */ static void text_disp_bar(double perct) { int i, j; int barinc = 5; /* option to display a wider bar */ if (wflag) { barinc = 2; } /* used (*) */ (void)printf("["); if (!cflag) { for (i = 0; i < perct; i += barinc) (void)printf("%c", cnf.gsymbol); for (j = i; j < 100; j += barinc) (void)printf("-"); } else { /* color */ /* green */ (void)printf("\033[;%dm", cnf.clow); for (i = 0; (i < cnf.gmedium) && (i < perct); i += barinc) (void)printf("%c", cnf.gsymbol); /* yellow */ (void)printf("\033[;%dm", cnf.cmedium); for (; (i < cnf.ghigh) && (i < perct); i += barinc) (void)printf("%c", cnf.gsymbol); /* red */ (void)printf("\033[;%dm", cnf.chigh); for (; (i < 100) && (i < perct); i += barinc) (void)printf("%c", cnf.gsymbol); reset_color(); for (j = i; j < 100; j += barinc) (void)printf("-"); } (void)printf("]"); }
void draw_street(void) { // obtain the lock so no other thread can interrupt us pend(draw_lock); set_color_bold(FG_WHITE); int x, y; for (y = 0; y < HEIGHT; y++) { goto_line(street_loc[1], street_loc[0]+y); for (x = 0; x < WIDTH; x++) { switch (diagram[y][x]) { // http://www.utf8-chartable.de/unicode-utf8-table.pl // lane markers case '=': set_color_dim(FG_YELLOW); printf("\u2550"); break; case ',': set_color_dim(FG_YELLOW); printf("\u2551"); break; case '-': set_color_bold(FG_WHITE); printf("\u2500"); break; case '|': set_color_bold(FG_WHITE); printf("\u2502"); break; case 'v': set_color_bold(FG_WHITE); printf("\u2518"); break; case 'r': set_color_bold(FG_WHITE); printf("\u250C"); break; case 'n': set_color_bold(FG_WHITE); printf("\u2510"); break; case 'l': set_color_bold(FG_WHITE); printf("\u2514"); break; // cross walks case 'h': printf(" "); break; case 'c': printf("C"); break; default: printf("%c", diagram[y][x]); } } } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void _log(int lineloglevel,const char* file,const char* function, int line,const char* fmt, va_list ap ){ // if the logger level fits if (lineloglevel >= 0 && lineloglevel <= 3 && lineloglevel >= log_level){ // get just the filename. this line found on a forum on line. // claims to be from google. file = ((strrchr(file, '/') ? : file- 1) + 1); char str[1024]; // write the actual header int byteswritten = snprintf(str,1024, "%s%s(%s:%d): ", messages[lineloglevel],file,function,line); // write the actual logger byteswritten += vsnprintf(str + byteswritten,1024 - byteswritten,fmt,ap); str[byteswritten] = '\n'; str[byteswritten+1] = 0; // write the output if (fout.good()) { pthread_mutex_lock(&mut); fout << str;; pthread_mutex_unlock(&mut); } if (log_to_console) { #ifdef COLOROUTPUT if (lineloglevel == LOG_FATAL) { textcolor(stderr, BRIGHT, RED); } else if (lineloglevel == LOG_ERROR) { textcolor(stderr, BRIGHT, RED); } else if (lineloglevel == LOG_WARNING) { textcolor(stderr, BRIGHT, GREEN); } #endif std::cerr << str;; #ifdef COLOROUTPUT reset_color(stderr); #endif } }
void swap_b(t_push **lista, t_push **listb, t_action **action) { t_push *tmp; int swap; if (checklen(*listb) > 1) { tmp = *listb; while (tmp->next) tmp = tmp->next; swap = tmp->nb; tmp->nb = tmp->prev->nb; tmp->prev->nb = swap; tmp->color = ON; tmp->prev->color = ON; add_action(action, cpy_list((*lista)), cpy_list((*listb)), "sb"); reset_color(listb); } }
/* * Display the sum (useful when -s option is used * @stot: total size of "total" * @atot: total size of "available" * @utot: total size of "used" * @ifitot: total number of inodes * @ifatot: total number of available inodes */ static void text_disp_sum(double stot, double atot, double utot, double ifitot, double ifatot) { double ptot = 0; int width; width = Tflag ? max.fsname + max.fstype : max.fsname; if ((int)stot == 0) ptot = 100.0; else ptot = (utot / stot) * 100.0; /* use color option if triggered */ if (cflag) (void)printf("\033[;%dm", cnf.chead); (void)printf("%-*s", width, _("SUM:")); reset_color(); if (!bflag) text_disp_bar(ptot); text_disp_perct(ptot); if (uflag) { stot = cvrt(stot); atot = cvrt(atot); if (dflag) utot = cvrt(utot); } if (dflag) text_disp_uat(utot, ptot, max.used); text_disp_uat(atot, ptot, max.avail); text_disp_uat(stot, ptot, max.total); if (iflag) text_disp_inodes((uint64_t)ifitot, (uint64_t)ifatot); (void)printf("\n"); }
int end_test() { if(test_status == -1) { return 0; } else { ++context_tests; ++total_tests; if(test_status == 0) { //Previous test succeeded ++context_success; ++success_tests; test_status = -1; //Inactivate color(SH_FG_GREEN); printf("Test %s: OK\n", current_test); reset_color(); return 0; } else { test_status = -1; return 1; } } }
void draw_walk(int state) { // obtain the lock so no other thread can interrupt us pend(draw_lock); int i; for (i = 0; i < 4; i++) { goto_line(street_loc[1] + walk_loc[i][1] - 1, street_loc[0] + walk_loc[i][0] - 1); set_light_color(state); printf("C"); } reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }
void draw_status(int y, const char *msg) { // obtain the lock so no other thread can interrupt us pend(draw_lock); set_color(FG_BLACK); set_color_bold(BG_WHITE); goto_line(status_loc[1], status_loc[0]+y); printf(" "); goto_line(status_loc[1], status_loc[0]+y); printf(msg); reset_color(); hide_cursor(); // we're done, release the lock post(draw_lock); }