Example #1
0
//Инициальзирует только графику
void win_rerun()
{
	//Инициализация ncurses
	initscr();						//ncurses mode
	refresh();	
	noecho();						//Отключить вывод клвиш
	curs_set(0);					//Прячем курсор
	keypad(stdscr, TRUE);			//Включаем обработку спец клавиш
	signal (SIGWINCH, win_resize);	//Вызов функции при ресайзе окна

	//Создаем окна
	win[WIN_BL] = newwin((LINES - 2), floor(COLS / 2), 0, 0);
	win[WIN_BR] = newwin((LINES - 2), COLS - floor(COLS / 2), 0, floor(COLS / 2));
	win[WIN_L] = newwin((LINES - 5), floor(COLS / 2 - 2), 2, 1);
	win[WIN_R] = newwin((LINES - 5), COLS - floor(COLS / 2) - 2, 2, floor(COLS / 2) + 1);
	win[WIN_PB] = newwin(2, COLS, LINES - 2, 0);

	//Цвета
	start_color();
	assume_default_colors(COLOR_WHITE,COLOR_BLUE);	//Цвета по умолчанию
	//Цветовые пары
	init_pair(1, COLOR_BLACK, COLOR_CYAN);			//Выбранная директори
	init_pair(2, COLOR_CYAN, COLOR_WHITE);			//Нижняя панель
	init_pair(3, COLOR_YELLOW, COLOR_BLUE);			//Заколовок таблицы
	
	winref_all();
}
Example #2
0
File: line.c Project: JakeSc/tig
void
init_colors(void)
{
	struct line_rule query = { "default", STRING_SIZE("default") };
	struct line_rule *rule = find_line_rule(&query);
	int default_bg = rule->info.bg;
	int default_fg = rule->info.fg;
	enum line_type type;

	start_color();

	if (assume_default_colors(default_fg, default_bg) == ERR) {
		default_bg = COLOR_BLACK;
		default_fg = COLOR_WHITE;
	}

	for (type = 0; type < line_rules; type++) {
		struct line_rule *rule = &line_rule[type];
		struct line_info *info;

		for (info = &rule->info; info; info = info->next) {
			init_line_info_color_pair(info, type, default_bg, default_fg);
		}
	}
}
Example #3
0
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int use_default_colors( void )
{
    __QCS_FCONTEXT( "use_default_colors" );

    default_colors = TRUE;
    first_col = -1;

    return assume_default_colors( -1, -1 );
}
Example #4
0
File: color.c Project: ryoon/eCos
int use_default_colors(void)
{
    PDC_LOG(("use_default_colors() - called\n"));

    default_colors = TRUE;
    first_col = -1;

    return assume_default_colors(-1, -1);
}
Example #5
0
/*Creates a new window*/
WINDOW *Create_NewWindow(int height, int width, int starty, int startx){
	WINDOW *local_win;
	
	local_win = newwin(height, width, starty, startx);
	
	assume_default_colors(COLOR_WHITE, COLOR_BLACK);
	
	
	return local_win;
}
Example #6
0
void Screen::setupScreen()
{
    initscr();

    start_color();
    assume_default_colors(COLOR_WHITE, COLOR_BLACK);
    init_pair(1, COLOR_YELLOW, COLOR_BLACK);
    init_pair(2, COLOR_RED, COLOR_BLACK);
    attrset(A_BOLD);
    curs_set(0);
}
int main(void)
{

	initscr();
	start_color();

	assume_default_colors(COLOR_RED,COLOR_CYAN);
	addstr("The default colors have been set to\n");
	addstr("Red text on a cyan background.\n");
	refresh();
	getch();

	endwin();
	return 0;
}
Example #8
0
int main()
{
	initscr();
	start_color();
	assume_default_colors(-1,-1);
	refresh();
	// hardcoded graph attempt
	// graph starts at 10,5 too
	// to keep this one-off example simple, I won't include values out of range
	int roworigin = 10;
	int colorigin = 5;
	init_pair(1,COLOR_GREEN, -1);
	init_pair(2,COLOR_YELLOW, -1);
	init_pair(3,COLOR_RED, -1);
	int data_points[DATA_SET_SIZE] = {0,1,2,5,1,0,0,1,2,3,2,0};
	for (int i=0; i<DATA_SET_SIZE; i++) {
		// init color
		int color_pair = 3;
		switch (data_points[i]) {
			case 0 :
		    case 1 :
				color_pair = 1; 
				break;
			case 2 :
			case 3 : 
				color_pair = 2;
				break;
			default :
				break; 
		}
		attron(COLOR_PAIR(color_pair));
		for (int j=0; j<data_points[i]; j++) {
			mvaddch(roworigin - j, colorigin, BAR);
		}
		attroff(COLOR_PAIR(color_pair));
		for (int j=data_points[i]; j<MAX; j++) {
			mvaddch(roworigin - j, colorigin, BLANK);
		}
		refresh();
		sleep(1);
	}
	refresh();
	move(0,0);
	getch();
	endwin();

	return 0;
}
Example #9
0
int main()
{
	initscr();
	raw();
	keypad(stdscr, TRUE);
	noecho();
	curs_set(0);
	start_color();
	use_default_colors();

	init_pair(1, COLOR_BLUE, 144);/*COLOR_BLACK); */
	init_pair(2, COLOR_BLUE, 186);/*238); */
	init_pair(3, COLOR_BLUE, 187);/*245); */
	init_pair(4, COLOR_BLUE, COLOR_WHITE);


	init_pair(5, TREECOLOR, 144);/*COLOR_BLACK); */
	init_pair(6, TREECOLOR, 186);/*238); */
	init_pair(7, TREECOLOR, 187);/*245); */
	init_pair(8, TREECOLOR, COLOR_WHITE);

	init_pair(9, -1, COLOR_BLUE);
	init_pair(10, -1, COLOR_RED);

	assume_default_colors(COLOR_WHITE, COLOR_BLACK);

	srand(time(NULL));

	map = make_level(1000,1000);
	player = create_monster(PLAYER);
	player->x = 500;
	player->y = 500;
	player->hp = 100;
	snow_count = 10;

	offset_x = 0;
	offset_y = 0;

	messages = al_makenull(NULL);

	ninterface();

	endwin();

	return 0;
}
Example #10
0
 void reset(int code)
 {
   endwin();
   initscr();
   nonl();
   cbreak();
   noecho();
   keypad(stdscr, TRUE);
   nodelay(stdscr, TRUE);
   curs_set(FALSE);
   set_escdelay(10);
   start_color();
   use_default_colors();
   assume_default_colors(COLOR_WHITE, COLOR_BLACK);
   idlok(stdscr, TRUE);
   clear();
   refresh();
 }
Example #11
0
static void init_term(void)
{
    signal(SIGWINCH, on_window_resize);

#if HAVE_WIDECHAR

    if (setlocale(LC_ALL, "") == NULL) {
        fprintf(stderr, "Could not set your locale, plese check your locale settings or"
                "disable wide char support\n");
        exit(EXIT_FAILURE);
    }

#endif

    initscr();
    cbreak();
    keypad(stdscr, 1);
    noecho();
    timeout(100);

    if (has_colors()) {
        short bg_color = COLOR_BLACK;
        start_color();

        if (user_settings->colour_theme == NATIVE_COLS) {
            if (assume_default_colors(-1, -1) == OK)
                bg_color = -1;
        }

        init_pair(0, COLOR_WHITE, COLOR_BLACK);
        init_pair(1, COLOR_GREEN, bg_color);
        init_pair(2, COLOR_CYAN, bg_color);
        init_pair(3, COLOR_RED, bg_color);
        init_pair(4, COLOR_BLUE, bg_color);
        init_pair(5, COLOR_YELLOW, bg_color);
        init_pair(6, COLOR_MAGENTA, bg_color);
        init_pair(7, COLOR_BLACK, COLOR_BLACK);
        init_pair(8, COLOR_BLACK, COLOR_WHITE);
    }

    refresh();
}
Example #12
0
static void init_term(void)
{
    signal(SIGWINCH, flag_window_resize);

#if HAVE_WIDECHAR

    if (!arg_opts.default_locale) {
        if (setlocale(LC_ALL, "") == NULL)
            exit_toxic_err("Could not set your locale, please check your locale settings or "
                           "disable unicode support with the -d flag.", FATALERR_LOCALE_SET);
    }

#endif

    initscr();
    cbreak();
    keypad(stdscr, 1);
    noecho();
    timeout(100);

    if (has_colors()) {
        short bg_color = COLOR_BLACK;
        start_color();

        if (user_settings_->colour_theme == NATIVE_COLS) {
            if (assume_default_colors(-1, -1) == OK)
                bg_color = -1;
        }

        init_pair(0, COLOR_WHITE, COLOR_BLACK);
        init_pair(1, COLOR_GREEN, bg_color);
        init_pair(2, COLOR_CYAN, bg_color);
        init_pair(3, COLOR_RED, bg_color);
        init_pair(4, COLOR_BLUE, bg_color);
        init_pair(5, COLOR_YELLOW, bg_color);
        init_pair(6, COLOR_MAGENTA, bg_color);
        init_pair(7, COLOR_BLACK, COLOR_BLACK);
        init_pair(8, COLOR_BLACK, COLOR_WHITE);
    }

    refresh();
}
Example #13
0
int main(int argc, char *argv[]) {
	int i;

	initscr();

	// hide the cursor and keypresses
	curs_set(0);
	noecho();

	if (has_colors()) {
		color_ind = 1;
		start_color();

		// set background to black even for areas outside the drawing region
		assume_default_colors(COLOR_CYAN, COLOR_BLACK);

		init_pair(ETCH_COLOR_FRAME, COLOR_RED, COLOR_BLACK);
		init_pair(ETCH_COLOR_KNOB, COLOR_WHITE, COLOR_BLACK);
		init_pair(ETCH_COLOR_DRAW, COLOR_CYAN, COLOR_BLACK);
	} else {
		color_ind = 0;
	}


	// show the etch device
	drawEtch();

	// etch animation
	etchResume();


	// clear any pending keypresses and wait for another before quitting
	flushinp();
	getch();


	// restore the cursor and cleanup
	curs_set(1);
	endwin();

	return 1;
}
Example #14
0
//Инициальзирует все переменные и графику
void win_init()	
{
	//Инициализируем все переменные
	dir_print = 0;
	dir_inwin = 0;
	win_active = WIN_L;
	getcwd(dir_patch[WIN_L], 1024);
	getcwd(dir_patch[WIN_R], 1024);
	dir_content[WIN_L] = NULL;
	dir_content[WIN_R] = NULL;
	dir_count[WIN_L] = dir_get(dir_patch[WIN_L], &(dir_content[WIN_L]));
	dir_count[WIN_R] = dir_get(dir_patch[WIN_R], &(dir_content[WIN_R]));
	getcwd(te_path, 1024);
	strcat(te_path, "/bin/text_editor");

	//Инициализация ncurses
	initscr();						//ncurses mode
	refresh();	
	noecho();						//Отключить вывод клвиш
	curs_set(0);					//Прячем курсор
	keypad(stdscr, TRUE);			//Включаем обработку спец клавиш
	signal (SIGWINCH, win_resize);	//Вызов функции при ресайзе окна

	//Создаем окна
	win[WIN_BL] = newwin((LINES - 2), floor(COLS / 2), 0, 0);
	win[WIN_BR] = newwin((LINES - 2), COLS - floor(COLS / 2), 0, floor(COLS / 2));
	win[WIN_L] = newwin((LINES - 5), floor(COLS / 2 - 2), 2, 1);
	win[WIN_R] = newwin((LINES - 5), COLS - floor(COLS / 2) - 2, 2, floor(COLS / 2) + 1);
	win[WIN_PB] = newwin(2, COLS, LINES - 2, 0);
	win[WIN_CF] = NULL;
	//Цвета
	start_color();
	assume_default_colors(COLOR_WHITE,COLOR_BLUE);	//Цвета по умолчанию
	//Цветовые пары
	init_pair(1, COLOR_BLACK, COLOR_CYAN);			//Выбранная директори
	init_pair(2, COLOR_CYAN, COLOR_WHITE);			//Нижняя панель
	init_pair(3, COLOR_YELLOW, COLOR_BLUE);			//Заколовок таблицы
	
	winref_all();
}
Example #15
0
int main(int argc, char**argv)
{
cellgrid *cgrid;
cellgrid *tmpgrid;
//*initialize program
initscr();
start_color();
cbreak();
noecho();
nonl();
intrflush(stdscr,FALSE);
keypad(stdscr, TRUE);
assume_default_colors(COLOR_GREEN,COLOR_BLACK);
clear();
gol_set_default_rules();
cgrid=create_cellgrid(LINES-2,COLS-1);
generate_random_cells(cgrid);
while(1)
{
draw_cells(cgrid);
//getch();
gol_do_iteration(&cgrid);

if(cgrid->iteration%5==0){
	if(gol_is_repeating(cgrid)==TRUE){
	sleep(2);
	free_cellgrid(cgrid);
	cgrid=create_cellgrid(LINES-2,COLS-1);

	generate_random_cells(cgrid);
	//generate_pulsar(cgrid);
	}
}

}
sleep(3);

endwin();
return 0;
}
Example #16
0
void  inicializar_pantalla(){
/*
 *----------------------------------
 * */
    setlocale( LC_ALL, "" );
    initscr();

    if( has_colors() ){
        start_color();
        assume_default_colors(COLOR_WHITE, COLOR_BLUE);
        tiene_colores = 1;
    } else tiene_colores = 0;

    cbreak();       /* take input chars one at a time, no wait for \n */
    noecho();
    keypad(stdscr, TRUE); 
    curs_set( 0 );


    refresh();
    
 
}
Example #17
0
int main()
{
    TANK tank;
    MAP map;
    int ch;
    
	initscr();              // Start curses mode
		
	if(has_colors() == FALSE)
	{	endwin();
		printf("Your terminal does not support color\n");
		exit(1);
	}
	start_color();          // ieslēdz krāsu funkciju
	
	assume_default_colors(COLOR_WHITE, COLOR_BLACK); // pieņem default krāsas (background)
	
	cbreak();		        // Line buffering disabled
	keypad(stdscr, TRUE);
	noecho();               // neraksta uz ekrāna to ko nospied
	
	// Initialize color parameters
	init_pair(1, COLOR_CYAN, COLOR_BLACK);
	
    // Initialize the window parameters
    init_map_params(&map);
	print_map_params(&map);
	init_tank_params(&tank);
	print_tank_params(&tank);
	
	create_map(&map, TRUE); // izveido karti
	
	create_tank(&tank, TRUE);
		        
	while((ch = getch()) != KEY_F(1)) //lasa nospiestās pogas
	{	switch(ch)
		{	case KEY_LEFT:
		        //clear();
				create_tank_left(&tank, FALSE);
				--tank.startx;
				if(tank.startx <= map.startx){
				    ++tank.startx;
				    create_map(&map, TRUE);
				    create_tank_left(&tank, TRUE);
				}else{
				    create_tank_left(&tank, TRUE);
				    create_map(&map, TRUE);
				}
				break;
			case KEY_RIGHT:
		        //clear();
				create_tank_right(&tank, FALSE);
				++tank.startx;
				if(tank.startx + tank.width >= map.startx + MAP_WIDTH){
				    --tank.startx;
				    create_map(&map, TRUE);
				    create_tank_right(&tank, TRUE);
				}else{
				    create_tank_right(&tank, TRUE);
				    create_map(&map, TRUE);
				}
				break;
			case KEY_DOWN:
		        //clear();
				create_tank_down(&tank, FALSE);
				++tank.starty;
				if(tank.starty + tank.height >= map.starty + MAP_HEIGHT){
				    --tank.starty;
				    create_map(&map, TRUE);
				    create_tank_down(&tank, TRUE);
				}else{
				    create_tank_down(&tank, TRUE);
				    create_map(&map, TRUE);
				}
				break;
			case KEY_UP:
		        //clear();
				create_tank(&tank, FALSE);
				--tank.starty;
				if(tank.starty <= map.starty){
				    ++tank.starty;
				    create_map(&map, TRUE); 
				    create_tank(&tank, TRUE);
				}else{
				    create_tank(&tank, TRUE);
				    create_map(&map, TRUE);
				}
				break;
		}
	}
	refresh();			/* Print it on to the real screen */
	getch();			/* Wait for user input */
	endwin();			/* End curses mode		  */

	return 0;
}
Example #18
0
void start_curses( void )
{
  int keypad_on = 0;
  if ( isatty( fileno( stdout ) ) && LYReopenInput( ) < 0 )
  {
    fwrite( "Cannot open tty input\n", 1, 22, stderr );
    exit_immediately( 1 );
  }
  if ( LYscreen == 0 )
  {
    BOOLEAN savesize = recent_sizechange;
    size_change( 0 );
    recent_sizechange = savesize;
    if ( WWW_TraceFlag )
    {
      fprintf( TraceFP( ), "Screen size: %s()\n", "initscr" );
    }
    LYscreen = initscr( );
    if ( LYscreen == 0 )
    {
      fprintf( TraceFP( ), "%s\n", gettext( "Terminal initialisation failed - unknown terminal type?" ) );
      exit_immediately( 1 );
    }
    lynx_called_initscr = 1;
    LYlines = LYscreenHeight( );
    LYcols = LYscreenWidth( );
    size_change( 0 );
    recent_sizechange = 0;
    if ( WWW_TraceFlag )
    {
      fprintf( TraceFP( ), "Screen size is now %d x %d\n", LYlines, LYcols );
    }
    if ( LYuseCursesPads )
    {
      LYwin = newpad( LYlines, 1014 );
      LYshiftWin = 0;
      LYwideLines = 0;
    }
    else
      LYwin = stdscr;
    keypad( LYwin, 1 );
    keypad_on = 1;
    if ( lynx_initialize_keymaps( ) == -1 )
    {
      endwin( );
      exit_immediately( 1 );
    }
    if ( has_colors( ) & 255 )
    {
      lynx_has_color = 1;
      start_color( );
      if ( COLORS > 16 )
        COLORS = 16;
      if ( COLORS <= 7 )
        COLORS = 2;
      if ( COLORS > 8 && COLORS != 16 )
        COLORS = 8;
      if ( LYuse_default_colors )
      {
        if ( assume_default_colors( default_fg, default_bg ) )
        {
          default_fg = 7;
          default_bg = 0;
        }
        if ( WWW_TraceFlag )
        {
          fprintf( TraceFP( ), "initializing default colors %d/%d\n", default_fg, default_bg );
        }
        if ( default_fg >= 0 || default_bg >= 0 )
        {
          unsigned int n = 0;
          for ( ; n <= 7; n++ )
          {
            if ( default_fg >= 0 && lynx_color_cfg[ n ].fg < 0 )
              lynx_color_cfg[ n ].fg = default_fg;
            if ( default_bg >= 0 && lynx_color_cfg[ n ].bg < 0 )
              lynx_color_cfg[ n ].bg = default_bg;
            if ( WWW_TraceFlag )
            {
              fprintf( TraceFP( ), "color_cfg[%u] = %d/%d\n", n, lynx_color_cfg[ n ].fg, lynx_color_cfg[ n ].bg );
            }
            // n++;
          }
          lynx_setup_colors( );
        }
      }
    }
    if ( lynx_lss_file && lynx_lss_file[0] && ( LYCanReadFile( lynx_lss_file ) & 255 ) )
      style_readFromFile( lynx_lss_file );
    parse_userstyles( );
    lynx_init_colors( );
  }
  cbreak( );
  signal( 2, &cleanup_sig );
  noecho( );
  if ( keypad_on == 0 )
    keypad( LYwin, 1 );
  lynx_enable_mouse( 1 );
  fflush( stdin );
  fflush( stdout );
  fflush( stderr );
  LYCursesON = 1;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "start_curses: done.\n" );
  }
  return;
}
static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx)
{
	struct regedit *regedit;
	struct tree_node *root;
	bool colors;
	int key;

	initscr();

	cbreak();
	noecho();

	fault_configure(regedit_panic_handler);

	colors = has_colors();
	if (colors) {
		start_color();
		use_default_colors();
		assume_default_colors(COLOR_WHITE, COLOR_BLUE);
		init_pair(PAIR_YELLOW_CYAN, COLOR_YELLOW, COLOR_CYAN);
		init_pair(PAIR_BLACK_CYAN, COLOR_BLACK, COLOR_CYAN);
		init_pair(PAIR_YELLOW_BLUE, COLOR_YELLOW, COLOR_BLUE);
	}

	regedit = talloc_zero(mem_ctx, struct regedit);
	SMB_ASSERT(regedit != NULL);
	regedit_main = regedit;

	regedit->registry_context = ctx;
	regedit->main_window = stdscr;
	keypad(regedit->main_window, TRUE);

	mvwprintw(regedit->main_window, 0, 0, "Path: ");
	regedit->path_label = newpad(1, PATH_WIDTH_MAX);
	SMB_ASSERT(regedit->path_label);
	wprintw(regedit->path_label, "/");
	show_path(regedit_main);

	root = tree_node_new_root(regedit, ctx);
	SMB_ASSERT(root != NULL);

	regedit->keys = tree_view_new(regedit, root, KEY_HEIGHT, KEY_WIDTH,
				      KEY_START_Y, KEY_START_X);
	SMB_ASSERT(regedit->keys != NULL);

	regedit->vl = value_list_new(regedit, VAL_HEIGHT, VAL_WIDTH,
				     VAL_START_Y, VAL_START_X);
	SMB_ASSERT(regedit->vl != NULL);

	regedit->tree_input = true;
	print_heading(regedit);

	tree_view_show(regedit->keys);
	load_values(regedit);
	value_list_show(regedit->vl);

	update_panels();
	doupdate();

	do {
		key = regedit_getch();

		handle_main_input(regedit, key);
		update_panels();
		doupdate();
	} while (key != 'q' || key == 'Q');

	endwin();
}
Example #20
0
int main(int argc, char* argv[]){
  /* Initialize pseudo random number generator */
  srand(time(NULL));

  /* Read command line arguments */
  struct basic_options op;
  struct multi_options mop;
  if (get_options(argc, argv, &op, &mop) == 1) return 1;
 
  /* Setup signal handlers */
  struct sigaction newhandler;            /* new settings         */
  sigset_t         blocked;               /* set of blocked sigs  */
  newhandler.sa_flags = SA_RESTART;       /* options     */
  sigemptyset(&blocked);                  /* clear all bits       */
  newhandler.sa_mask = blocked;           /* store blockmask      */
  newhandler.sa_handler = on_timer;      /* handler function     */
  if ( sigaction(SIGALRM, &newhandler, NULL) == -1 )
    perror("sigaction");


  /* prepare the terminal for the animation */
  setlocale(LC_ALL, "");
  initscr();     /* initialize the library and screen */
  cbreak();      /* put terminal into non-blocking input mode */
  noecho();      /* turn off echo */
  start_color();
  clear();       /* clear the screen */
  curs_set(0);   /* hide the cursor */

  use_default_colors();
  init_pair(0, COLOR_WHITE, COLOR_BLACK);
  init_pair(1, COLOR_WHITE, COLOR_BLACK);
  init_pair(2, COLOR_BLACK, COLOR_BLACK);
  init_pair(3, COLOR_RED, COLOR_BLACK);
  init_pair(4, COLOR_GREEN, COLOR_BLACK);
  init_pair(5, COLOR_BLUE, COLOR_BLACK);
  init_pair(6, COLOR_YELLOW, COLOR_BLACK);
  init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
  init_pair(8, COLOR_CYAN, COLOR_BLACK);
 
  color_set(0, NULL);
  assume_default_colors(COLOR_WHITE, COLOR_BLACK);
  clear();
    
  struct state st;
  struct ui ui;

  /* Initialize the parameters of the program */
  attrset(A_BOLD | COLOR_PAIR(2));
  mvaddstr(0,0,"Map is generated. Please wait.");
  refresh();

  state_init(&st, &op, &mop);
 
  ui_init(&st, &ui);

  clear();
 
  /* non-blocking input */
  int fd_flags = fcntl(0, F_GETFL);
  fcntl(0, F_SETFL, (fd_flags|O_NONBLOCK));

  /* Start the real time interval timer with delay interval size */
  struct itimerval it;
  it.it_value.tv_sec = 0;
  it.it_value.tv_usec = 10000;
  it.it_interval.tv_sec = 0;
  it.it_interval.tv_usec = 10000;
  setitimer(ITIMER_REAL, &it, NULL);
  
  refresh();        
  input_ready = 0;
  time_to_redraw = 1;

  if (!mop.multiplayer_flag) {
    /* Run the game */
    run(&st, &ui);
  }
  else {
    if (mop.server_flag) run_server(&st, mop.clients_num, mop.val_server_port);
    else run_client(&st, &ui, mop.val_server_addr, mop.val_server_port, mop.val_client_port);
  }

  /* Restore the teminal state */
  echo();
  curs_set(1);
  clear();
  endwin();

  if (!mop.multiplayer_flag || mop.server_flag)
    printf ("Random seed was %i\n", st.map_seed);

  free(mop.val_server_addr);
  free(mop.val_server_port);
  free(mop.val_client_port);
  return 0;
}
Example #21
0
int main(void) {
    // int pid = getpid();
    // printf("PID = %d\n", pid);
    // getchar();

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);

    int scr_width, scr_height;
    getmaxyx(stdscr, scr_height, scr_width);
    int columns[scr_width];
    int arr_index;
    for(arr_index = 0; arr_index < scr_width; ++arr_index)
        columns[arr_index] = 0;

    start_color();

    assume_default_colors(COLOR_WHITE, COLOR_WHITE);

    init_pair(1, COLOR_RED, COLOR_RED);
    init_pair(2, COLOR_WHITE, COLOR_WHITE);
    init_pair(3, COLOR_BLUE, COLOR_BLUE);
    init_pair(4, COLOR_BLACK, COLOR_WHITE);
    init_pair(5, COLOR_BLACK, COLOR_BLACK);

    int block_start = 1;
    int block_end = block_start + 20;
    int block_row = scr_height - 1;

    int index;

    SET_COLOR_RED;
    for(index = block_start; index < 20; ++index) {
        move(block_row, index);
        delch();
        insch(' ');
    }

    SET_COLOR_BLACK;
    for(index = 0; index <= scr_width; ++index) {
        move(1, index);
        delch();
        insch(' ');
    }

    // hide cursor. doesn't work?.
    curs_set(0);
    refresh();
    // pthread_attr_t attr;

    pthread_mutex_init(&mutex, NULL);

    Block *block = malloc(sizeof(Block)); // freed by another thread
    block->start = 1;
    block->end = (block->start) + 20;
    block->row = scr_height - 1;
    block->screen_height = scr_height;
    block->screen_width = scr_width;
    block->cols = columns;

    // initialize score information
    score.bombs_caught = 0;
    score.bombs_missed = 0;
    score.points = 0;
    displayScore();

    speed = 1000; // 1 second

    pthread_t block_thread;
    threadPool.tid = block_thread;
    threadPool.next = NULL;
    pthread_create(&block_thread, NULL, blockMovement, (void *) block);

    pthread_t timer_thread;
    pthread_create(&timer_thread, NULL, changeSpeed, (void *) 0);
    addThread(timer_thread);

    pthread_t bomb_thread;
    pthread_create(&bomb_thread, NULL, drop_bombs, (void *) block);
    addThread(bomb_thread);
    // void *status;
    // wait for the user to press q to actually quit
    pthread_join(block_thread, NULL);
    // free(score);
    pthread_mutex_destroy(&mutex);
    pthread_exit(NULL);
}
Example #22
0
File: irc.c Project: klange/ponyos
int main(int argc, char * argv[]) {

	int c;

	while ((c = getopt(argc, argv, "hp:n:")) != -1) {
		switch (c) {

			case 'n':
				nick = optarg;
				break;

			case 'p':
				port = atoi(optarg);
				break;

			case 'h':
			default:
				show_usage(argc,argv);
		}
	}

	if (optind >= argc) {
		show_usage(argc,argv);
	}

	setlocale (LC_ALL, "");

	host = argv[optind];

	char tmphost[512];
	sprintf(tmphost, "/dev/net/%s:%d", host, port);
	int sockfd = open(tmphost, O_RDWR);
	sock = fdopen(sockfd, "w");
	sockb = fdopen(sockfd, "r");

	if (!sock) {
		fprintf(stderr, "%s: Connection failed or network not available.\n", argv[0]);
		return 1;
	}

	main_win = initscr();
	start_color();
	use_default_colors();
	assume_default_colors(-1,-1);

	for (int bg = 1; bg < 16; ++bg) {
		for (int fg = 0; fg < 16; ++fg) {
			init_pair(fg+bg*16, fg, bg);
		}
	}

	for (int fg = 1; fg < 16; ++fg) {
		init_pair(fg, fg, -1);
	}


	int w, h;
	getmaxyx(main_win, h, w);

	topic_win  = newwin(1, w, 0, 0);
	body_win   = newwin(h-3, w, 1, 0);
	status_win = newwin(1, w, h-2, 0);
	input_win  = newwin(1, w, h-1, 0);

	signal(SIGWINCH, SIGWINCH_handler);

	scrollok(body_win, TRUE);

	wbkgd(topic_win, COLOR_PAIR(COLOR_WHITE+COLOR_BLUE*16));
	wbkgd(body_win, COLOR_PAIR(0));
	wbkgd(status_win, COLOR_PAIR(COLOR_WHITE+COLOR_BLUE*16));
	wbkgd(input_win, COLOR_PAIR(0));

	/* Write the welcome thing to the body */
	wprintw(body_win, " - Toaru IRC v. %s - \n", VERSION_STRING);
	wprintw(body_win, " Copyright 2015 K Lange\n");
	wprintw(body_win, " http://toaruos.org - http://github.com/klange/toaruos\n");
	wprintw(body_win, "\n");
	wprintw(body_win, " For help, type /help.\n");

	wmove(topic_win, 0, 0);
	wprintw(topic_win, " Toaru IRC v. %s", VERSION_STRING);

	/* Update status */
	wmove(status_win, 0, 0);
	wprintw(status_win, "[%s] ", nick);

	refresh_all();

	pthread_create(&read_thread, NULL, irc_read_thread, NULL);

	fprintf(sock, "NICK %s\r\nUSER %s * 0 :%s\r\n", nick, nick, nick);
	fflush(sock);

	char * buf = malloc(1024);

	while (1) {
		spin_lock(&c_lock);
		wmove(input_win, 0, 0);
		wprintw(input_win, "[%s] ", channel ? channel : "(none)");
		memset(buf, 0, sizeof(buf));
		spin_unlock(&c_lock);
		wgetstr(input_win, buf);

		do_thing(buf);

		spin_lock(&c_lock);
		wclear(input_win);
		wrefresh(input_win);
		spin_unlock(&c_lock);
	}

	endwin();

	return 0;
}
Example #23
0
File: color.c Project: M6PIC/curses
/*
 * use_default_colors --
 *	Use terminal default colours instead of curses default colour.
  */
int
use_default_colors()
{
	return(assume_default_colors(-1, -1));
}
Example #24
0
int start_ncurses(const char *prog_name, const char *real_prog_name)
{
#if defined(DJGPP) || defined(__MINGW32__)
  if(initscr()==NULL)
  {
    log_critical("initscr() has failed. Exiting\n");
    printf("initscr() has failed. Exiting\n");
    printf("Press Enter key to quit.\n");
    (void)getchar();
    return 1;
  }
#else
  get_newterm(real_prog_name);
  if(screenp==NULL)
  {
    log_critical("Terminfo file is missing.\n");
#if defined(__CYGWIN__)
    printf("The terminfo file '63\\cygwin' is missing.\n");
#else
    printf("Terminfo file is missing.\n");
#endif
    printf("Extract all files and subdirectories before running the program.\n");
    printf("Press Enter key to quit.\n");
    (void)getchar();
    return 1;
  }
#endif
  /* Should solve a problem with users who redefined the colors */
  if(has_colors())
  {
    start_color();
#ifdef HAVE_ASSUME_DEFAULT_COLORS
    assume_default_colors(COLOR_WHITE,COLOR_BLACK);
#endif
    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_GREEN, COLOR_BLACK);
  }
  noecho();
#ifndef DJGPP
  nonl(); /*don't use for Dos version but enter will work with it... dilema */
#endif
  /*  intrflush(stdscr, FALSE); */
  cbreak();
  curs_set(0);
  {
    int quit=0;
    while(LINES>=8 && LINES<MINIMUM_LINES && quit==0)
    {
      aff_copy(stdscr);
      wmove(stdscr,4,0);
      wprintw(stdscr,"%s need %d lines to work.", prog_name, MINIMUM_LINES);
      wmove(stdscr,5,0);
      wprintw(stdscr,"Please enlarge the terminal.");
      wmove(stdscr,LINES-2,0);
      wattrset(stdscr, A_REVERSE);
      waddstr(stdscr,"[ Quit ]");
      wattroff(stdscr, A_REVERSE);
      wrefresh(stdscr);
      switch(wgetch(stdscr))
      {
	case 'q':
	case 'Q':
	case KEY_ENTER:
#ifdef PADENTER
	case PADENTER:
#endif
	case '\n':
	case '\r':
	  quit=1;
	  break;
      }
    }
  }
  if(LINES < MINIMUM_LINES)
  {
    end_ncurses();
    printf("%s need %d lines to work.\nPlease enlarge the terminal and restart %s.\n", prog_name, MINIMUM_LINES, prog_name);
    log_critical("Terminal has only %d lines\n",LINES);
    return 1;
  }
  return 0;
}
Example #25
0
int
ncurses_init()
{
    int bg, fg;
    const char *term;
    // Set Locale
    setlocale(LC_CTYPE, "");

    // Initialize curses
    if (!initscr()) {
        fprintf(stderr, "Unable to initialize ncurses mode.\n");
        return -1;
    }

    // Check if user wants a black background
    if (setting_has_value(SETTING_BACKGROUND, "dark")) {
        assume_default_colors(COLOR_WHITE, COLOR_BLACK);
    } else {
        use_default_colors();
    }
    // Enable Colors
    start_color();
    cbreak();

    // Dont write user input on screen
    noecho();
    // Hide the cursor
    curs_set(0);
    // Only delay ESC Sequences 25 ms (we dont want Escape sequences)
    ESCDELAY = 25;

    // Redefine some keys
    term = getenv("TERM");
    if (term
        && (!strcmp(term, "xterm") || !strcmp(term, "xterm-color") || !strcmp(term, "vt220"))) {
        define_key("\033[H", KEY_HOME);
        define_key("\033[F", KEY_END);
        define_key("\033OP", KEY_F(1));
        define_key("\033OQ", KEY_F(2));
        define_key("\033OR", KEY_F(3));
        define_key("\033OS", KEY_F(4));
        define_key("\033[11~", KEY_F(1));
        define_key("\033[12~", KEY_F(2));
        define_key("\033[13~", KEY_F(3));
        define_key("\033[14~", KEY_F(4));
        define_key("\033[17;2~", KEY_F(18));
    }

    if (setting_has_value(SETTING_BACKGROUND, "dark")) {
        fg = COLOR_WHITE;
        bg = COLOR_BLACK;
    } else {
        fg = COLOR_DEFAULT;
        bg = COLOR_DEFAULT;
    }

    // Initialize colorpairs
    init_pair(CP_CYAN_ON_DEF, COLOR_CYAN, bg);
    init_pair(CP_YELLOW_ON_DEF, COLOR_YELLOW, bg);
    init_pair(CP_MAGENTA_ON_DEF, COLOR_MAGENTA, bg);
    init_pair(CP_GREEN_ON_DEF, COLOR_GREEN, bg);
    init_pair(CP_RED_ON_DEF, COLOR_RED, bg);
    init_pair(CP_BLUE_ON_DEF, COLOR_BLUE, bg);
    init_pair(CP_WHITE_ON_DEF, COLOR_WHITE, bg);
    init_pair(CP_DEF_ON_CYAN, fg, COLOR_CYAN);
    init_pair(CP_DEF_ON_BLUE, fg, COLOR_BLUE);
    init_pair(CP_WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
    init_pair(CP_BLACK_ON_CYAN, COLOR_BLACK, COLOR_CYAN);
    init_pair(CP_WHITE_ON_CYAN, COLOR_WHITE, COLOR_CYAN);
    init_pair(CP_YELLOW_ON_CYAN, COLOR_YELLOW, COLOR_CYAN);
    init_pair(CP_BLUE_ON_CYAN, COLOR_BLUE, COLOR_CYAN);
    init_pair(CP_BLUE_ON_WHITE, COLOR_BLUE, COLOR_WHITE);
    init_pair(CP_CYAN_ON_WHITE, COLOR_CYAN, COLOR_WHITE);
    init_pair(CP_CYAN_ON_BLACK, COLOR_CYAN, COLOR_BLACK);

    return 0;
}
Example #26
0
use_default_colors(void)
{
    T((T_CALLED("use_default_colors()")));
    returnCode(assume_default_colors(C_MASK, C_MASK));
}
Example #27
0
int main(int argc, char *argv[]) {
  int option;
  int option_index;
  int passes_through_deck = 3;
  int use_utf8 = 0;
  static const struct option options[] = {
    {"help",    no_argument,       NULL, 'h'},
    {"version", no_argument,       NULL, 'v'},
    {"passes",  required_argument, NULL, 'p'},
    {"utf8",    no_argument,       NULL, 'u'}
  };

  program_name = argv[0];

  while ((option = getopt_long(argc, argv, "hvp:u", options, &option_index)) != -1) {
    switch (option) {
    case 'v':
      version();
      exit(0);
    case 'p':
      passes_through_deck = atoi(optarg);
      break;
    case 'u':
      use_utf8 = true;
      break;   
    case 'h':
    default:
      usage(program_name);
      exit(0);
    }
  }

  set_utf8_mode(use_utf8);
  setlocale(LC_ALL, "");
  initscr();
  raw();
  noecho();
  keypad(stdscr, TRUE);
  start_color();
  curs_set(FALSE);
  set_escdelay(0);
  assume_default_colors(COLOR_WHITE, COLOR_GREEN);
  init_pair(1, COLOR_BLACK, COLOR_WHITE);
  init_pair(2, COLOR_RED, COLOR_WHITE);
  init_pair(3, COLOR_WHITE, COLOR_BLUE);
  init_pair(4, COLOR_WHITE, COLOR_GREEN);

  int key;

  while (!term_size_ok()) {
    clear();
    mvprintw(1, 1, SMALL_TERM_MSG);
    refresh();
    if ((key = getch()) == 'q' || key == 'Q') {
      endwin();
      return(0);
    }
  }

  clear();
  draw_greeting();
  refresh();

  for (;;) {
    if ((key = getch()) == 'q' || key == 'Q') {
      endwin();
      return(0);
    }
    if (term_size_ok()) {
      clear();
      draw_greeting();
      refresh();
      if (key == KEY_SPACEBAR) {
        clear();
        refresh();
        game_init(&game, passes_through_deck);
        break;
      }
    } else if (key == KEY_RESIZE) {
      clear();
      mvprintw(1, 1, SMALL_TERM_MSG);
      refresh();
    }
  }

  do {
    keyboard_event(getch());
  } while (!game_won());

  endwin();
  game_end();
  printf("You won.\n");

  return(0);
}