Beispiel #1
0
/*-----------------------------------------------------------------------------------*/
void
console_init(void)
{
  /* mouse support is ncurses-specific */
#ifdef NCURSES_MOUSE_VERSION
  mmask_t oldmask;
#endif
  static unsigned char done;
  int bg, fg;

  if(done) {
    return;
  }
  done = 1;

  initscr();
  start_color();
  cbreak();

  /* don't echo typed characters */
  noecho();
  /* disable return -> newline translation */
  nonl();

  /* hide text cursor, CTK draws its own */
  curs_set(0);

  intrflush(stdscr, FALSE);
  keypad(stdscr, TRUE);

#ifdef NCURSES_MOUSE_VERSION
  /* done here because ctk_mouse_init() is called before anyway */
  mousemask(ALL_MOUSE_EVENTS, &oldmask);
#endif

  screensize(&width, &height);

  /* we must declare all possible color pairs */
  for(fg = 0; fg < 8; fg++) {
    for(bg = 0; bg < 8; bg++) {
      init_pair(MKPAIR(bg, fg), fg, bg);
    }
  }

  /* set window title */
  putp("\033]0;Contiki\a");

  /* don't block on read, just timeout 1ms */
  timeout(1);

  /* make sure we return the terminal in a clean state */
  signal(SIGINT, ctrlhandler);
  atexit(console_exit);
}
Beispiel #2
0
static void *curses_open(int argc, char **argv)
{
	initscr();	/* Fullscreen */
	cbreak();	/* Character at a time */
	noecho();	/* No local echo */

	nonl();		/* No newline */
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);

	return stdscr;
}
Beispiel #3
0
void menu_init(void)
{
#ifdef USE_NCURSES
  initscr();
  cbreak();
  noecho();
  nonl();
  intrflush(stdscr, FALSE);
  keypad(stdscr, TRUE);
  menu_initialized = 1;
#endif /* USE_NCURSES */
}
Beispiel #4
0
void
Responder::create_ncurses_window()
{
    _window = initscr();
    cbreak();       // Unbuffered key input, except for signals (cf. 'raw')
    noecho();
    nonl();
    intrflush(_window, FALSE);
    keypad(_window, TRUE);   // Enable function keys, arrow keys, ...
    nodelay(_window, 0);
    timeout(0);
}
Beispiel #5
0
void
initcurses(void)
{
	initscr();
	cbreak();
	noecho();
	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);
	curs_set(FALSE); /* Hide cursor */
	timeout(1000); /* One second */
}
Beispiel #6
0
/* creation - ncurses' window handling */
void
set_input_opts (void)
{
  noecho ();
  halfdelay (10);
  nonl ();
  intrflush (stdscr, FALSE);
  keypad (stdscr, TRUE);
  curs_set (0);

  if (conf.mouse_support)
    mousemask (BUTTON1_CLICKED, NULL);
}
Beispiel #7
0
void curses_loop() {
  initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE);
  nonl();
  intrflush(stdscr, FALSE);

  while(true) {
    int c = getch();
    if(c != ERR) handler(c);
  }
}
Beispiel #8
0
void setupcurses() {
	g_screen = initscr();
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_WHITE, COLOR_RED);
	init_pair(4, COLOR_WHITE, COLOR_GREEN);
	noecho();
	cbreak();
	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);
	curs_set(0);
}
int main () 
{
  int segment_id; 
  data* shared_memory; 
  struct shmid_ds shmbuffer; 
  int segment_size; 
  const int shared_segment_size = 0x6400; 
	int smhkey=33222;

	int ch = 0;

    /* Basic initialization of curses lib */
    initscr();
    cbreak();
    noecho(); /* Set this for interactive programs. */
    nonl();
    intrflush(stdscr, FALSE);
    keypad(stdscr, TRUE);
 
  /* Allocate a shared memory segment.  */ 
  segment_id = shmget (smhkey, shared_segment_size,IPC_CREAT | 0666); 
  /* Attach the shared memory segment.  */ 
  shared_memory = (data*) shmat (segment_id, 0, 0); 
  printf ("shared memory attached at address %p\n", shared_memory); 
  /* Determine the segment's size. */ 
  shmctl (segment_id, IPC_STAT, &shmbuffer); 
  segment_size  =               shmbuffer.shm_segsz; 
  printf ("segment size: %d\n", segment_size); 
  /* Write a string to the shared memory segment.  */ 
int i=0;
while(1)
{
 
    /* Ready to rumble! */
    //printf("Type a key. Use 'q' to quit\n");
    while (ch != 'q')
        ch = getch();
	if (ch != ERR){
           printf("You typed: '%c' which is ASCII %d\n\r", (char) ch, ch);
   	   shared_memory->a=ch;
	   shared_memory->sequence_num=i++;
        }else{
           printf("Waiting for key.");
           shared_memory->a=10;
           shared_memory->sequence_num=i++;

        }

}
} 
Beispiel #10
0
void startup()
{
    setlocale(LC_CTYPE, "");
    win = initscr();
    /* FIXME: is this cast a good idea? */
    atexit((void (*)()) endwin);
    start_color();
    init_pairs();
    cbreak();
    noecho();
    nonl();
    intrflush(win, FALSE);
    meta(win, TRUE);
}
Beispiel #11
0
void CRT_init(int delay, int colorScheme) {
   initscr();
   noecho();
   CRT_delay = delay/2;
   if (CRT_delay == 0) {
      CRT_delay = 1;
   }
   CRT_colorScheme = colorScheme;
   halfdelay(CRT_delay);
   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, "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));
   }
#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);
}
Beispiel #12
0
void initNCurses(string *snakeColor)
{
	/*init ncurses*/
	initscr();

	/* use colours */
	start_color();

	/* get keys as they are pressed */
	cbreak();

	/* don't echo the keys as the are pressed */
	noecho();

	/* prevent flushing on interrupt keys */
	intrflush(stdscr, FALSE);

	/* prevent blocking on getch() */
	nodelay(stdscr, TRUE);

	/* enable keypad (and arrow keys) */
	keypad(stdscr, TRUE);

	/* hide the cursor */
	curs_set(0);

	/* initialize the colours */
	int bodycolor = BODY_COLOR;
	if (snakeColor == NULL) {
		bodycolor = BODY_COLOR;

	} else if (snakeColor->compare("red") == 0) {
		bodycolor = COLOR_RED;
	} else if (snakeColor->compare("green") == 0) {
		bodycolor = COLOR_GREEN;
	} else if (snakeColor->compare("blue") == 0) {
		bodycolor = COLOR_BLUE;
	} else if (snakeColor->compare("white") == 0) {
		bodycolor = COLOR_WHITE;
	} else if (snakeColor->compare("yellow") == 0) {
		bodycolor = COLOR_YELLOW;
	}

	init_color(COLOR_BLUE, 0, 0, 999);
	init_pair(TEXT_COLOR, COLOR_WHITE, COLOR_BLACK); /* wall/text */
	init_pair(BODY_COLOR, bodycolor, COLOR_BLACK); /* body */
	init_pair(FOOD_COLOR, COLOR_GREEN, COLOR_BLACK); /* food */
	init_pair(TEXT_INPUT, COLOR_BLACK, COLOR_WHITE); /* text input */
	init_pair(HEAD_COLOR, COLOR_RED, COLOR_BLACK); /* text input */
}
void Pantalla::startCurses(){
    if (curses_ON) {
        refresh();
    }
    else {
        initscr();
        cbreak();
        noecho();
        intrflush(stdscr, false);
        keypad(stdscr, true);
        atexit(endCurses);
        curses_ON = true;
    }
}
Beispiel #14
0
void start_curses()
{
	if (curses_started) {
		refresh();
	} else {
		initscr();
		cbreak();
		noecho();
		intrflush(stdscr, false);
		keypad(stdscr, true);
		atexit(stop_curses);
		curses_started = true;
	}
}
Beispiel #15
0
void StatFormBase::StartWin()
{
	if(m_bCursesOn)
		return;
	//忽略中止信号
	signal(SIGINT,SIG_IGN);
	initscr();
	noecho();
	intrflush(stdscr,true); 
	keypad(stdscr,TRUE);
	savetty();
	
	m_bCursesOn = true;
}
Beispiel #16
0
/*#DOC*/
int viewG_start()
{
	if (!initscr()) return ERR;
	viewP_cbreak(FALSE);
	signal(SIGWINCH, viewP_sigwinch);
	keypad(stdscr, TRUE);
	intrflush(stdscr, FALSE);
	_stdview._win = stdscr;
	_stdview._pan = NULL;
	TERM_W = getmaxx(stdscr);
	TERM_H = getmaxy(stdscr);
	viewP_initColor();
	return OK;
}
Beispiel #17
0
bool Interface::init() {
    initscr();
    cbreak();
    noecho();
    nonl();
    intrflush(stdscr, FALSE);
    keypad(stdscr, TRUE);

#ifdef WIN32
    SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), 0); // hide mouse cursor
#endif

    if (LINES < 25 || COLS < 80) {
        clear();
        mvaddstr(0, 0, "Error: your console should be at least");
        mvaddstr(1, 0, "25x80 characters to run this game.");
        mvaddstr(3, 0, "Press Q to quit or any other key to try again.");
        move(4, 0);
        
        int key;
        while (true) {
            key = getkey();
            if (key == 'q' || key == 'Q')
                return false;
            if (LINES >= 25 && COLS >= 80)
                break;
        }
    }

    if (!has_colors()) {
        clear();
        mvaddstr(0, 0, "Error: your console doesn't support colors.");
        mvaddstr(2, 0, "Press any key to quit.");
        move(3, 0);
        getkey();
        return false;
    }

    start_color();
    for (int i = 1; i < 64; i++)
        init_pair(i, (i & 7) ^ 7, i >> 3);

    clear();
    refresh();

    msgdisplaylen = 0;

    return true;
}
Beispiel #18
0
void init_ncurses()
{
  // set up ncurses
  setlocale(LC_ALL, "");
  initscr();
  start_color();
  cbreak();
  nodelay(stdscr, TRUE);
  noecho();
  nonl();
  idlok(stdscr, TRUE);
  intrflush(stdscr, FALSE);
  keypad(stdscr, FALSE);
  curs_set(0);
}
Beispiel #19
0
int win_ini(int *fil, int *col, char creq, unsigned int inv)
{
  int p_fil,p_col;
  chtype wc;

  if (hi_ha_win) return(-1);       /* error si ja s'havia creat la finestra */
  if (initscr() == NULL) return(-2);    /* error en iniciar les curses */
  if ((*fil > LINES) || (*col > COLS))    /* error en les mides */
  { endwin();
    return(-3);
  }
  if (*fil == 0) *fil = LINES;	/* cas de mida maxima */
  if (*col == 0) *col = COLS;
  p_fil = (LINES - *fil)/ 2;		/* posicio de la finestra centrada */
  p_col = (COLS - *col) / 2;
                              /* canviar interrupcio de final de proces */
  oldsig = signal(SIGINT,win_fi);
	                     /* configuracio preliminar de les curses */
  cbreak();			/* rep tecles sense buffering */
  noecho();			/* no fa echo de les tecles llegides */
  nonl();			/* el newline \n no es tradueix a CR i LF */
  intrflush(stdscr,FALSE);	/* ^C no s'esborra del buffer d'entrada */
  keypad(stdscr,TRUE);		/* s'activa el teclat numeric i mov. cursor */

  win = newwin(*fil, *col, p_fil, p_col);

  if (win == NULL)            /* error en la creacio de la finestra */
  { endwin();
    return(-4);
  }
  hi_ha_win = TRUE;

  leaveok(win,TRUE);	/* dibuixar en pantalla no modificara el cursor */
  curs_set(0);		/* fixa el cursor com a invisible */
  nodelay(win,TRUE);
  refresh();		/* refresca la pantalla (inicialment l'esborra) */

  ufil = *fil;			/* memoritza numero files */
  ucol = *col;			/* memoritza numero columnes */
  wc = creq;			/* dibuixa el requadre */
  if (inv) wc |= A_REVERSE;
  mvwhline(win,0,0,wc,ucol);		/* fila superior */
  mvwhline(win,ufil-2,0,wc,ucol);	/* fila inferior */
  mvwvline(win,1,0,wc,ufil-2);		/* columna dreta */
  mvwvline(win,1,ucol-1,wc,ufil-2);	/* columna esquerra */
  wrefresh(win);		/* redibuixa el contingut de la finestra */
  return(0);			/* retorna OK */
}
Beispiel #20
0
static void curses_setup(void)
{
    int i, colour_default[8] = {
        COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
        COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE,
    };

    /* input as raw as possible, let everything be interpreted
     * by the guest system */
    initscr(); noecho(); intrflush(stdscr, FALSE);
    nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
    start_color(); raw(); scrollok(stdscr, FALSE);

    for (i = 0; i < 64; i ++)
        init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
}
Beispiel #21
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);
}
Beispiel #22
0
static void curses_uninit(aa_context * c)
{
    wclear(stdscr);
    intrflush(stdscr, TRUE);
#if 0
    nocbreak();
    echo();
    nl();
#endif
    refresh();
    if (uninitcurses) {
	uninitcurses = 0;
	__curses_is_up = 0;
	endwin();
    }
}
Beispiel #23
0
WDL_CursesEditor::WDL_CursesEditor(void *cursesCtx)
{ 
  m_max_undo_states = 500;
  m_indent_size=2;
  m_cursesCtx = cursesCtx;

  m_color_bottomline = COLOR_PAIR(1);
  m_color_statustext = COLOR_PAIR(1);
  m_color_selection = COLOR_PAIR(2);
  m_color_message = COLOR_PAIR(2);

  m_top_margin=0;
  m_bottom_margin=2;

  m_selecting=0;
  m_select_x1=m_select_y1=m_select_x2=m_select_y2=0;
  m_state=0;
  m_offs_x=m_offs_y=0;
  m_curs_x=m_curs_y=0;
  m_want_x=-1;
  m_undoStack_pos=-1;
  m_clean_undopos=0;


#ifdef WDL_IS_FAKE_CURSES
  if (m_cursesCtx)
  {
    CURSES_INSTANCE->user_data = this;
    CURSES_INSTANCE->onMouseMessage = _onMouseMessage;
  }
#endif

  initscr();
  cbreak();
  noecho();
  nonl();
  intrflush(stdscr,FALSE);
  keypad(stdscr,TRUE);
  nodelay(stdscr,TRUE);
  raw(); // disable ctrl+C etc. no way to kill if allow quit isn't defined, yay.
  start_color();
  init_pair(1, COLOR_WHITE, COLOR_BLUE); // normal status lines
  init_pair(2, COLOR_BLACK, COLOR_CYAN); // value

  erase();
  refresh();
}
Beispiel #24
0
Datei: view.c Projekt: bytbox/iv
void view_init() {
    buffer_init(); /* initialize the buffers */
    /* init the actual view */
    initscr(); /* start ncurses */
    start_color(); /* enable the use of color */
    cbreak(); /* don't wait for RETURN or ENTER to get input */
    noecho(); /* don't immediately echo characters */
    nonl(); /* don't display newlines as newlines */
    intrflush(stdscr,0);
    keypad(stdscr,1); /* enable the keypad */
    scrollok(stdscr,0); /* don't scroll off the bottom */
    view_layout.hsplit=0; /* no split */
    view_layout.vsplit=0;
    view_layout.view1=0;
    view_layout.view2=0;
    view_layout.active=0;
}
Beispiel #25
0
void init_curses() {
    initscr();
    start_color();
    use_default_colors();
    init_pair(YELLOW, COLOR_YELLOW, -1);
    init_pair(GREEN, COLOR_GREEN, -1);
    init_pair(RED, COLOR_RED, -1);
    init_pair(BLUE, COLOR_BLUE, -1);
    init_pair(CYAN, COLOR_CYAN, -1);
    init_pair(MAGENTA, COLOR_MAGENTA, -1);
    init_pair(WHITE_BLUE, COLOR_WHITE, COLOR_BLUE);
    cbreak();
    nonl();
    noecho();
    intrflush(stdscr,FALSE);
    refresh();
}
Beispiel #26
0
WINDOW* CursesOut::initWindow() {
    WINDOW *w = initscr();
    start_color();
    use_default_colors();
    nodelay(w, TRUE); // do not block on getch()
    cbreak();
    noecho();
    nonl();
    intrflush(w, FALSE);
    keypad(w, TRUE);
    meta(w, TRUE);
    raw();
    scrollok(w, FALSE);
    erase();
    refresh();
    return w;
}
Beispiel #27
0
void term_init()
{
#ifdef UNIX
#ifdef CURSES
    initscr();
    cbreak();
    noecho();
    nonl();
    intrflush(stdscr, FALSE);
    keypad(stdscr, TRUE);
#else
    system("stty -echo");
    system("stty raw");
#endif
#endif
    term_reset();
}
Beispiel #28
0
void curses_init()
{
    null = g_fopen("/dev/null", "w");
    unsetenv("COLUMNS");
    unsetenv("LINES");
    initscr();
    noecho();
    nonl();
    cbreak();
    keypad(stdscr, TRUE);
    meta(stdscr, TRUE);
    intrflush(stdscr, FALSE);
    leaveok(stdscr, TRUE);

    if (has_colors())
    {
        start_color();
        use_default_colors();
        init_pair(COLORPAIR, conf.fg, conf.bg);
    }
    else
        conf.color = FALSE;

    curs_set(false);

    ws = newwin(1, COLS, EL, 0);

    view.current = 0;
    view.top_x   = 0;
    view.top_y   = 0;

    prompt.buf   = g_string_new("");
    prompt.on    = false;
    prompt.regex = NULL;

    grid = g_array_sized_new(FALSE, TRUE, sizeof(grid_line_t*), SL);
    for (glong i = 0; i < SL; i++)
    {
        grid_line_t* grid_line = g_malloc(sizeof(grid_line_t));
        g_array_append_val(grid, grid_line);
    }

    regrid();
}
Beispiel #29
0
/**
 * Initialize the used windows
 */
static void init_windows(void)
{
    extern nyancat_t nc;

    initscr();
    init_colors();
    cbreak();       /* line buffering disabled, pass on everty thing to me */
    noecho();       /* don't print typed chars */
    curs_set(0);    /* don't show a carret */
    keypad(stdscr, TRUE);
    intrflush(stdscr, FALSE);

    /* create sub windows */
    nc.ui.world = newwin(SCREENHEIGHT, SCREENWIDTH, 0, 0);
    nc.ui.status = newwin(1, SCREENWIDTH, SCREENHEIGHT, 0);
#ifdef DEBUG
    nc.ui.debug = newwin(5, SCREENWIDTH, SCREENHEIGHT + 1, 0);
#endif
}
Beispiel #30
0
void tui_setup(void)
{
    int i;

    for (i = 0; i < 10; i++)
	winstack[i] = NULL;
    /* From the ncurses manpage... */
    initscr (); start_color (); cbreak(); noecho(); nonl (); intrflush (stdscr, FALSE); keypad (stdscr, TRUE);
    currwin = stdscr;
    if (has_colors ()) {
	init_pair (1, COLOR_WHITE, COLOR_BLUE);
	init_pair (2, COLOR_BLACK, COLOR_WHITE);
	wattron (currwin, COLOR_PAIR (1) | A_BOLD);
	wbkgd (currwin, ' ' | COLOR_PAIR (1));
    }

    winstack[0] = stdscr;
    winnr = 1;
}