예제 #1
0
파일: core.c 프로젝트: jesseadams/profanity
void
ui_init(void)
{
    log_info("Initialising UI");
    initscr();
    raw();
    keypad(stdscr, TRUE);
    if (prefs_get_boolean(PREF_MOUSE)) {
        mousemask(ALL_MOUSE_EVENTS, NULL);
        mouseinterval(5);
    }
    ui_load_colours();
    refresh();
    create_title_bar();
    create_status_bar();
    status_bar_active(1);
    create_input_window();
    wins_init();
    cons_about();
    notifier_init();
#ifdef HAVE_LIBXSS
    display = XOpenDisplay(0);
#endif
    ui_idle_time = g_timer_new();
    wins_refresh_current();
}
예제 #2
0
파일: term.c 프로젝트: AlexMooney/Brogue
static int curses_init( ) {
	if (videomode.curses) return 0;
	
	// isterm?
	initscr( );
	if (!has_colors( )) {
		endwin( );
		fprintf (stderr, "Your terminal has no color support.\n");
		return 1;
	}

	start_color( );
	clear( );
	curs_set( 0 );
	refresh( );
	leaveok(stdscr, TRUE);
	preparecolor( );
	cbreak( );
	noecho( );

	nodelay(stdscr, TRUE);
	meta(stdscr, TRUE);
	keypad(stdscr, TRUE);

	mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED | REPORT_MOUSE_POSITION | BUTTON_SHIFT | BUTTON_CTRL, NULL);
	mouseinterval(0); //do no click processing, thank you
	
	videomode.curses = 1;

	getmaxyx(stdscr, Term.height, Term.width);

	return 1;
}
예제 #3
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
		
		if (halfdelay(5) == ERR) { // Timeout after 5/10 of a second
			std::cout << "WARNING: Unable to set terminal blocking half delay to 0.5s!\n";
			std::cout << "\tThis will increase CPU usage in the command thread.\n";
			if (nodelay(input_window, true) == ERR) { //Disable the blocking timeout.
				std::cout << "ERROR: Unable to remove terminal blocking!\n";
				std::cout << "\tThe command thread will be locked until a character is entered. This will reduce functionality of terminal status bar and timeout.\n";
			}
		}
		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;
		offset = 0;
		
		// Set the position of the physical cursor
		cursX = 0; cursY = _winSizeY-1;
		update_cursor_();
		refresh_();

		init_colors_();
	}
	
	setup_signal_handlers();
}
예제 #4
0
int curs_initciolib(long inmode)
{
	short	fg, bg, pair=0;

#ifdef XCURSES
	char	*argv[2]={"ciolib",NULL};

	Xinitscr(1,argv);
#else
	char *term;
	SCREEN *tst;

	term=getenv("TERM");
	if(term==NULL)
		return(0);
	tst=newterm(term,stdout,stdin);
	if(tst==NULL)
		return(0);
	endwin();
	initscr();
#endif
	start_color();
	cbreak();
	noecho();
	nonl();
	keypad(stdscr, TRUE);
	scrollok(stdscr,FALSE);
	halfdelay(1);
	raw();
	timeout(10);
	atexit(curs_suspend);

	/* Set up color pairs */
	for(bg=0;bg<8;bg++)  {
		for(fg=0;fg<8;fg++) {
			init_pair(++pair,curses_color(fg),curses_color(bg));
		}
	}
	mode = inmode;
#ifdef NCURSES_VERSION_MAJOR
		if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION)) {
			mouseinterval(0);
			cio_api.mouse=1;
		}
		else
			mousemask(0,NULL);
#endif

	curs_textmode(0);
	return(1);
}
예제 #5
0
void lynx_enable_mouse( int state )
{
  static int was;
  if ( LYUseMouse )
  {
    if ( state )
    {
      if ( was == 0 )
      {
        int old = mouseinterval( -1 );
        was++;
        if ( old <= 199 )
          mouseinterval( 300 );
      }
      mousemask( 84013535, 0 );
    }
    else
    {
      mousemask( 0, 0 );
    }
  }
  return;
}
예제 #6
0
파일: uiview.c 프로젝트: d99kris/namp
/* ----------- 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;
}
예제 #7
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;
}
예제 #8
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();
}
예제 #9
0
파일: main.c 프로젝트: lnslbrty/gameoflife
/* 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;
}
예제 #10
0
파일: CRT.c 프로젝트: EliteTK/htop
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

}
예제 #11
0
파일: ncconsole.c 프로젝트: rofl0r/concol
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);
}
예제 #12
0
파일: main.cpp 프로젝트: Vifon/PW-Gomoku
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;
}
예제 #13
0
파일: display.c 프로젝트: zhez/tig
void
init_display(void)
{
	const char *term;
	int x, y;

	die_callback = done_display;
	/* XXX: Restore tty modes and let the OS cleanup the rest! */
	if (atexit(done_display))
		die("Failed to register done_display");

	/* Initialize the curses library */
	if (isatty(STDIN_FILENO)) {
		cursed = !!initscr();
		opt_tty = stdin;
	} else {
		/* Leave stdin and stdout alone when acting as a pager. */
		opt_tty = fopen("/dev/tty", "r+");
		if (!opt_tty)
			die("Failed to open /dev/tty");
		cursed = !!newterm(NULL, opt_tty, opt_tty);
	}

	if (!cursed)
		die("Failed to initialize curses");

	nonl();		/* Disable conversion and detect newlines from input. */
	cbreak();       /* Take input chars one at a time, no wait for \n */
	noecho();       /* Don't echo input */
	leaveok(stdscr, FALSE);

	if (has_colors())
		init_colors();

	getmaxyx(stdscr, y, x);
	status_win = newwin(1, x, y - 1, 0);
	if (!status_win)
		die("Failed to create status window");

	/* Enable keyboard mapping */
	keypad(status_win, TRUE);
	wbkgdset(status_win, get_line_attr(NULL, LINE_STATUS));
#ifdef NCURSES_MOUSE_VERSION
	/* Enable mouse */
	if (opt_mouse){
		mousemask(ALL_MOUSE_EVENTS, NULL);
		mouseinterval(0);
	}
#endif

#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119)
	set_tabsize(opt_tab_size);
#else
	TABSIZE = opt_tab_size;
#endif

	term = getenv("XTERM_VERSION") ? NULL : getenv("COLORTERM");
	if (term && !strcmp(term, "gnome-terminal")) {
		/* In the gnome-terminal-emulator, the message from
		 * scrolling up one line when impossible followed by
		 * scrolling down one line causes corruption of the
		 * status line. This is fixed by calling wclear. */
		use_scroll_status_wclear = TRUE;
		use_scroll_redrawwin = FALSE;

	} else if (term && !strcmp(term, "xrvt-xpm")) {
		/* No problems with full optimizations in xrvt-(unicode)
		 * and aterm. */
		use_scroll_status_wclear = use_scroll_redrawwin = FALSE;

	} else {
		/* When scrolling in (u)xterm the last line in the
		 * scrolling direction will update slowly. */
		use_scroll_redrawwin = TRUE;
		use_scroll_status_wclear = FALSE;
	}
}
예제 #14
0
파일: ncurses.c 프로젝트: mwgoldsmith/caca
static int ncurses_init_graphics(caca_display_t *dp)
{
    static int curses_colors[] =
    {
        /* Standard curses colours */
        COLOR_BLACK,
        COLOR_BLUE,
        COLOR_GREEN,
        COLOR_CYAN,
        COLOR_RED,
        COLOR_MAGENTA,
        COLOR_YELLOW,
        COLOR_WHITE,
        /* Extra values for xterm-16color */
        COLOR_BLACK + 8,
        COLOR_BLUE + 8,
        COLOR_GREEN + 8,
        COLOR_CYAN + 8,
        COLOR_RED + 8,
        COLOR_MAGENTA + 8,
        COLOR_YELLOW + 8,
        COLOR_WHITE + 8
    };

    mmask_t newmask;
    int fg, bg, max;

    dp->drv.p = malloc(sizeof(struct driver_private));

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

#if defined HAVE_SIGNAL
    sigwinch_d = dp;
    signal(SIGWINCH, sigwinch_handler);
#endif

#if defined HAVE_LOCALE_H
    setlocale(LC_ALL, "");
#endif

    _caca_set_term_title("caca for ncurses");

    initscr();
    keypad(stdscr, TRUE);
    nonl();
    raw();
    noecho();
    nodelay(stdscr, TRUE);
    curs_set(0);

    /* Activate mouse */
    newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
    mousemask(newmask, &dp->drv.p->oldmask);
    mouseinterval(-1); /* No click emulation */

    /* Set the escape delay to a ridiculously low value */
    ESCDELAY = 10;

    /* Activate colour */
    start_color();

    /* If COLORS == 16, it means the terminal supports full bright colours
     * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
     * we can build 16*16 colour pairs.
     * If COLORS == 8, it means the terminal does not know about bright
     * colours and we need to get them through A_BOLD and A_BLINK (\e[1m
     * and \e[5m). We can only build 8*8 colour pairs. */
    max = COLORS >= 16 ? 16 : 8;

    for(bg = 0; bg < max; bg++)
        for(fg = 0; fg < max; fg++)
        {
            /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
             * is light gray on black. Some terminals don't like this
             * colour pair to be redefined. */
            int col = ((max + 7 - fg) % max) + max * bg;
            init_pair(col, curses_colors[fg], curses_colors[bg]);
            dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);

            if(max == 8)
            {
                /* Bright fg on simple bg */
                dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
                /* Simple fg on bright bg */
                dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
                                                    | COLOR_PAIR(col);
                /* Bright fg on bright bg */
                dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
                                                        | COLOR_PAIR(col);
            }
        }

    caca_add_dirty_rect(dp->cv, 0, 0, dp->cv->width, dp->cv->height);
    dp->resize.allow = 1;
    caca_set_canvas_size(dp->cv, COLS, LINES);
    dp->resize.allow = 0;

    return 0;
}