Exemple #1
0
int print_it_nocurses ( ppstat *stats_array, int count )
{
	int i, j;
	time_t t;
	struct tm *now;
	char timestring[9];
	extern pmstat memory;
	output = &printf;

	mousemask(ALL_MOUSE_EVENTS, NULL);
	keypad ( win, TRUE );
	erase();

	t = time ( NULL );
	now = localtime ( &t );
	strftime ( timestring, 9, "%H:%M:%S", now );
	
	attroff ( A_BOLD );

	/*
	print the header
	*/
	for ( j = 0; j < FIELDS_AVAILABLE; j++ )
	{
		if ( display_fields[j] == NULL )
		{
			break;
		}
		output ( display_fields[j]->header_format, display_fields[j]->fieldname );
	}
	printf ( "\n" );

	/*
	print the data fields
	*/
	for ( i = 0; i < count; i++ )
	{
		for ( j = 0; j < FIELDS_AVAILABLE; j++ )
		{
			if ( display_fields[j] == NULL )
			{
				break;
			}
			display_fields[j]->printout( stats_array[i], display_fields[j]->identifier );
		}
		printf ( "\n" );
	}
	return ( i + 1 );
}
Exemple #2
0
/* creation - ncurses' window handling */
void
set_input_opts (void)
{
  initscr ();
  clear ();
  noecho ();
  halfdelay (10);
  nonl ();
  intrflush (stdscr, FALSE);
  keypad (stdscr, TRUE);
  curs_set (0);

  if (conf.mouse_support)
    mousemask (BUTTON1_CLICKED, NULL);
}
Exemple #3
0
void initcurses()
{
    locale = setlocale(LC_ALL, NULL);
    setlocale(LC_ALL, "");
    initscr();
    noecho();
    curs_set(0);
    keypad(stdscr,true); //разрешаем стрелки и т.п.
#ifdef ENABLEMOUSE
    mousemask(ALL_MOUSE_EVENTS, NULL); // Report all mouse events
#endif
    timeout(100); //ожидание для getch() 100 милисекунд
    start_color();
    initcolorpairs();
}
Exemple #4
0
/* ----------- Global Functions ---------------------------------- */
int uiview_init(void)
{
  int rv = 0;

  initscr();
  cbreak();
  noecho();
  curs_set(0);
  nodelay(stdscr, TRUE);
  keypad(stdscr, TRUE);
  mousemask(ALL_MOUSE_EVENTS, NULL);
  mouseinterval(300);
 
  return rv;
}
Exemple #5
0
ui_t *create_ui() {
  ui_t *ui = malloc(sizeof(ui_t));

  initscr();
  init_colours();
  noecho();

  /* Get all the mouse events */
  mousemask(ALL_MOUSE_EVENTS, NULL);
  mouseinterval(1);
  keypad(stdscr, TRUE);

  render_ui(ui);
  return ui;
}
Exemple #6
0
int main()
{	int c, choice = 0;
	WINDOW *menu_win;
	MEVENT event;

	/* Initialize curses */
	initscr();
	clear();
	noecho();
	cbreak();	//Line buffering disabled. pass on everything

	/* Try to put the window in the middle of screen */
	startx = (80 - WIDTH) / 2;
	starty = (24 - HEIGHT) / 2;
	
	attron(A_REVERSE);
	mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
	refresh();
	attroff(A_REVERSE);

	/* Print the menu for the first time */
	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
	print_menu(menu_win, 1);
	/* Get all the mouse events */
	mousemask(ALL_MOUSE_EVENTS, NULL);
	
	while(1)
	{	c = wgetch(menu_win);
		switch(c)
		{	case KEY_MOUSE:
			if(getmouse(&event) == OK)
			{	/* When the user clicks left mouse button */
				if(event.bstate & BUTTON1_PRESSED)
				{	report_choice(event.x + 1, event.y + 1, &choice);
					if(choice == -1) //Exit chosen
						goto end;
					mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]);
					refresh(); 
				}
			}
			print_menu(menu_win, choice);
			break;
		}
	}		
end:
	endwin();
	return 0;
}
Exemple #7
0
static int ncurses_end_graphics(caca_display_t *dp)
{
    _caca_set_term_title("");
    mousemask(dp->drv.p->oldmask, NULL);
    curs_set(1);
    noraw();
    endwin();

#if defined HAVE_GETENV && defined HAVE_PUTENV
    ncurses_uninstall_terminal(dp);
#endif

    free(dp->drv.p);

    return 0;
}
Exemple #8
0
/* creation - ncurses' window handling */
void
set_input_opts (void)
{
  initscr ();
  clear ();
  noecho ();
  halfdelay (10);
  nonl ();
  intrflush (stdscr, FALSE);
  keypad (stdscr, TRUE);
  if (curs_set (0) == ERR)
    LOG_DEBUG (("Unable to change cursor: %s\n", strerror (errno)));

  if (conf.mouse_support)
    mousemask (BUTTON1_CLICKED, NULL);
}
Exemple #9
0
int main(int argc, char** argv) {
	initscr();
	raw();
	noecho();
	curs_set(0);
	keypad(stdscr, true);
	mousemask(BUTTON1_RELEASED | BUTTON3_RELEASED, 0);

	int state = RUNNING;
	int size_x = 12;
	int size_y = 8;

	if (argc > 1)
		size_x = atoi(argv[1]);
	if (argc > 2)
		size_y = atoi(argv[2]);

	char* field = calloc(size_x * size_y, sizeof(char));

	signal(SIGALRM, timer_tick);
	timer_tick(size_x); // start timer

	state = game_loop(field, size_x, size_y);

	struct itimerval tout_val = {{0}};	// stop timer
	setitimer(ITIMER_REAL, &tout_val, 0);

	switch (state) {
	case WON:
		mvprintw(3, size_x + 2, ":-)");
		refresh();
		getch();

		break;
	case LOST:
		mvprintw(3, size_x + 2, ":-(");
		refresh();
		getch();

		break;
	case QUIT:
		break;
	}

	endwin();
	return 0;
}
Exemple #10
0
void Terminal::Initialize(){
	if(init){ return; }
	
	original = std::cout.rdbuf(); // Back-up cout's streambuf
	pbuf = stream.rdbuf(); // Get stream's streambuf
	std::cout.flush();
	std::cout.rdbuf(pbuf); // Assign streambuf to cout
	
	main = initscr();
	
	if(main == NULL ){ // Attempt to initialize ncurses
		std::cout.rdbuf(original); // Restore cout's original streambuf
		fprintf(stderr, " Error: failed to initialize ncurses!\n");
	}
	else{		
   		getmaxyx(stdscr, _winSizeY, _winSizeX);
		output_window = newpad(_scrollbackBufferSize, _winSizeX);
		input_window = newpad(1, _winSizeX);
		wmove(output_window, _scrollbackBufferSize-1, 0); // Set the output cursor at the bottom so that new text will scroll up
		
		halfdelay(5); // Timeout after 5/10 of a second
		keypad(input_window, true); // Capture special keys
		noecho(); // Turn key echoing off
		
		scrollok(output_window, true);
		scrollok(input_window, true);

		if (NCURSES_MOUSE_VERSION > 0) {		
			mousemask(ALL_MOUSE_EVENTS,NULL);
			mouseinterval(0);
		}

		init = true;
		text_length = 0;
		offset = 0;
		
		// Set the position of the physical cursor
		cursX = 0; cursY = _winSizeY-1;
		update_cursor_();
		refresh_();

		init_colors_();
	}
	
	setup_signal_handlers();
}
int InputManager::startUp(){
    GraphicsManager& graphics_manager = GraphicsManager::getInstance();
    LogManager& log_manager = LogManager::getInstance();
    if(!graphics_manager.isStarted()){
        log_manager.writeLog("InputManager::startUp(): GraphicsManager is not started. ");
        return -1;
    }
    
    // Error checking
    int* flag = new int[7]();
    
    // enable keypad
    *(flag++) = keypad(stdscr, TRUE);

    // disable line buffering
    *(flag++) = cbreak();

    // turn off newline so can detect 'enter' key
    *(flag++) = nonl();

    // disable character echo
    *(flag++) = noecho();

    // turn off the cursor
    *(flag++) = curs_set(0);

    // no delay for input
    *(flag++) = nodelay(stdscr, TRUE);

    // enable mouse event
    *flag = mousemask(BUTTON1_CLICKED, NULL);

    flag -= 6;
    for(int i = 0; i != 7; i++){
        if(*(flag+i) == ERR){
            log_manager.writeLog("InputManager::startUp(): curse input start fails. ");
            delete[] flag;
            return -1;
        }
    }
    Manager::startUp();
    delete[] flag;
    return 0;
}
// sets up global variables necessary to use ncurses
void GUI_Globals::init_gui()
{
   //setlocale(LC_ALL, "");
   initscr();
   start_color();
   raw();
   keypad(stdscr, TRUE);
   noecho();
   MEVENT event;
   mousemask(ALL_MOUSE_EVENTS, NULL);
   if (has_colors() == FALSE)
   {  endwin();
      printf("Your terminal doesn't support colors\n");
      exit(1);
   }
   init_pair(1, COLOR_RED, COLOR_BLACK);
   init_pair(2, COLOR_BLUE, COLOR_BLACK);
   GUI_Globals::GUI_IS_ON = true;
}
Exemple #13
0
/*
 * Initialize screen display.
 */
void
cursinit()
{
	initscr();
	if ((LINES < SCRNH) || (COLS < SCRNW)) {
		endwin();
		errx(1,"Screen too small (need %dx%d)",SCRNW,SCRNH);
	}
#ifdef KEY_MIN
	keypad(stdscr, TRUE);
#endif /* KEY_MIN */
	nonl();
	noecho();
	cbreak();

#ifdef NCURSES_MOUSE_VERSION
	mousemask(BUTTON1_CLICKED, (mmask_t *)NULL);
#endif /* NCURSES_MOUSE_VERSION*/
}
int main(int argc, char const *argv[]) {
    int c, choice = 0;
    WINDOW *menu_win;
    MEVENT event;

    initscr();
    clear();
    noecho();
    cbreak();

    startx = (80 - WIDTH) / 2;
    starty = (24 - HEIGHT) / 2;

    attron(A_REVERSE);
    mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
    refresh();
    attroff(A_REVERSE);

    menu_win = newwin(HEIGHT, WIDTH, starty, startx);
    print_menu(menu_win, 1);
    mousemask(ALL_MOUSE_EVENTS, NULL);

    while (1) {
        c = wgetch(menu_win);
        switch (c) {
        case KEY_MOUSE:
            if (getmouse(&event) == OK) {
                if (event.bstate & BUTTON1_PRESSED) {
                    report_choice(event.x + 1, event.y + 1, &choice);
                    if (choice == -1)
                        goto end;
                    mvprintw(22, 1, "Choice made is : %d String Choice is \"%s\"", choice, choices[choice]);
                    refresh();
                }
            }
            print_menu(menu_win, choice);
            break;
        }
    }
end:
    endwin();
    return 0;
}
Exemple #15
0
Fichier : CRT.c Projet : lyase/htop
void CRT_init(int delay, int colorScheme) {
     initscr();
     noecho();
     CRT_delay = delay;
     CRT_colorScheme = colorScheme;
     halfdelay(CRT_delay/2);
     nonl();
     intrflush(stdscr, false);
     keypad(stdscr, true);
     curs_set(0);
     if (has_colors()) {
          start_color();
          CRT_hasColors = true;
     } else {
          CRT_hasColors = false;
     }
     CRT_termType = getenv("TERM");
     if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "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));
     }
#ifndef DEBUG
     signal(11, CRT_handleSIGSEGV);
#endif
     signal(SIGTERM, CRT_handleSIGTERM);
     use_default_colors();
     if (!has_colors())
          CRT_colorScheme = 1;
     CRT_setColors(CRT_colorScheme);

     mousemask(BUTTON1_CLICKED, NULL);
}
Exemple #16
0
int32_t tui_init(void)
{
    //Start curses
    initscr( );
    //No buffer for getch()
    cbreak( );
    raw( );
    nonl( );
    //no echo while entering from keyboard
    noecho( );
    //no text cursor
    curs_set(0);
    //Enable special keys
    keypad(stdscr, TRUE);
    //
    mousemask(ALL_MOUSE_EVENTS, NULL);
    //start color mode
    if ( has_colors( ) == FALSE )
    {
        endwin( );
        printf("\nYour terminal does not support color\n");
        return 1;
    }
    start_color( );
    use_default_colors( );
    //set main colors
    init_pair( 1, COLOR_WHITE,   COLOR_BLUE);
    init_pair( 2, COLOR_GREEN,    COLOR_BLACK);
    init_pair( 3, COLOR_MAGENTA,  COLOR_BLUE);
    init_pair( 4, COLOR_BLACK,     COLOR_YELLOW);
    init_pair( 5, COLOR_GREEN,   COLOR_WHITE);
    init_pair( 6, COLOR_BLUE,   COLOR_WHITE);
    init_pair( 7, COLOR_MAGENTA,   COLOR_WHITE);
    init_pair( 8, COLOR_WHITE, COLOR_MAGENTA);
    init_pair( 9, COLOR_CYAN,    COLOR_WHITE);
    init_pair(10, COLOR_YELLOW,  COLOR_BLACK);
    //assume_default_colors(COLOR_BLUE, COLOR_BLACK);

    return 0;
}
Exemple #17
0
pLScreen::pLScreen()
{
	row = 0 ;
	col = 0 ;
	if ( screensTotal == 0 )
	{
		initscr();
		getmaxyx( stdscr, maxrow, maxcol ) ;
		if ( (maxrow < 24) || (maxcol < 80) )
		{
			endwin() ;
			cout << "This program cannot run in a screen with fewer than 24 lines and 80 columns." << endl ;
			cout << "The size of this screen is " << maxrow << " lines by " << maxcol << " columns." << endl ;
			cout << "Exiting..." << endl ;
			return;
		}
		maxrow = maxrow - 2 ;
		start_color();
		cbreak() ;
		noecho() ;
		nonl()   ;
		intrflush( stdscr, FALSE ) ;
		keypad( stdscr, TRUE )     ;
		init_pair( 0, COLOR_BLACK,   COLOR_BLACK ) ;
		init_pair( 1, COLOR_RED,     COLOR_BLACK ) ;
		init_pair( 2, COLOR_GREEN,   COLOR_BLACK ) ;
		init_pair( 3, COLOR_YELLOW,  COLOR_BLACK ) ;
		init_pair( 4, COLOR_BLUE,    COLOR_BLACK ) ;
		init_pair( 5, COLOR_MAGENTA, COLOR_BLACK ) ;
		init_pair( 6, COLOR_CYAN,    COLOR_BLACK ) ;
		init_pair( 7, COLOR_WHITE,   COLOR_BLACK ) ;
		mvhline( maxrow, 0, ACS_HLINE, maxcol ) ;
		mousemask( ALL_MOUSE_EVENTS, NULL ) ;
		OIA = newwin( 1, maxcol, maxrow+1, 0 ) ;
	}
	++screensTotal    ;
	currScreen = this ;
	screenID   = ++maxScreenID ;
}
Exemple #18
0
static void
init_program(void)
{
    setlocale(LC_ALL, "");

    srand((unsigned) getpid());
    initscr();
    cbreak();			/* immediate char return */
    noecho();			/* no immediate echo */
    boardwin = newwin(BDEPTH * 2 + 1, BWIDTH * 4 + 1, BOARDY, BOARDX);
    helpwin = newwin(0, 0, INSTRY, INSTRX);
    msgwin = newwin(1, INSTRX - 1, NOTIFYY, 0);
    scrollok(msgwin, TRUE);
    keypad(boardwin, TRUE);

    if (has_colors()) {
	int bg = COLOR_BLACK;

	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() == OK)
	    bg = -1;
#endif

	(void) init_pair(TRAIL_COLOR, (short) COLOR_CYAN, (short) bg);
	(void) init_pair(PLUS_COLOR, (short) COLOR_RED, (short) bg);
	(void) init_pair(MINUS_COLOR, (short) COLOR_GREEN, (short) bg);

	trail |= COLOR_PAIR(TRAIL_COLOR);
	plus |= COLOR_PAIR(PLUS_COLOR);
	minus |= COLOR_PAIR(MINUS_COLOR);
    }
#ifdef NCURSES_MOUSE_VERSION
    (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
#endif /* NCURSES_MOUSE_VERSION */

    oldch = minus;
}
Exemple #19
0
bool mrutils::ColChooser::init() {
    mrutils::mutexAcquire(updateMutex);
    refresh();

    if (createdWin) {
        use_default_colors();
        start_color();
    }

    keypad(stdscr, TRUE);
    if (enableMouse) mousemask(ALL_MOUSE_EVENTS, NULL);

    init_pair(COL_BLANK   ,   -1,     -1);
    init_pair(COL_SELECTED,    0,     12);
    init_pair(COL_INPUT   ,    0,      8);
    init_pair(COL_TARGETED,    0,     11);

    if (data.size() > 1) {
        int columns = data.size();
        int width = (cols - data[0].colWidth) / (columns - 1);
        data[columns-1].colWidth = cols - data[0].colWidth;
        for (int i = 1; i < columns-1; ++i) {
            data[i].colWidth = width;
            data[columns-1].colWidth -= width;
            mvwvline((WINDOW*)chooserWin, 0, 
                data[i-1].colWidth, ACS_VLINE, lines-1);
        }

        mvwvline((WINDOW*)chooserWin, 0, 
            cols - data[columns-1].colWidth, ACS_VLINE, lines-1);
    }

    wmove((WINDOW*)chooserWin,0,0);

    mrutils::mutexRelease(updateMutex);
    return true;

}
Exemple #20
0
int main(void)
{
  int ch;
  mev = (MEVENT *)malloc(sizeof(MEVENT));

  initscr();
  atexit(quit);
  clear();
  noecho();
  curs_set(0);
  cbreak();
  keypad(stdscr, TRUE);
  start_color();
  mousemask(BUTTON1_CLICKED, 0);

  init_pair(1, COLOR_YELLOW, COLOR_BLUE);
  bkgd(COLOR_PAIR(1));
  mvaddstr(5, 3, "Programm durch anklicken der Maustaste 1 beenden");
  refresh();
 
  for(;;)
  {
    ch=getch();
        
    switch(ch)
    {
      case KEY_MOUSE:
      { 
        if(getmouse(mev) == OK)
        {
          exit(0);
        }
      } 
    }   
  }   

  return (0);  
}
Exemple #21
0
/* set up ncurses screen */
WINDOW * init_screen() {
	WINDOW * win = initscr();
	noecho();
	timeout(0);
	keypad(win, 1);
	mousemask(BUTTON1_PRESSED, NULL);
	mouseinterval(200);
	curs_set(0);

	start_color();
	init_color(COLOR_CYAN, 500, 1000, 0);  /* redefine as orange */

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

	return win;
}
// _____________________________________________________________________________
void MineSweeperGame::play(size_t numRows, size_t numCols, size_t numMines) {
  _mss.initialize(numRows, numCols, numMines);
  _mss.setMines();
  mousemask(ALL_MOUSE_EVENTS, NULL);
  while (true) {
    _mss.drawField();

    // check whether game is already over and print appropriate output if it is
    if (_mss.status() != MineSweeperState::GameStatus::ONGOING) {
      gameOver();

    // process user input
    } else {
      printf("\x1b[%d;%dH", _mss.yAl() - 3, _mss.xAl() + _mss.numCols());
      printf("\xF0\x9F\x98\x8A");
      if (getmouse(&_me) == OK) {
        processClick();
      }
    }
    int ch = getch();
    if (ch == 'q') break;
    if (ch == 'r') _mss.reset();
  }
}
Exemple #23
0
int main (void)
{
	mmask_t mask;
	MEVENT event;
	int ch;

	initscr();
	cbreak();
	keypad (stdscr, true);

	/*Detectando eventos do mouse*/
	mousemask (mask, NULL);
	
	while ((toupper(ch = getch())) != 'Q')
	{
		if (ch == KEY_MOUSE) {
			getmouse (&event);
			switch (event.bstate) {
				case BUTTON1_RELEASED:
					printw  ("botao 1 pressionado!\n");
					break;
				case BUTTON2_RELEASED:
					printw  ("botao 2 pressionado!\n");
					break;
				case BUTTON3_RELEASED:
					printw  ("botao 3 pressionado!\n");
					break;
				default:
					printw ("evento desconhecido");
			}
		refresh ();
		}
	}

	endwin ();
}
Exemple #24
0
void CRT_init(int delay, int colorScheme) {
   initscr();
   noecho();
   CRT_delay = delay;
   if (CRT_delay == 0) {
      CRT_delay = 1;
   }
   CRT_colors = CRT_colorSchemes[colorScheme];
   CRT_colorScheme = colorScheme;
   
   for (int i = 0; i < LAST_COLORELEMENT; i++) {
      unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i];
      CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPair(Black,Black)) ? ColorPair(White,Black) : color;
   }
   
   halfdelay(CRT_delay);
   nonl();
   intrflush(stdscr, false);
   keypad(stdscr, true);
   mouseinterval(0);
   curs_set(0);
   if (has_colors()) {
      start_color();
      CRT_hasColors = true;
   } else {
      CRT_hasColors = false;
   }
   CRT_termType = getenv("TERM");
   if (String_eq(CRT_termType, "linux"))
      CRT_scrollHAmount = 20;
   else
      CRT_scrollHAmount = 5;
   if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "vt220")) {
      define_key("\033[H", KEY_HOME);
      define_key("\033[F", KEY_END);
      define_key("\033[7~", KEY_HOME);
      define_key("\033[8~", 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));
      char sequence[3] = "\033a";
      for (char c = 'a'; c <= 'z'; c++) {
         sequence[1] = c;
         define_key(sequence, KEY_ALT('A' + (c - 'a')));
      }
   }
#ifndef DEBUG
   signal(11, CRT_handleSIGSEGV);
#endif
   signal(SIGTERM, CRT_handleSIGTERM);
   signal(SIGQUIT, CRT_handleSIGTERM);
   use_default_colors();
   if (!has_colors())
      CRT_colorScheme = 1;
   CRT_setColors(CRT_colorScheme);

   /* initialize locale */
   setlocale(LC_CTYPE, "");

#ifdef HAVE_LIBNCURSESW
   if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
      CRT_utf8 = true;
   else
      CRT_utf8 = false;
#endif

   CRT_treeStr =
#ifdef HAVE_LIBNCURSESW
      CRT_utf8 ? CRT_treeStrUtf8 :
#endif
      CRT_treeStrAscii;

#if NCURSES_MOUSE_VERSION > 1
   mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
#else
   mousemask(BUTTON1_RELEASED, NULL);
#endif

}
Exemple #25
0
static void
intro(void)
{
    char *tmpname;

    srand((unsigned) (time(0L) + getpid()));	/* Kick the random number generator */

    (void) signal(SIGINT, uninitgame);
    (void) signal(SIGINT, uninitgame);
    (void) signal(SIGIOT, uninitgame);	/* for assert(3) */
    if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
	(void) signal(SIGQUIT, uninitgame);

    if ((tmpname = getlogin()) != 0) {
	(void) strcpy(name, tmpname);
	name[0] = toupper(name[0]);
    } else
	(void) strcpy(name, dftname);

    (void) initscr();
    keypad(stdscr, TRUE);
    (void) def_prog_mode();
    (void) nonl();
    (void) cbreak();
    (void) noecho();

#ifdef PENGUIN
    (void) clear();
    (void) mvaddstr(4, 29, "Welcome to Battleship!");
    (void) move(8, 0);
    PR("                                                  \\\n");
    PR("                           \\                     \\ \\\n");
    PR("                          \\ \\                   \\ \\ \\_____________\n");
    PR("                         \\ \\ \\_____________      \\ \\/            |\n");
    PR("                          \\ \\/             \\      \\/             |\n");
    PR("                           \\/               \\_____/              |__\n");
    PR("           ________________/                                       |\n");
    PR("           \\  S.S. Penguin                                         |\n");
    PR("            \\                                                     /\n");
    PR("             \\___________________________________________________/\n");

    (void) mvaddstr(22, 27, "Hit any key to continue...");
    (void) refresh();
    (void) getch();
#endif /* PENGUIN */

#ifdef A_COLOR
    start_color();

    init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
    init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
    init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
    init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
    init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
    init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
    init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
    init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
#endif /* A_COLOR */

#ifdef NCURSES_MOUSE_VERSION
    (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
#endif /* NCURSES_MOUSE_VERSION */
}
Exemple #26
0
void console_init_graphics(Console* con, point resolution, font* fnt) {
	(void) resolution; (void) fnt;
	char org_term[64];

	struct NcConsole *self = &con->backend.nc;

	snprintf(org_term, sizeof org_term, "%s", getenv("TERM"));

	if(!strcmp(org_term, "xterm")) {
		setenv("TERM", "xterm-256color", 1);
		self->flags |= NC_SUPPORTSCOLORREADER;
	} else if(!strcmp(org_term, "rxvt-unicode")) {
		setenv("TERM", "rxvt-unicode-256color", 1);
		self->flags |= NC_SUPPORTSCOLORREADER;
	} else if(!strcmp(org_term, "xterm-256color")) {
		self->flags |= NC_SUPPORTSCOLORREADER;
	}


	self->active.fgcol = -1;
	self->active.fgcol = -1;

	self->lastattr = 0;

	console_inittables(con);

	initscr();
	noecho();
	cbreak();
	keypad(stdscr, TRUE);
	nonl(); // get return key events

	// the ncurses table is apparently only initialised after initscr() oslt
	ncurses_chartab_init();

#ifdef CONSOLE_DEBUG
	dbg = fopen("console.log", "w");
#endif

	if(!getenv("CONCOL_NO_COLORS")) {
		if (has_colors()) self->flags |= NC_HASCOLORS;
	}
	if (self_hasColors(self) && can_change_color())
		self->flags |= NC_CANCHANGECOLORS;

	if (self_hasColors(self)) start_color();
	self->maxcolors = get_maxcolors(org_term);

	if (self_canChangeColors(self))
		console_savecolors(self);

	if(mousemask(ALL_MOUSE_EVENTS |
		BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED |
		BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED |
		REPORT_MOUSE_POSITION | BUTTON_SHIFT | BUTTON_ALT | BUTTON_CTRL,
		NULL) != (mmask_t) ERR) {
		mouseinterval(0) /* prevent ncurses from making click events.
		this way we always get an event for buttondown and up.
		we won't get any mouse movement events either way. */;
		self->flags |= NC_HASMOUSE;
	}
	PDEBUG("hasmouse: %d\n", self_hasMouse(self));
	self->lastattr = 0;

	self->maxcolor = 0;

	self->lastused.fgcol = -1;
	self->lastused.bgcol = -1;

	getmaxyx(stdscr, con->dim.y, con->dim.x);
}
Exemple #27
0
void gnt_init()
{
	char *filename;
	const char *locale;

	if (channel)
		return;

	locale = setlocale(LC_ALL, "");

	setup_io();

#ifdef NO_WIDECHAR
	ascii_only = TRUE;
#else
	if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) {
		ascii_only = FALSE;
	} else {
		ascii_only = TRUE;
		gnt_need_conversation_to_locale = TRUE;
	}
#endif

	initscr();
	typeahead(-1);
	noecho();
	curs_set(0);

	gnt_init_keys();
	gnt_init_styles();

	filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL);
	gnt_style_read_configure_file(filename);
	g_free(filename);

	gnt_init_colors();

	wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
	refresh();

#ifdef ALL_MOUSE_EVENTS
	if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE)))
		mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
#endif

	wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
	werase(stdscr);
	wrefresh(stdscr);

#ifdef SIGWINCH
	org_winch_handler = signal(SIGWINCH, sighandler);
#endif
	signal(SIGCHLD, sighandler);
	signal(SIGINT, sighandler);
	signal(SIGPIPE, SIG_IGN);

	g_type_init();

	init_wm();

	clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL);
}
Exemple #28
0
int main(int argc, char *argv[])
{
    initscr();
    cbreak();
    noecho();
    start_color();
    mousemask(BUTTON1_CLICKED, NULL);
    mouseinterval(0);

    init_pair(0, COLOR_WHITE, COLOR_BLACK);
    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_BLUE, COLOR_BLACK);

    int          x,y;
    int          ch      = 0;
    square       turn    = GUMA;
    bool         winner  = false;
    WINDOW*      win_big = newwin(N+2, N+2, 1, 0);
    WINDOW*      win     = derwin(win_big, N, N, 1, 1);
    Board_curses b(win);
    MEVENT       event;
    keypad(win, 1);
    box(win_big, 0, 0);
    curPlayer(turn);
    refresh();
    wrefresh(win_big);
    b.print();
    wmove(win, 0, 0);
    while(!winner)
    {
        bool restart_loop = false;
        bool mouse        = false;
        while (!mouse && (ch = wgetch(win)) != '\n')
        {
            getyx(win, y, x);
            switch (ch)
            {
                case KEY_UP:
                    if (y > 0)
                        wmove(win, --y, x);
                    break;
                case KEY_DOWN:
                    if (y < N-1)
                        wmove(win, ++y, x);
                    break;
                case KEY_LEFT:
                    if (x > 0)
                        wmove(win, y, --x);
                    break;
                case KEY_RIGHT:
                    if (x < N-1)
                        wmove(win, y, ++x);
                    break;
                case KEY_MOUSE:
                    if (getmouse(&event) == OK && ( event.bstate & BUTTON1_CLICKED ) )
                    {
                        event.x -= 1;
                        event.y -= 2;
                        if( event.x <  N &&
                            event.x >= 0 &&
                            event.y <  N &&
                            event.y >= 0 )
                        {
                            wmove(win, event.y, event.x);
                            mouse = true;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        getyx(win, y, x);
        
        try
        {
            winner = b.move(turn, x, y);
        }
        catch (square_occupied)
        {
            restart_loop = true;
        }
        if (!restart_loop)
        {
            if (!winner)
            {
                if (turn == GUMA)
                    turn = BATON;
                else
                    turn = GUMA;
            }
            b.print();
            curPlayer(turn);
            refresh();
            wmove(win, y, x);
        }
    }

    endwin();
    
    if (turn == GUMA)
        puts("Red player is a winrar");
    else
        puts("Blue player is a winrar");
    return 0;
}
Exemple #29
0
int print_it ( ppstat *stats_array, int count )
{
	int input;
	int i, j;
	time_t uptime;
	time_t t;
	struct tm *now;
	char timestring[9];
	extern pmstat memory;
	double	total_ticks;
	MEVENT event;

	output = &printw;

	mousemask(ALL_MOUSE_EVENTS, NULL);
	total_ticks = parametres.ticks_passed * sysconf ( _SC_NPROCESSORS_ONLN );
	keypad ( win, TRUE );
	erase();

	t = time ( NULL );
	now = localtime ( &t );
	strftime ( timestring, 9, "%H:%M:%S", now );
	
	uptime = time ( NULL ) - parametres.btime;

	attroff ( A_BOLD );

	mvprintw ( 0, 0, "%-6s - %s  up %ld days %02ld:%02ld",
		parametres.progname,
		timestring,
		uptime / 86400,
		( uptime % 86400 ) / 3600,
		( uptime % 3600 ) / 60
		);
	mvprintw ( 0, 41, "load average: %7.2f %7.2f %7.2f",
		parametres.loadavg[0],
		parametres.loadavg[1],
		parametres.loadavg[2]
		);

	if ( parametres.cpu_stats[1].user != 0 )
	{
		mvprintw ( 2, 0, "Cpu(s):%5.1f us,%5.1f sy,%5.1f ni,%5.1f id,%5.1f wa,%5.1f hi,%5.1f si,%5.1f st",
		((parametres.cpu_stats[0].user - parametres.cpu_stats[1].user)/total_ticks) * 100,
	 	((parametres.cpu_stats[0].system - parametres.cpu_stats[1].system)/total_ticks) * 100,
		((parametres.cpu_stats[0].nice - parametres.cpu_stats[1].nice)/total_ticks) * 100 ,
		((parametres.cpu_stats[0].idle - parametres.cpu_stats[1].idle)/total_ticks) * 100 ,
		((parametres.cpu_stats[0].iowait - parametres.cpu_stats[1].iowait)/total_ticks) * 100,
		((parametres.cpu_stats[0].irq - parametres.cpu_stats[1].irq)/total_ticks) * 100,
		((parametres.cpu_stats[0].softirq - parametres.cpu_stats[1].softirq)/total_ticks) * 100,
		((parametres.cpu_stats[0].steal - parametres.cpu_stats[1].steal)/total_ticks) * 100 );
	}
	else
	{
		mvprintw ( 2, 0, "Cpu(s):%5.1f us,%5.1f sy,%5.1f ni,%5.1f id,%5.1f wa,%5.1f hi,%5.1f si,%5.1f st", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
	}
	if ( memory->memtotal > 1000000000 )
	{
		mvprintw ( 3, 0, "MiB Mem:%10lu total, %10lu used, %10lu free, %10lu buffers",
			memory->memtotal / 1024,
			( memory->memtotal - memory->memfree ) / 1024,
			memory->memfree / 1024,
			memory->buffers / 1024
		);
		mvprintw ( 4, 0, "MiB Swap:%9lu total, %10lu used, %10lu free, %10lu cached",
			memory->swaptotal / 1024,
			( memory->swaptotal - memory->swapfree ) / 1024,
			memory->swapfree / 1024,
			memory->cached / 1024
		);
	}
	else
	{
		mvprintw ( 3, 0, "KiB Mem:%10lu total, %10lu used, %10lu free, %10lu buffers",
			memory->memtotal,
			memory->memtotal - memory->memfree,
			memory->memfree,
			memory->buffers
		);
		mvprintw ( 4, 0, "KiB Swap:%9lu total, %10lu used, %10lu free, %10lu cached",
			memory->swaptotal,
			memory->swaptotal - memory->swapfree,
			memory->swapfree,
			memory->cached
		);
	}
	mvprintw ( 5, 0, "JKUtop - horrovac invenit et fecit" );
	attron ( A_REVERSE );
	/*
	print the header
	*/
	move ( 6, 0 );
	for ( j = 0; j < FIELDS_AVAILABLE; j++ )
	{
		attroff ( A_BOLD );
		if ( display_fields[j] == NULL )
		{
			break;
		}
		if ( display_fields[j]->identifier == parametres.sortby )
		{
			attron ( A_BOLD );
		}
		printw ( display_fields[j]->header_format, display_fields[j]->fieldname );
	}
	for ( i = 67; i < col; i++ )
	{
		printw ( " " );
	}
	printw ( "\n" );
	attroff ( A_REVERSE );

	/*
	print the data fields
	*/
	for ( i = 0; i < count; i++ )
	{
		move ( i + 7, 0 );
		{
			if ( stats_array[i]->state == 'R' )
			{
			attron ( A_BOLD );
			}
			else
			{
				attroff ( A_BOLD );
			}
			for ( j = 0; j < FIELDS_AVAILABLE; j++ )
			{
				if ( display_fields[j] == NULL )
				{
					break;
				}
				display_fields[j]->printout( stats_array[i], display_fields[j]->identifier );
			}
			printw ( "\n" );

		}
		/* limit output to visible rows */
		if ( i + 8 >= row )
		{
			break;
		}
	}
	refresh();
	if ( ( input = getch () ) != ERR )
	{
		switch ( input )
		{
			case 'w':		/* save current configuration */
				save_config();
				break;
			case 'q':
				endwin();
				exit ( 0 );
				break;
			case 'o':
			case 'O':
			case 's':
			case 'S':
			case 'f':
			case 'F':
				modify_display();
				break;
			case KEY_MOUSE:
				if(getmouse(&event) == OK)
				{
					if ( event.bstate & BUTTON1_DOUBLE_CLICKED )
					{
						if ( event.y > 6 )
						{
							show_process_detail ( stats_array, event.y - 7 );
						}
						else if ( event.y == 6 )
						{
							mouse_select_sortfield ( event.x );
						}
					}
				}
				break;
			case 'h':
				show_help ();
				break;
			default:
				break;
		}
	}
	return ( i + 1 );
}
Exemple #30
0
void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space)
{
  list_part_t *list_part;
#ifdef HAVE_NCURSES
  list_part_t *current_element;
  unsigned int current_element_num;
  int done=0;
  int command;
  unsigned int offset=0;
  unsigned int menu=0;
  static const struct MenuItem menuMain[]=
  {
	{'S',"Search","Start file recovery"},
	{'O',"Options","Modify options"},
	{'F',"File Opt","Modify file options"},
	{'G',"Geometry", "Change disk geometry" },
	{'Q',"Quit","Return to disk selection"},
	{0,NULL,NULL}
  };
#endif
  params->blocksize=0;
  list_part=init_list_part(params->disk, options);
  if(list_part==NULL)
    return;
  log_all_partitions(params->disk, list_part);
  if(params->cmd_run!=NULL)
  {
    if(menu_photorec_cli(list_part, params, options, list_search_space) > 0)
    {
      if(params->recup_dir==NULL)
      {
	char *res;
#ifdef HAVE_NCURSES
	res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
#else
	res=get_default_location();
#endif
	if(res!=NULL)
	{
	  params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
	  strcpy(params->recup_dir,res);
	  strcat(params->recup_dir,"/");
	  strcat(params->recup_dir,DEFAULT_RECUP_DIR);
	  free(res);
	}
      }
      if(params->recup_dir!=NULL)
	photorec(params, options, list_search_space);
    }
  }
  if(params->cmd_run!=NULL)
  {
    part_free_list(list_part);
    return;
  }
#ifdef HAVE_NCURSES
  if(list_part->next!=NULL)
  {
    current_element_num=1;
    current_element=list_part->next;
  }
  else
  {
    current_element_num=0;
    current_element=list_part;
  }
  while(done==0)
  { /* ncurses interface */
    list_part_t *element;
    unsigned int i;
    aff_copy(stdscr);
    wmove(stdscr,4,0);
    wprintw(stdscr,"%s",params->disk->description_short(params->disk));
    mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    mousemask(ALL_MOUSE_EVENTS, NULL);
#endif
    for(i=0,element=list_part; element!=NULL && i<offset+INTER_SELECT;element=element->next,i++)
    {
      if(i<offset)
	continue;
      wmove(stdscr,7+i-offset,0);
      wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
      if(element==current_element)
      {
	wattrset(stdscr, A_REVERSE);
	waddstr(stdscr, ">");
	aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
	wattroff(stdscr, A_REVERSE);
      } else
      {
	waddstr(stdscr, " ");
	aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
      }
    }
    wmove(stdscr,7+INTER_SELECT,5);
    wclrtoeol(stdscr);
    if(element!=NULL)
      wprintw(stdscr, "Next");
    command = wmenuSelect(stdscr, INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8,
	(options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    if(command == KEY_MOUSE)
    {
      MEVENT event;
      if(getmouse(&event) == OK)
      {	/* When the user clicks left mouse button */
	if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED))
	{
	  if(event.y >=7 && event.y<7+INTER_SELECT)
	  {
	    /* Disk selection */
	    while(current_element_num > event.y-(7-offset) && current_element->prev!=NULL)
	    {
	      current_element=current_element->prev;
	      current_element_num--;
	    }
	    while(current_element_num < event.y-(7-offset) && current_element->next!=NULL)
	    {
	      current_element=current_element->next;
	      current_element_num++;
	    }
	    if(event.bstate & BUTTON1_DOUBLE_CLICKED)
	      command='S';
	  }
	  else
	    command = menu_to_command(INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8,
		(options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, event.y, event.x);
	}
      }
    }
#endif
    switch(command)
    {
      case KEY_UP:
	if(current_element!=NULL && current_element->prev!=NULL)
	{
	  current_element=current_element->prev;
	  current_element_num--;
	}
	break;
      case KEY_PPAGE:
	for(i=0; (signed)i<INTER_SELECT && current_element->prev!=NULL; i++)
	{
	  current_element=current_element->prev;
	  current_element_num--;
	}
	break;
      case KEY_DOWN:
	if(current_element->next!=NULL)
	{
	  current_element=current_element->next;
	  current_element_num++;
	}
	break;
      case KEY_NPAGE:
	for(i=0; (signed)i<INTER_SELECT && current_element->next!=NULL; i++)
	{
	  current_element=current_element->next;
	  current_element_num++;
	}
	break;
      case 's':
      case 'S':
	if(current_element!=NULL)
	{
	  params->partition=current_element->part;
	  ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, &params->carve_free_space_only);
	  menu=0;
	  if(params->recup_dir==NULL)
	  {
	    char *res;
	    res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
	    if(res!=NULL)
	    {
	      params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
	      strcpy(params->recup_dir,res);
	      strcat(params->recup_dir,"/");
	      strcat(params->recup_dir,DEFAULT_RECUP_DIR);
	      free(res);
	    }
	  }
	  if(params->recup_dir!=NULL)
	  {
	    if(td_list_empty(&list_search_space->list))
	    {
	      init_search_space(list_search_space, params->disk, params->partition);
	    }
	    if(params->carve_free_space_only>0)
	    {
	      aff_copy(stdscr);
	      wmove(stdscr,5,0);
	      wprintw(stdscr, "Filesystem analysis, please wait...\n");
	      wrefresh(stdscr);
	      params->blocksize=remove_used_space(params->disk, params->partition, list_search_space);
	      /* Only free space is carved, list_search_space is modified.
	       * To carve the whole space, need to quit and reselect the params->partition */
	      done = 1;
	    }
	    photorec(params, options, list_search_space);
	  }
	}
	break;
      case 'o':
      case 'O':
	{
	  interface_options_photorec_ncurses(options);
	  menu=1;
	}
	break;
      case 'f':
      case 'F':
	interface_file_select_ncurses(options->list_file_format);
	menu=2;
	break;
      case 'g':
      case 'G':
	if(options->expert!=0)
	  if(change_geometry_ncurses(params->disk))
	    done=1;
	break;
      case 'a':
      case 'A':
	if(params->disk->arch != &arch_none)
	{
	  list_part=add_partition_ncurses(params->disk, list_part);
	  current_element=list_part;
	  current_element_num=0;
	}
	break;
      case 'q':
      case 'Q':
	done = 1;
	break;
    }
    if(current_element_num<offset)
      offset=current_element_num;
    if(current_element_num>=offset+INTER_SELECT)
      offset=current_element_num-INTER_SELECT+1;
  }
#endif
  log_info("\n");
  part_free_list(list_part);
}