Beispiel #1
0
  int todo_edit::print() const {
    // do not need to do anything if not visible
    if(!m_visible) return 0;

    int row_count = 0;
    std::string str = m_prefix + m_text + " ";
    const int size_x = m_end.scr_x - m_pos.scr_x - 1;

    unsigned int actual_cursor_pos = m_cursor_pos + m_prefix.length() + 1;
    int start_pos = ((int)actual_cursor_pos - size_x) > 0 ?
      ((int)actual_cursor_pos - size_x) : 0;

    // clear line TODO check for better way!
    move(m_pos.scr_y, m_pos.scr_x);
    for(int l = 0; l < size_x; l++)
      addch(' ');

    mvaddnstr(m_pos.scr_y, m_pos.scr_x, str.c_str() + start_pos, size_x);
    str = m_prefix + m_text.substr(0, m_cursor_pos);
    mvaddnstr(m_pos.scr_y, m_pos.scr_x, str.c_str() + start_pos, size_x);
    row_count = 1;
    refresh();
    curs_set(1);
    return row_count;
  }
Beispiel #2
0
void sparkle_pause(void)
{
	static const char *str = "*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    ";
	unsigned a, b;

	attrset(A_FG_COLOR(COLOR_RED) | A_BG_COLOR(COLOR_BLACK));

	do {
		for (a = 0; a < 5; a++) {
			mvaddnstr(0, 0, str + a, 80);
			mvaddnstr(21, 0, str + (4 - a), 80);

			for (b = 1; b < 21; b++) {
				if ((a + b + 2) % 5 == 1) {
					mvaddch(b, 79, MAKE_CHARACTER('*', COLOR_RED, COLOR_BLACK));
					mvaddch(21 - b, 0, MAKE_CHARACTER('*', COLOR_RED, COLOR_BLACK));
				} else {
					mvaddch(b, 79, MAKE_CHARACTER(0, COLOR_BLACK, COLOR_BLACK));
					mvaddch(21 - b, 0, MAKE_CHARACTER(0, COLOR_BLACK, COLOR_BLACK));
				}
			}

			if (keyboard_get_key() != -1) {
				return;
			}

			usleep(150 * 1000);
		}
	} while (1);
}
Beispiel #3
0
void sinsp_cursesui::draw_bottom_menu(vector<sinsp_menuitem_info>* items, bool istable)
{
	uint32_t j = 0;
	uint32_t k = 0;

	//
	// Clear the line
	//
	move(m_screenh - 1, 0);
	for(uint32_t j = 0; j < m_screenw; j++)
	{
		addch(' ');
	}

	m_mouse_to_key_list.clear();

	for(j = 0; j < items->size(); j++)
	{
		if(istable && ((items->at(j).m_type & sinsp_menuitem_info::TABLE) == 0))
		{
			continue;
		}

		if((!istable) && ((items->at(j).m_type & sinsp_menuitem_info::LIST) == 0))
		{
			continue;
		}

		uint32_t startx = k;

		attrset(m_colors[PROCESS]);
		string fks = items->at(j).m_key;
		mvaddnstr(m_screenh - 1, k, fks.c_str(), MAX(fks.size(), 2));
		k += MAX(fks.size(), 2);

		attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
		fks = items->at(j).m_desc;
		
		if(fks.size() < 6)
		{
			fks.resize(6, ' ');
		}
		
		mvaddnstr(m_screenh - 1, k, fks.c_str(), fks.size());
		k += fks.size();
		
		m_mouse_to_key_list.add(sinsp_mouse_to_key_list_entry(startx,
			m_screenh - 1,
			k - 1,
			m_screenh - 1,
			items->at(j).m_keyboard_equivalent));
	}
}
void WDL_CursesEditor::draw_status_state()
{
  int paney[2], paneh[2];
  const int pane_divy=GetPaneDims(paney, paneh);

  attrset(m_color_statustext);
  bkgdset(m_color_statustext);

  int line=LINES-1;
  const char* whichpane="";
  if (m_pane_div > 0.0 && m_pane_div < 1.0)
  {
    whichpane=(!m_curpane ? "Upper pane: " : "Lower pane: ");
    line=m_top_margin+pane_divy;
    move(line, 0);
    clrtoeol();
  }

  char str[512];
  snprintf(str, sizeof(str), "%sLine %d/%d, Col %d [%s]%s",
    whichpane, m_curs_y+1, m_text.GetSize(), m_curs_x, 
    (s_overwrite ? "OVR" : "INS"), (m_clean_undopos == m_undoStack_pos ? "" : "*"));
  int len=strlen(str);
  int x=COLS-len-1;
  mvaddnstr(line, x, str, len);
  clrtoeol();

  attrset(0);
  bkgdset(0);  

  const int col=m_curs_x-m_offs_x;
  line=m_curs_y+paney[m_curpane]-m_paneoffs_y[m_curpane];
  if (line >= paney[m_curpane] && line < paney[m_curpane]+paneh[m_curpane]) move(line, col);
}
Beispiel #5
0
void
list_headerline()
{
	struct index_elem *e;
	int x_pos = 1, width;
	char *str = NULL;

#if defined(A_BOLD) && defined(A_NORMAL)
	attrset(A_BOLD);
#endif

	for(e = index_elements; e; e = e->next)
		if(e->type == INDEX_TEXT)
			x_pos += strwidth(e->d.text);
		else if(e->type == INDEX_FIELD) {
			get_field_info(e->d.field.id, NULL, &str, NULL);
			width = e->d.field.len ?
				abs(e->d.field.len) : strwidth(str);
			if(width + x_pos > COLS)
				width = bytes2width(str, COLS - x_pos);
			mvaddnstr(2, x_pos, str, width);
			x_pos += width;
		} else
			assert(0);

#if defined(A_BOLD) && defined(A_NORMAL)
	attrset(A_NORMAL);
#endif
}
Beispiel #6
0
/* Temporarily display some text and wait for a keypress.
 */
static int runtextdisplay(char const *title, char const *lines[])
{
    char const *line;
    int y, i, n;

    erase();
    mvaddstr(0, xDice + 4, title);
    y = 2;
    for (i = 0 ; lines[i] ; ++i) {
	line = lines[i];
	while (*line) {
	    n = textbreak(&line, 72);
	    mvaddnstr(y, 4, line, n);
	    ++y;
	    line += n;
	}
    }
    move(cyScreen - 1, 0);
    refresh();

    for (;;) {
	switch (getch()) {
	  case '\003':
	  case '\030':
	    return 0;
	  default:
	    render();
	    return 1;
	}
    }
}
Beispiel #7
0
/*
 * High speed screen update.  row and col are 1-based.
 */
void
putline(int row, int col, const char *buf)
{
  int actual_row, actual_col;

  get_actual_pos (row - 1, col - 1, &actual_row, &actual_col);
  mvaddnstr(actual_row, actual_col, buf, ncol - col + 1);
}
Beispiel #8
0
static int my_mvaddstr(int y, int x, const char *str)
{
    int i = 0;

    for ( ; x < 0; ++x, ++i)
	if (str[i] == '\0')  return ERR;
    if (mvaddnstr(y, x, &str[i], (int)COLS - x) == ERR) return ERR;
    return OK;
}
Beispiel #9
0
void DrawBoardFrame(void)
{
	int y;

	for(y = 0; y < BOARD_HEIGHT+2*BOARD_BORDER; y++) {
		mvaddnstr(y+BOARD_TOP, BOARD_LEFT, (const char *)&initialScreen[(BOARD_WIDTH+2)*y], BOARD_WIDTH+2);
	}
	mvaddstr(y+BOARD_TOP, BOARD_LEFT, "Score");
	PrintScore(0);
}
Beispiel #10
0
  int todo_multiline_edit::print() const {
    // do not need to do anything if not visible
    if(!m_visible) return 0;

    int row_count = 0;
    std::string str = m_text + " ";
    const int size_x = m_end.scr_x - m_pos.scr_x - 1;

    row_count = str.length() / size_x + 1;
    for(int l = 0; l < row_count; l++)
      mvaddnstr(m_pos.scr_y + l, m_pos.scr_x, str.c_str() + (l * size_x), size_x);
    unsigned int cursor_row_pos = m_cursor_pos / size_x;
    unsigned int cursor_col_pos = m_cursor_pos % size_x;
    mvaddnstr(m_pos.scr_y + cursor_row_pos, m_pos.scr_x,
        str.c_str() + (cursor_row_pos * size_x), cursor_col_pos);
    refresh();
    curs_set(1);
    return row_count;
  }
Beispiel #11
0
void do_mvaddstr(state *st) {
  int arity;
  long strlen, y, x;
  ei_decode_tuple_header(st->args, &(st->index), &arity);
  ei_decode_long(st->args, &(st->index), &y);
  ei_decode_long(st->args, &(st->index), &x);
  ei_decode_long(st->args, &(st->index), &strlen);
  char str[strlen];
  ei_decode_string(st->args, &(st->index), str);
  encode_ok_reply(st, mvaddnstr((int)y, (int)x, str, (int)strlen));
}
Beispiel #12
0
void PrintBoard(char *data)
{
	int i, y;

	y = BOARD_HEIGHT + 2;
	for(i = 0; i < BOARD_HEIGHT; i++) {
		mvaddnstr(y, BOARD_LEFT+BOARD_BORDER, &data[(BOARD_WIDTH)*i], BOARD_WIDTH);
		y--;
	}

	move(0, 0);
}
int
window_new_identity_print ()
{
  int y, x;
  char buf[250];

  curseson ();
  cbreak ();
  noecho ();
  nonl ();
  keypad (stdscr, TRUE);

  getmaxyx (stdscr, y, x);
  attrset (A_NORMAL);
  attrset (COLOR_PAIR (1));

  if (gui_window_new_identity.x1 == -999)
    {
  } else
    x = gui_window_new_identity.x1;

  attrset (COLOR_PAIR (0));
  snprintf (buf, 199, "%199.199s", " ");
  mvaddnstr (gui_window_new_identity.y0 + 1,
             gui_window_new_identity.x0, buf, x - gui_window_new_identity.x0 - 1);
  mvaddnstr (gui_window_new_identity.y0 + 2, gui_window_new_identity.x0, buf,
             x - gui_window_new_identity.x0 - 1);
  mvaddnstr (gui_window_new_identity.y0 + 3, gui_window_new_identity.x0, buf,
             x - gui_window_new_identity.x0 - 1);
  mvaddnstr (gui_window_new_identity.y0 + 4, gui_window_new_identity.x0, buf,
             x - gui_window_new_identity.x0 - 1);

  attrset (COLOR_PAIR (1));
  snprintf (buf, x - gui_window_new_identity.x0, "SIP url : ");
  mvaddnstr (gui_window_new_identity.y0,
             gui_window_new_identity.x0, buf, x - gui_window_new_identity.x0 - 1);
  snprintf (buf, x - gui_window_new_identity.x0, "TEL url : ");
  mvaddnstr (gui_window_new_identity.y0 + 1,
             gui_window_new_identity.x0, buf, x - gui_window_new_identity.x0 - 1);
  snprintf (buf, x - gui_window_new_identity.x0, "Email   : ");
  mvaddnstr (gui_window_new_identity.y0 + 2,
             gui_window_new_identity.x0, buf, x - gui_window_new_identity.x0 - 1);
  snprintf (buf, x - gui_window_new_identity.x0, "Phone   : ");
  mvaddnstr (gui_window_new_identity.y0 + 3,
             gui_window_new_identity.x0, buf, x - gui_window_new_identity.x0 - 1);

  window_new_identity_draw_commands ();

  return 0;
}
Beispiel #14
0
Datei: sl.c Projekt: isamu/sl
int my_mvaddstr(int y, int x, char *str)
{
  int i = 0;
  
  for ( ; x < 0; ++x, ++i) {
    if (str[i] == '\0') {
      return ERR;
    }
  }
  if (mvaddnstr(y, x, &str[i], (int)COLS - x) == ERR) {
    return ERR;
  }
  
  return OK;
}
Beispiel #15
0
void WDL_CursesEditor::draw_message(const char *str)
{
  int l=strlen(str);
  if (l > COLS-2) l=COLS-2;
  if (str[0]) 
  {
    attrset(m_color_message);
    bkgdset(m_color_message);
  }
  mvaddnstr(LINES-(m_bottom_margin>1?2:1),0,str,l);
  clrtoeol();
  if (str[0])
  {
    attrset(0);
    bkgdset(0);
  }
}
void WDL_CursesEditor::doDrawString(int y, int x, int line_n, const char *p, int ml, int *c_comment_state, int skipcnt)
{
  if (skipcnt < 0) skipcnt=0;
  mvaddnstr_highlight(y,x,p,ml + skipcnt,c_comment_state, skipcnt);

  if (m_selecting)
  {
    int miny,maxy,minx,maxx;
    getselectregion(minx,miny,maxx,maxy);
   
    if (line_n >= miny && line_n <= maxy && (miny != maxy || minx < maxx))
    {
      minx-=skipcnt;
      maxx-=skipcnt;

      if (line_n > miny) minx=0;
      if (line_n < maxy) maxx=ml;

      if (minx<0)minx=0;
      if (minx > ml) minx=ml;
      if (maxx > ml) maxx=ml;

      if (maxx > minx)
      {
        int a = skipcnt + minx;
        while (a-- > 0 && *p) p++;

        a=strlen(p);
        if (a > maxx-minx) a= maxx-minx;

        attrset(m_color_selection);
        mvaddnstr(y,x+minx, p, a);
        attrset(A_NORMAL);
      }
      else if (maxx==minx && !*p && ml>0)
      {
        attrset(m_color_selection);
        mvaddstr(y,x+minx," ");
        attrset(A_NORMAL);
      }
    }
  }
}
int window_loglines_print()
{
  char buf1[200];
  int x, y;
  getmaxyx(stdscr,y,x);

  if (log_buf1!='\0')
    {
      /* int xpos; */
      osip_mutex_lock(log_mutex);
      snprintf(buf1,199, "%199.199s", " ");
      attrset(COLOR_PAIR(4));
      mvaddnstr(y-1,0,buf1,x-1);
      /* xpos = (x - strlen(log_buf1))/2;
	 if (xpos<0)
	 xpos = 0; */
      /* mvaddnstr(y-1,xpos,log_buf1,x-1); */
      mvaddnstr(y-1,0,log_buf1,x-1);
      osip_mutex_unlock(log_mutex);
    }
  if (log_buf2!='\0')
    {
      /* int xpos; */
      osip_mutex_lock(log_mutex);
      snprintf(buf1,199, "%199.199s", " ");
      attrset(COLOR_PAIR(4));
      mvaddnstr(y-2,0,buf1,x-1);
      /* xpos = (x - strlen(log_buf2))/2;
	 if (xpos<0)
	 xpos = 0; */
      /* mvaddnstr(y-2,xpos,log_buf2,x-1); */
      mvaddnstr(y-2,0,log_buf2,x-1);
      osip_mutex_unlock(log_mutex);
    }
  if (log_buf3!='\0')
    {
      /* int xpos; */
      osip_mutex_lock(log_mutex);
      snprintf(buf1,199, "%199.199s", " ");
      attrset(COLOR_PAIR(4));
      mvaddnstr(y-3,0,buf1,x-1);
      /* xpos = (x - strlen(log_buf3))/2;
	 if (xpos<0)
	 xpos = 0; */
      /* mvaddnstr(y-3,xpos,log_buf3,x-1); */
      mvaddnstr(y-3,0,log_buf3,x-1);
      osip_mutex_unlock(log_mutex);
    }
  return 0;
}
Beispiel #18
0
int
josua_clear_box_and_commands(gui_t *box)
{
  int pos;
  int y,x;
  char buf[250];
  curseson(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE);

  getmaxyx(stdscr,y,x);
  attrset(A_NORMAL);
  attrset(COLOR_PAIR(1));

  {
    char *commands[] = {
      NULL
    };
    josua_print_command(commands,
			y-5,
			0);
  }

  if (box->x1==-999)
    {}
  else x = box->x1;

  if (box->y1<0)
    y = y + box->y1;
  else
    y = box->y1;

  attrset(COLOR_PAIR(0));
  for (pos=box->y0;pos<y;pos++)
    {
      snprintf(buf, 199, "%199.199s", " ");
      mvaddnstr(pos,
		box->x0,
		buf,
		x-box->x0-1);
    }

  return 0;
}
void WDL_CursesEditor::draw_message(const char *str)
{
  int l=strlen(str);
  if (l > COLS-2) l=COLS-2;
  if (str[0]) 
  {
    attrset(m_color_message);
    bkgdset(m_color_message);
  }
  mvaddnstr(LINES-(m_bottom_margin>1?2:1),0,str,l);
  clrtoeol();
  if (str[0])
  {
    attrset(0);
    bkgdset(0);
  }   

  int paney[2], paneh[2];
  const int pane_divy=GetPaneDims(paney, paneh);

  const int col=m_curs_x-m_offs_x;
  int line=m_curs_y+paney[m_curpane]-m_paneoffs_y[m_curpane];
  if (line >= paney[m_curpane] && line < paney[m_curpane]+paneh[m_curpane]) move(line, col);
}
Beispiel #20
0
static void
draw_help(void)
{
#define HW 46
#define HH 19
	int i, y = (rows/2) - (HH/2);
	int x = (cols/2) - (HW/2);
	char pad[HW+1];

	memset(pad, ' ', sizeof(pad));
	pad[sizeof(pad) - 1] = '\0';

	attron(A_STANDOUT);

	for (i = 0; i < HH; i++)
		mvaddnstr(y + i, x, pad, -1);

	mvaddch(y  - 1, x - 1, ACS_ULCORNER);
	mvaddch(y + HH, x - 1, ACS_LLCORNER);
	
	mvaddch(y  - 1, x + HW, ACS_URCORNER);
	mvaddch(y + HH, x + HW, ACS_LRCORNER);

	for (i = 0; i < HH; i++) {
		mvaddch(y + i, x -  1, ACS_VLINE);
		mvaddch(y + i, x + HW, ACS_VLINE);
	}

	for (i = 0; i < HW; i++) {
		mvaddch(y  - 1, x + i, ACS_HLINE);
		mvaddch(y + HH, x + i, ACS_HLINE);
	}

	attron(A_BOLD);
	mvaddnstr(y- 1, x+15, "REFERENCIA RAPIDA", -1);
	attron(A_UNDERLINE);
	mvaddnstr(y+ 0, x+3, "Navigation", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+ 1, x+5, "UP      Tarjeta Anterior", -1);
	mvaddnstr(y+ 2, x+5, "DOWN    Tarjeta Siguiente", -1);
	mvaddnstr(y+ 3, x+5, "LEFT    Nodo Anterior", -1);
	mvaddnstr(y+ 4, x+5, "RIGHT   Nodo Siguiente", -1);
	mvaddnstr(y+ 5, x+5, "?       Palanca referencia rapida", -1);
	mvaddnstr(y+ 6, x+5, "q       Salir bmon", -1);

	attron(A_BOLD | A_UNDERLINE);
	mvaddnstr(y+ 7, x+3, "Mostrar Configuracion", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+ 8, x+5, "g       Toggle graphical statistics", -1);
	mvaddnstr(y+ 9, x+5, "d       Toggle detailed statistics", -1);
	mvaddnstr(y+10, x+5, "c       Toggle combined node list", -1);
	mvaddnstr(y+11, x+5, "l       Toggle interface list", -1);
	mvaddnstr(y+12, x+5, "f       (Un)fold sub interfaces", -1);

	attron(A_BOLD | A_UNDERLINE);
	mvaddnstr(y+13, x+3, "Measurement Units", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+14, x+5, "R       Read Interval", -1);
	mvaddnstr(y+15, x+5, "S       Segundos", -1);
	mvaddnstr(y+16, x+5, "M       Minutos", -1);
	mvaddnstr(y+17, x+5, "H       Horas", -1);
	mvaddnstr(y+18, x+5, "D       Dias", -1);
	attroff(A_STANDOUT);
}
Beispiel #21
0
static void curses_draw_line(unsigned x, unsigned y, const char *text, unsigned len, BYTE attr)
{
    mvaddnstr(y, x, text, len);
}
Beispiel #22
0
int
io_list(field_t *f)
{
 int c = 0, i = -1, y = -1, max_x = 0, max_y = 0, top = 0, bot = 0;
 int index = 0, offset = 0, size = 0, j = 0, first = 1, k = 0;
 int n = 0, rows = 0, find_index = 0, value_count = 0, increase = 0;
 char *s = NULL, *p = NULL, s_v[2] = {'\0', '\0'};
 size_t *on = NULL;

 s_v[0] = value_separator;
 if ( BOOLEAN_T != f->type ) {
     if ( NULL == f->list ) {
         return (0);
     } else if ( access(f->list, X_OK) < 0 ) {
         return (-1);
     }
 }
 if ( ((BOOLEAN_T == f->type ) || (f->list)) && (0 == f->constant) ) { 
     if ( (list(f) < 0) || (0 == S_count) ) {
         return (0);  /*  XXX  */
     } else {
         if ( NULL == (on = calloc(S_count, sizeof(size_t))) ) {
             return (0); /*  XXX  */
         }
         for (;;) {
             getmaxyx(stdscr, max_y, max_x);
             if ( (max_y < MIN_Y) || (max_x < MIN_X) ) {
                 return (0);
             } else {
                 clear(); mvprintw(1, 30, "%s", f->label); bot = max_y-5;
                 if ( 1 == f->max_values ) {
                     top = 5;
                     mvaddstr(3,2,
                               "Move cursor to desired item and press Enter.");
                 } else {
                     top = 7;
                     mvaddstr(top-4, 2,
                                  "Move cursor to desired item and press F7.");
                     mvaddstr(top-3, 6, "ONE OR MORE items can be selected.");
                     mvaddstr(top-2, 2,
                                   "Press Enter AFTER making all selections.");
                 }
                 if ( S_count > max_y-12 ) {
                     top++; bot--;
                 }
             }
             LIST_LEGEND;
             if ( 1 == f->max_values ) {
                 rows = max_y-12;
             } else {
                 rows = max_y-14;
             }
             for (;;) {
                 for ( i = offset, y = top; i < S_count && y < bot; i++, y++) {
                     mvaddch(y, 2, on[i] ? '>' : ' ');
                     mvaddnstr(y, 4, S[i], max_x-6); clrtoeol();
                 }
                 attron(A_STANDOUT);
                 mvaddnstr(top+(index-offset), 4, S[index], max_x-6);
                 attroff(A_STANDOUT);
                 if ( S_count > max_y-12 ) {
                     if ( offset ) {
                         mvprintw(top-1, 2, "[MORE...%d]", offset); clrtoeol();
                     } else {
                         mvaddstr(top-1, 2, "[TOP]"); clrtoeol();
                     }
                     if ( S_count > offset+(bot-top) ) {
                         mvprintw(max_y-6, 2, "[MORE...%d]",
                                                   S_count-(offset+(bot-top)));
                         clrtoeol();
                     } else {
                         mvaddstr(max_y-6, 2, "[BOTTOM]"); clrtoeol();
                     }
                 }
                 (void)border('|', '|', '-', '-', '+', '+', '+', '+');
                 c = get_key(top+(index-offset), 3);
                 if ( KEY_DOWN == c ) {
                     if ( index < S_count-1 ) {
                         index++;
                         if ( (index-offset) > (bot-top-1) ) {
                             offset++;
                         }
                     }
                 } else if ( KEY_UP == c ) {
                     if ( index ) {
                         if ( index == offset ) {
                             offset--;
                         }
                         index--;
                     }
                 } else if ( KEY_PPAGE == c ) {
                     if ( offset > 0 ) {
                         if ( offset > rows ) {
                             offset -= rows; index -= rows;
                         } else {
                             index -= offset; offset = 0;
                         }
                     } else {
                         index = 0;
                     }
                 } else if ( KEY_NPAGE == c ) {
                     if ( offset < S_count-rows ) {
                         if ( offset < S_count-2*rows ) {
                             offset += rows; index += rows;
                         } else {
                             index  += S_count-offset-rows;
                             offset += S_count-offset-rows;
                         }
                     } else {
                         index = S_count-1;
                     } 
                 } else if ( (KEY_F(1) == c) || (KEY_F(10) == c)  ) {
                     return (c);
                 } else if ( KEY_F(3) == c ) {
                     return (KEY_F(2));
                 } else if ( (KEY_F(7) == c) || (' ' == c) ) {
                     if ( f->max_values > 1 ) {
                         if ( on[index] ) {
                             size -= on[index]; on[index] = 0; value_count--;
                         } else if ( value_count < f->max_values ) {
                             increase = strlen(S[index]);
                             if ( value_count ) {
                                 increase+=1;
                             }
                             if ( size+increase < f->width ) {
                                 on[index] = increase; value_count++;
                                 size+=increase;
                             }
                         } /*  XXX else ERROR  */
                     }
                 } else if ( KEY_F(8) == c ) {
                     if ( (KEY_F(1) == (k = image())) || (KEY_F(10) == k)  ) {
                         return (k);
                     } else if ( KEY_F(2) == k ) {
                         refresh();
                     }
                 } else if ( '/' == c ) {
                     find_index = find_text(index);
                     if ( FIND_CANCEL == find_index ) {
                         find_index = 0;  /*  No-op.  */
                     } else if ( FIND_EXIT == find_index ) {
                         free(srch_txt); srch_txt = NULL;
                         return ( KEY_F(10) );
                     } else if ( find_index > offset+rows-1 ) {
                         /* Forward find off page. */
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         /* Backward find off page. */
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                     LIST_LEGEND;
                 } else if ( 'n' == c ) {
                     find_index = find_next(index);
                     if ( find_index > offset+rows-1 ) {
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                 } else if ( (KEY_ENTER == c) || ('\r' == c) || ('\n' == c) ) {
                     if ( 1 == f->max_values ) {
                         for ( k = 0; k < S_count; k++ ) {
                             on[k] = 0;
                         }
                         on[index] = 1;
                     }
                     f->buf[0] = '\0';
                     for ( j = 0; j < S_count; j++ ) {
                         if ( on[j] ) {
                             if ( !first ) {
                                 strcat(f->buf, s_v);
                             }
                             strcat(f->buf, S[j]); first = 0;
                         }
                     }
                     for ( k = 0; k < S_count; k++ ) {
                         free(S[k]); S[k] = NULL;
                     }
                     free(S); S = NULL; free(on); S_count = 0; return (0);
                 }
             }
         }
     }
 }
 return (0);
}
Beispiel #23
0
void sinsp_cursesui::render_filtersearch_main_menu()
{
	uint32_t k = 0;
	string* str;

	//
	// Pick the right string based on what we're doing
	//
	if(m_output_filtering)
	{
		str = &m_manual_filter;

		if(*str == "" && m_is_filter_sysdig && m_complete_filter != "")
		{
			*str = m_complete_filter;
		}
	}
	else if(m_output_searching)
	{
		str = &m_manual_search_text;
	}
	else
	{
		if(m_search_caller_interface)
		{
			str = m_search_caller_interface->get_last_search_string();
		}
		else
		{
			ASSERT(false);
		}
	}

	//
	// Only clear the line if this is the first refresh, to prevent deleting the
	// text that the user is typing
	//
	if(m_cursor_pos == 0)
	{
		move(m_screenh - 1, 0);
		for(uint32_t j = 0; j < m_screenw; j++)
		{
			addch(' ');
		}
	}

	attrset(m_colors[PROCESS]);
	string fks = "F1";
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 10);
	k += fks.size();
	attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
	fks = "Help";
	fks.resize(6, ' ');
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 6);
	k += 6;

	if(m_output_filtering)
	{
		attrset(m_colors[PROCESS]);
		fks = "F2";
		mvaddnstr(m_screenh - 1, k, fks.c_str(), 10);
		k += fks.size();
		attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
		if(m_is_filter_sysdig)
		{
			fks = "Text";
		}
		else
		{
			fks = "sysdig";
		}
		fks.resize(6, ' ');
		mvaddnstr(m_screenh - 1, k, fks.c_str(), 6);
		k += 6;
	}

	attrset(m_colors[PROCESS]);
	fks = "Enter";
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 10);
	k += fks.size();

	attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
	fks = "Done";
	fks.resize(6, ' ');
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 6);
	k += 6;

	attrset(m_colors[PROCESS]);
	fks = "Esc";
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 10);
	k += fks.size();

	attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
	fks = "Clear";
	fks.resize(6, ' ');
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 6);
	k += 6;

	k++;
	attrset(m_colors[PANEL_HIGHLIGHT_FOCUS]);
	if(m_is_filter_sysdig)
	{
		fks = "Expression: ";
	}
	else
	{
		if(m_search_header_text == "")
		{
			fks = "Text to match: ";
		}
		else
		{
			fks = m_search_header_text + ": ";
		}
	}
	mvaddnstr(m_screenh - 1, k, fks.c_str(), 20);
	k += fks.size();

	uint32_t cursor_pos = k;

	if(m_cursor_pos == 0)
	{
		for(; k < m_screenw; k++)
		{
			addch(' ');
		}

		m_cursor_pos = cursor_pos;

		mvprintw(m_screenh - 1, m_cursor_pos, str->c_str());

		m_cursor_pos += str->size();
	}

	move(m_screenh - 1, m_cursor_pos);
}
Beispiel #24
0
void sinsp_cursesui::render_header()
{
	uint32_t j = 0;
	uint32_t k = 0;

	//
	// Show the 'viewing' line
	//
	attrset(m_colors[HELP_BOLD]);
	move(0, 0);
	for(j = 0; j < m_screenw; j++)
	{
		addch(' ');
	}

	mvaddstr(0, 0, "Viewing:");
	k += sizeof("Viewing: ") - 1;
 
	attrset(m_colors[sinsp_cursesui::PROCESS]);

	string vs;

	if(m_selected_view >= 0)
	{
		sinsp_view_info* sv = get_selected_view();
		const char* vcs = sv->m_name.c_str();
		vs = vcs;
	}
	else
	{
		if(m_selected_view == VIEW_ID_SPY)
		{
			vs = "I/O activity";
		}
		else if(m_selected_view == VIEW_ID_DIG)
		{
			vs = "sysdig output";
		}
		else
		{
			ASSERT(false);
		}
	}

	mvaddstr(0, k, vs.c_str());

	k+= vs.size() + 1;

	attrset(m_colors[HELP_BOLD]);
	mvaddstr(0, k, "For: ");
	k += sizeof("For: ") - 1;

	attrset(m_colors[sinsp_cursesui::PROCESS]);
	if(m_sel_hierarchy.size() != 0)
	{
		vs = "";

		for(j = 0; j < m_sel_hierarchy.size(); j++)
		{
			vs += m_sel_hierarchy.at(j)->m_field;
			vs += "=";
			vs += m_sel_hierarchy.at(j)->m_val;

			if(j < m_sel_hierarchy.size() - 1)
			{
				vs += " and ";
			}
		}
	}
	else
	{
		vs = "whole machine";
	}

	mvaddstr(0, k, vs.c_str());

	if(m_paused)
	{
		string wstr = "PAUSED";
		attrset(m_colors[sinsp_cursesui::LARGE_NUMBER]);
		mvprintw(0,
			m_screenw / 2 - wstr.size() / 2, 
			wstr.c_str());	
	}

	//
	// Show the 'filter' line
	//
	attrset(m_colors[HELP_BOLD]);

	move(1, 0);
	for(uint32_t j = 0; j < m_screenw; j++)
	{
		addch(' ');
	}

	attrset(m_colors[HELP_BOLD]);

	mvaddstr(1, 0, "Source:");
	k = sizeof("Source: ") - 1;

	attrset(m_colors[sinsp_cursesui::PROCESS]);
	
	string srcstr;
	
	if(m_inspector->is_live())
	{
		srcstr = "Live System";
	}
	else
	{
		if(m_n_evts_in_file == 0)
		{
			m_n_evts_in_file = m_inspector->get_num_events();
			m_evt_ts_delta = m_last_evt_ts - m_1st_evt_ts;
		}

		srcstr = m_inspector->get_input_filename();
		srcstr += " (" + to_string(m_n_evts_in_file) + " evts, ";

		if(m_truncated_input)
		{
			srcstr += " truncated, ";
		}

		m_timedelta_formatter->set_val(PT_RELTIME, 
			(uint8_t*)&m_evt_ts_delta,
			8,
			0,
			ppm_print_format::PF_DEC);

			srcstr += string(m_timedelta_formatter->tostring_nice(NULL, 0, 0)) + ")";
	}

	mvaddnstr(1, k, srcstr.c_str(), m_screenw - k - 1);

	k += srcstr.size() + 1;
	m_filterstring_start_x = k;

	attrset(m_colors[HELP_BOLD]);

	mvaddstr(1, k, "Filter:");
	k += sizeof("Filter: ") - 1;

	attrset(m_colors[sinsp_cursesui::PROCESS]);

	string sflt;
	if(m_complete_filter != "")
	{
		sflt = m_complete_filter.c_str();
	}
	else
	{
		sflt = "none";
	}

	mvaddnstr(1, k, sflt.c_str(), m_screenw - k - 1);
	
	k += sflt.size();
	m_filterstring_end_x = k;
}
int window_new_call_print(gui_t* gui, int wid)
{
	int y,x;
	char buf[250];

	ogmp_curses_t* ocui = gui->topui;
	user_profile_t* user_profile = ocui->sipua->profile(ocui->sipua);

	int pos;
	char c, *ch;
	
	curseson(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE);

	gui->parent = wid;

	getmaxyx(stdscr,y,x);
	attrset(A_NORMAL);
	attrset(COLOR_PAIR(1));

	if (gui->x1==-999)
    {}
	else 
		x = gui->x1;

	/* Window Title */
	snprintf(buf, 250, "%199.199s", " ");

	attrset(COLOR_PAIR(4));
	mvaddnstr(gui->y0, gui->x0, buf, (x-gui->x0));
	snprintf(buf, x-gui->x0-1, "New call from: '%s'<%s>", user_profile->fullname, user_profile->regname);
	mvaddstr(gui->y0, gui->x0+1, buf);

	/* Window Body */
	pos = editline_pos(newcall_edit[cursor_newcall]);
	editline_char(newcall_edit[cursor_newcall], &ch);
	if(!*ch)
		c = ' ';
	else
		c = *ch;

	attrset(COLOR_PAIR(0));
	snprintf(buf, 199, "%199.199s", " ");
	mvaddnstr(gui->y0+1, gui->x0, buf, x-gui->x0-1);
	mvaddnstr(gui->y0+2, gui->x0, buf, x-gui->x0-1);
	mvaddnstr(gui->y0+3, gui->x0, buf, x-gui->x0-1);
	mvaddnstr(gui->y0+4, gui->x0, buf, x-gui->x0-1);
  
	
	if(cursor_newcall == NEWCALL_TO)
		attrset(COLOR_PAIR(10));
	else
		attrset(COLOR_PAIR(1));

	snprintf(buf, 25, "%10.10s", "To :");
	mvaddstr(gui->y0+1, gui->x0, buf);
  
	
	if(cursor_newcall == NEWCALL_SUBJ)
		attrset(COLOR_PAIR(10));
	else
		attrset(COLOR_PAIR(1));

	snprintf(buf, 25, "%10.10s", "Subject :");
	mvaddstr(gui->y0+2, gui->x0, buf);


	if(cursor_newcall == NEWCALL_MSG)
		attrset(COLOR_PAIR(10));
	else
		attrset(COLOR_PAIR(1));

	snprintf(buf, 25, "%10.10s", "Message :");
	mvaddstr(gui->y0+3, gui->x0, buf);

	if(newcall_inputs[NEWCALL_TO][0] == '\0' && ocui->contact)
	{
		editline_set_line(newcall_edit[NEWCALL_TO], ocui->contact->sip, strlen(ocui->contact->sip));

		ocui->contact = NULL;
	}
  
	attrset(COLOR_PAIR(0));
	mvaddstr(gui->y0+1, gui->x0+11, newcall_inputs[NEWCALL_TO]);

	attrset(COLOR_PAIR(0));
	mvaddstr(gui->y0+2, gui->x0+11, newcall_inputs[NEWCALL_SUBJ]);

	attrset(COLOR_PAIR(0));
	mvaddstr(gui->y0+3, gui->x0+11, newcall_inputs[NEWCALL_MSG]);

	attrset(COLOR_PAIR(10));
	mvaddch(gui->y0+1+cursor_newcall, gui->x0+11+pos, c);

	window_new_call_draw_commands(gui);

	return 0;
}
Beispiel #26
0
static void
draw_help(void)
{
#define HW 46
#define HH 19
	int i, y = (rows/2) - (HH/2);
	int x = (cols/2) - (HW/2);
	char pad[HW+1];

	memset(pad, ' ', sizeof(pad));
	pad[sizeof(pad) - 1] = '\0';

	attron(A_STANDOUT);

	for (i = 0; i < HH; i++)
		mvaddnstr(y + i, x, pad, -1);

	mvaddch(y  - 1, x - 1, ACS_ULCORNER);
	mvaddch(y + HH, x - 1, ACS_LLCORNER);
	
	mvaddch(y  - 1, x + HW, ACS_URCORNER);
	mvaddch(y + HH, x + HW, ACS_LRCORNER);

	for (i = 0; i < HH; i++) {
		mvaddch(y + i, x -  1, ACS_VLINE);
		mvaddch(y + i, x + HW, ACS_VLINE);
	}

	for (i = 0; i < HW; i++) {
		mvaddch(y  - 1, x + i, ACS_HLINE);
		mvaddch(y + HH, x + i, ACS_HLINE);
	}

	attron(A_BOLD);
	mvaddnstr(y- 1, x+15, "QUICK REFERENCE", -1);
	attron(A_UNDERLINE);
	mvaddnstr(y+ 0, x+3, "Navigation", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+ 1, x+5, "UP      Previous interface", -1);
	mvaddnstr(y+ 2, x+5, "DOWN    Next interface", -1);
	mvaddnstr(y+ 3, x+5, "LEFT    Previous node", -1);
	mvaddnstr(y+ 4, x+5, "RIGHT   Next node", -1);
	mvaddnstr(y+ 5, x+5, "?       Toggle quick reference", -1);
	mvaddnstr(y+ 6, x+5, "q       Quit bmon", -1);

	attron(A_BOLD | A_UNDERLINE);
	mvaddnstr(y+ 7, x+3, "Display Settings", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+ 8, x+5, "g       Toggle graphical statistics", -1);
	mvaddnstr(y+ 9, x+5, "d       Toggle detailed statistics", -1);
	mvaddnstr(y+10, x+5, "c       Toggle combined node list", -1);
	mvaddnstr(y+11, x+5, "l       Toggle interface list", -1);
	mvaddnstr(y+12, x+5, "f       (Un)fold sub interfaces", -1);

	attron(A_BOLD | A_UNDERLINE);
	mvaddnstr(y+13, x+3, "Measurement Units", -1);
	attroff(A_BOLD | A_UNDERLINE);

	mvaddnstr(y+14, x+5, "R       Read Interval", -1);
	mvaddnstr(y+15, x+5, "S       Seconds", -1);
	mvaddnstr(y+16, x+5, "M       Minutes", -1);
	mvaddnstr(y+17, x+5, "H       Hours", -1);
	mvaddnstr(y+18, x+5, "D       Days", -1);
	attroff(A_STANDOUT);
}
Beispiel #27
0
int
josua_print_command(char **commands, int ypos, int xpos)
{
  int i;
  int y,x;
  char buf[250];
  curseson(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE);

  getmaxyx(stdscr,y,x);
  attrset(A_NORMAL);

#if 0
  for (i=0;commands[i]!=NULL;i=i+2)
    {
      int len = strlen(commands[i+1]);
      if (len>maxlen)
	maxlen = len;
    }
#endif

  if (commands[0]!=NULL) /* erase with default background */
    attrset(COLOR_PAIR(10));
  else
    attrset(COLOR_PAIR(0));
  snprintf(buf, 199, "%199.199s", " ");
  mvaddnstr(ypos,
	    xpos,
	    buf,
	    x-xpos-1);
  mvaddnstr(ypos+1,
	    xpos,
	    buf,
	    x-xpos-1);

  for (i=0;commands[i]!=NULL;i=i+2)
    {
      int maxlen = strlen(commands[i+1]);
      if (commands[i+2]!=NULL)
	{
	  int len = strlen(commands[i+3]);
	  if (len>maxlen)
	    maxlen = len;
	}
      attrset(COLOR_PAIR(1));
      snprintf(buf,
	       strlen(commands[i])+1,
	       commands[i]);
      mvaddnstr(ypos,
		xpos,
		buf,
		strlen(commands[i]));
      attrset(COLOR_PAIR(10));
      snprintf(buf,
	       strlen(commands[i+1])+1,
	       "%s", commands[i+1]);
      mvaddnstr(ypos,
		xpos+3,
		buf,
		maxlen);
      i=i+2;
      if (commands[i]==NULL)
	break;
      attrset(COLOR_PAIR(1));
      snprintf(buf,
	       strlen(commands[i])+1,
	       commands[i]);
      mvaddnstr(ypos+1,
		xpos,
		buf,
		strlen(commands[i]));
      attrset(COLOR_PAIR(10));
      snprintf(buf,
	       strlen(commands[i+1])+1,
	       "%s", commands[i+1]);
      mvaddnstr(ypos+1,
		xpos+3,
		buf,
		maxlen);
      xpos = xpos+maxlen+4; /* position for next column */
    }
  return 0;
}
Beispiel #28
0
/* Among other things,  'newtest' demonstrates how to make a Win32a
PDCurses app that is a for-real,  "pure Windows" version (instead of
a console application).  Doing this is quite easy,  and has certain
advantages.  If the app is invoked from a command prompt,  the only
difference you'll see is that the app runs separately (that is,  you
can continue to use the command prompt,  switching between it,  your
PDCurses/Win32a app,  and other processes).  Which is the main reason
I did it;  it meant that I could invoke a PDCurses-based text editor,
for example,  and still have use of the command line.

   (NOTE that,  for reasons I don't actually understand,  this happens
when the Visual C++ compiler is used.  With MinGW or OpenWatcom,  it's
still "really" a console app.)

   To do it,  we ensure that the usual main() function has an alternative
dummy_main() form,  taking the same arguments as main().  We add a
WinMain() function,  whose sole purpose is to reformulate lpszCmdLine
into argc/argv form,  and pass it on to dummy_main().  And,  of course,
we can switch back to a "normal" console app by removing the above
#define PURE_WINDOWS_VERSION line.             */

#ifdef PURE_WINDOWS_VERSION
#undef MOUSE_MOVED
#include <windows.h>

int dummy_main( int argc, char **argv);

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpszCmdLine, int nCmdShow)
{
   char *argv[30];
   int i, argc = 1;

   argv[0] = "newtest";
   for( i = 0; lpszCmdLine[i]; i++)
       if( lpszCmdLine[i] != ' ' && (!i || lpszCmdLine[i - 1] == ' '))
          argv[argc++] = lpszCmdLine + i;

   for( i = 0; lpszCmdLine[i]; i++)
       if( lpszCmdLine[i] == ' ')
          lpszCmdLine[i] = '\0';

   return dummy_main( argc, (char **)argv);
}

int dummy_main( int argc, char **argv)
#else       /* "usual",  console-app version: */
int main( int argc, char **argv)
#endif
{
    int quit = 0, i,  use_slk = 1;
    int fmt = 0xa;
    bool blink_state = FALSE;
    int cursor_state_1 = 2, cursor_state_2 = 3;
    int show_slk_index_line = 0;
    int redraw = 1;
    unsigned extra_character_to_show = 0;
#ifdef PDC_WIDE
    unsigned unicode_offset = 0x80;
#endif

/*  setlocale(LC_ALL, ".utf8");     */
    ttytype[0] = 25;   ttytype[1] = 90;         /* Allow 25 to 90 lines... */
    ttytype[2] = 80;   ttytype[3] = (char)200;  /* ...and 80 to 200 columns */
         /* (This program gets weird artifacts when smaller than 25x80.) */
    for( i = 1; i < argc; i++)
        if( argv[i][0] == '-')
            switch( argv[i][1])
            {
                case 's':
                    use_slk = 0;
                    break;
                case 'l':
                    setlocale( LC_ALL, argv[i] + 2);
                    break;
                case 'e':
                    sscanf( argv[i] + 2, "%x", &extra_character_to_show);
                    break;
                case 'f':
                    sscanf( argv[i] + 2, "%x", (unsigned *)&fmt);
                    break;
                case 'i':
                    show_slk_index_line = 1;
                    break;
                case 'r':     /* allow user-resizable windows */
                    {
                        int min_lines, max_lines, min_cols, max_cols;

                        if( sscanf( argv[i] + 2, "%d,%d,%d,%d",
                                       &min_lines, &max_lines,
                                       &min_cols, &max_cols) == 4)
                        {
                            ttytype[0] = min_lines;
                            ttytype[1] = max_lines;
                            ttytype[2] = min_cols;
                            ttytype[3] = max_cols;
                        }
                    }
                    break;
                case 'd':     /* set window size before initscr */
                    {
                        int n_lines, n_cols;

                        if( sscanf( argv[i] + 2, "%d,%d", &n_lines,
                                    &n_cols) == 2)
                            resize_term( n_lines, n_cols);
                    }
                    break;
#ifdef PDC_WIDE
                case 'u':
                    sscanf( argv[i] + 2, "%x", &unicode_offset);
                    break;
#endif
                default:
                    printf( "Option '%s' unrecognized\n", argv[i]);
                    break;
            }
    if( use_slk)
       slk_init( show_slk_index_line ? 3 : 0);
    Xinitscr(argc, argv);
    if( use_slk)
       slk_setup( show_slk_index_line ? -fmt : fmt);

    start_color();

# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
    use_default_colors();
# endif
    cbreak();
    noecho();
    clear();
    refresh();
#ifdef __PDCURSES__
    PDC_set_title( "NewTest: tests various PDCurses features");
#endif
    keypad( stdscr, TRUE);
    init_pair( 1, 15, COLOR_BLACK);
    init_pair( 2, COLOR_BLACK, COLOR_YELLOW);

    mousemask( ALL_MOUSE_EVENTS, NULL);
    attrset( COLOR_PAIR( 1));
    while( !quit)
    {
        char buff[40];
        const int xmax = getmaxx( stdscr);
        const int ymax = getmaxy( stdscr);
        int color_block_start = 54, c;
        int color_block_cols = (xmax - color_block_start) / 2;
        const int color_block_lines = 19;
        const char *cursor_state_text[N_CURSORS] = {
                  "Invisible (click to change) ",
                  "Underscore (click to change)",
                  "Block (click to change)     ",
                  "Outline (click to change)   ",
                  "Caret (click to change)     ",
                  "Half-block (click to change)",
                  "Central (click to change)   ",
                  "Cross (click to change)     ",
                  "Heavy box (click to change) " };

        if( color_block_cols < 0)
            color_block_cols = 0;
        if( redraw)
        {
            mvaddstr( 1, COL1, "'Normal' white-on-black");
#if(CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
            attron( A_DIM);
            mvaddstr( 2, COL1, "Dimmed text");
            attroff( A_DIM);
#endif
#ifdef PDC_WIDE
            mvaddwstr( 3, COL1, L"'Normal' text,  but wide");
#endif
            attron( A_BLINK);
            mvaddstr( 6, 40, "Blinking");
            attron( A_BOLD);
            mvaddstr( 8, 40, "BlinkBold");
            attron( A_ITALIC);
            mvaddstr( 0, COL2, "BlinkBoldItalic");
            attrset( COLOR_PAIR( 3));
            attron( A_UNDERLINE);
#ifdef PDC_WIDE
            mvaddstr( 1, COL2, "Underlined");
            addwstr( L"WideUnder");
#endif
            attrset( COLOR_PAIR( 1));
            attron( A_UNDERLINE | A_ITALIC);
            mvaddstr( 2, COL2, "UnderlinedItalic");
            attrset( COLOR_PAIR( 2));
            attron( A_BLINK);
            mvaddstr( 4, COL1, "Black-on-yellow blinking");

            attrset( COLOR_PAIR( 1));
            move( 4, COL2);
            text_in_a_box( "Text in a box");

#ifdef CHTYPE_LONG
            attrset( COLOR_PAIR( 6));
            attron( A_STRIKEOUT);
            mvaddstr( 10, 40, "Strikeout");
            attrset( COLOR_PAIR( 1));
#endif

#ifdef PDC_WIDE
            move( 11, 40);
            text_in_a_box( "Next Ucode pg");
            if( unicode_offset)
               {
               move( 12, 40);
               text_in_a_box( "Prev Ucode pg");
               }
            mvprintw( 13, 40, "U+%04x ", unicode_offset);

#endif

            for( i = 0; i < 128; i++)
            {                 /* Show extended characters: */
#ifdef PDC_WIDE
                wchar_t buff[20];

                swprintf( buff, 20, L"%02x ",
                           (unsigned)( i + unicode_offset) & 0xff);
                mvaddwstr( 5 + i % 16, (i / 16) * 5, buff);
                if( i + unicode_offset > ' ')
                   addch( (chtype)( i + unicode_offset));
                else
                   addch( ' ');
                addch( ' ');
#else
                char buff[6];

                sprintf( buff, "%02x %c", i + 128, (char)(i + 128));
                mvaddstr( 5 + i % 16, (i / 16) * 5, buff);
#endif
            }

#if(CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
            for( i = 0; i < 3 && i + 21 < ymax; i++)
            {                 /* Demonstrate full RGB color control: */
                int j;
                const char *output_text[3] = {
                    "Red on green to white on black   | (you can get full RGB colors when desired,",
                    "Blue on yellow to black on red | with palette coloring still being available)",
                    "White on red to green on blue,  underlined and italic" };
                const int len = (int)strlen( output_text[i]);

                move( 21 + i, 1);
                for( j = 0; j < len && j + 1 < xmax; j++)
                {
                    attr_t output_color;
                    const int oval = j * 31 / len;
                    const int reverse = 31 - oval;

                    if( !i)
                        output_color = A_RGB( 31, oval, oval, 0, reverse, 0);
                    else if( i == 1)
                        output_color = A_RGB( 0, 0, reverse, 31, reverse, 0);
                    else
                    {
                        output_color = A_RGB( reverse, 31, reverse,
                               reverse, 0, oval);
                        output_color |= A_UNDERLINE | A_ITALIC;
                    }
                    attrset( output_color);
                    addch( output_text[i][j]);
                }
            }
#endif         /* #if(CHTYPE_LONG >= 2) */
            redraw = 0;
            attrset( COLOR_PAIR( 1));
            if( extra_character_to_show && ymax > 23)
                mvaddch( 23, 63, (chtype)extra_character_to_show);

#ifdef PDC_WIDE
            for( i = 0; i < 6; i++)
            {
                static const wchar_t spanish[] = L"Espa\xf1ol";
                const int line = 24 + i / 3;
                const int col = 5 + 25 * (i % 3);

                static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
                   0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};

                static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7,
                   0x03bd, 0x03b9, 0x03ba, 0x03ac, 0};

                static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7,
                   0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0};

                static const wchar_t fullwidth[] = { 0xff26, 0xff55, 0xff4c, 0xff4c,
                   0xff57, 0xff49, 0xff44, 0xff54, 0xff48, 0 };  /* "Fullwidth" */

                static const wchar_t combining_marks[] = { L'C', L'o', 0x35c, L'm',
                   L'b', 0x30a, L'i', L'n', L'i', 0x304, L'n', 0x30b, 0x329,
                   L'g', 0x310,
                   L' ', L'C', 0x338, L'h', 0x306,  L'a', 0x361, L'r', L's',
                   0x30e, 0x348, 0 };

                static const wchar_t *texts[6] = { spanish, russian, greek,
                                georgian, fullwidth, combining_marks};

                if( line < ymax && col < xmax)
                   mvaddnwstr( line, 5 + 25 * (i % 3), texts[i], xmax - col);
            }
#endif

#ifdef MAYBE_TRY_THIS_SOMEWHERE_ELSE
        mvaddstr(  1, COL3, "Click on cursor descriptions to");
        mvaddstr(  2, COL3, "cycle through possible cursors");
        mvaddstr(  3, COL3, "Click on colors at left to change");
        mvaddstr(  4, COL3, "colors used for under/over/outlining");
        mvaddstr(  5, COL3, "Click 'Blink' at bottom to toggle");
        mvaddstr(  6, COL3, "'real' blinking vs. 'highlit' blink");
#endif
        }

        mvaddnstr( 19, color_block_start, cursor_state_text[cursor_state_1],
                                 xmax - color_block_start);
        mvaddnstr( 20, color_block_start, cursor_state_text[cursor_state_2],
                                 xmax - color_block_start);
        curs_set( (cursor_state_1 << 8) | cursor_state_2);
        for( i = 0; i < color_block_cols * color_block_lines; i++)
        {
            const int n_color_blocks = 256;

            attrset( COLOR_PAIR( i >= n_color_blocks ? 2 : i));
            if( i > 2 && i < n_color_blocks)
               init_pair((short)i, (short)i, COLOR_BLACK);
            if( !(i % color_block_cols))
               move( i / color_block_cols, color_block_start);
            attron( A_REVERSE);
            addstr( "  ");
        }
        move( 19, color_block_start - 3);
        refresh();
        c = getch( );
        attrset( COLOR_PAIR( 1));
        if( c == KEY_RESIZE)
        {
            redraw = 1;
            resize_term( 0, 0);
        }
        else if( c == KEY_F(1) || c == 27)
            quit = 1;
        else if( c == KEY_F(2))
        {
            blink_state ^= 1;
            PDC_set_blink( blink_state);
        }
        else if( c == KEY_F(3))   /* toggle SLKs */
        {
            use_slk ^= 1;
            if( use_slk)
                slk_restore( );
            else
                slk_clear( );
        }
        else if( c >= KEY_F(4) && c < KEY_F(12))
        {
            sscanf( labels[c - KEY_F(1)], "%x", (unsigned *)&fmt);
            if( use_slk)
                slk_setup( show_slk_index_line ? -fmt : fmt);
        }
//      else if( c == 'w')
//          PDC_write_screen_to_file( "scrdump.htm", curscr);
        if( c != KEY_MOUSE)
        {
            sprintf( buff, "Key %s hit          ", keyname( c));
            mvaddstr( 0, COL1, buff);
        }
        else
        {
            MEVENT mouse_event;
#ifdef __PDCURSES__
            nc_getmouse( &mouse_event);
#else
            getmouse( &mouse_event);
#endif
            sprintf( buff, "Mouse at %d x %d: %x  ", mouse_event.x,
                              mouse_event.y, (unsigned)mouse_event.bstate);
            mvaddstr( 0, COL1, buff);
            if( mouse_event.x >= color_block_start
                            && mouse_event.y < color_block_lines)
            {
                int new_color = (mouse_event.x - color_block_start) / 2
                              + mouse_event.y * color_block_cols;

                if( new_color >= 256)
                    new_color = -1;
                PDC_set_line_color( (short)new_color);
            }
            else if( mouse_event.x >= color_block_start)
            {
                int shift = ((mouse_event.bstate & BUTTON_MODIFIER_SHIFT) ?
                           N_CURSORS - 1 : 1);

                if( mouse_event.y == 19)  /* blink/non-blink toggle */
                    cursor_state_1 = (cursor_state_1 + shift) % N_CURSORS;
                else if( mouse_event.y == 20)  /* cycle cursor state */
                    cursor_state_2 = (cursor_state_2 + shift) % N_CURSORS;
            }
#ifdef PDC_WIDE
            else if( mouse_event.x >= 40 && mouse_event.x < 40 + 10)
               {
               if( mouse_event.y == 11)
                  {
                  redraw = 1;
                  unicode_offset += 0x80;
                  }
               else if( mouse_event.y == 12 && unicode_offset)
                  {
                  redraw = 1;
                  unicode_offset -= 0x80;
                  }
               }
#endif
        }
    }

    endwin();

    return 0;
}
int
window_new_identity_run_command (int c)
{
  int y, x;

  getmaxyx (stdscr, y, x);

  if (gui_window_new_identity.x1 == -999)
    {
  } else
    x = gui_window_new_identity.x1;

  switch (c)
    {
      case KEY_DC:
        delch ();
        break;
      case KEY_BACKSPACE:
      case 127:
        if (active_gui->xcursor > 10)
          {
            int xcur, ycur;

            active_gui->xcursor--;
            getyx (stdscr, ycur, xcur);
            move (ycur, xcur - 1);
            delch ();
          }
        break;
      case '\n':
      case '\r':
      case KEY_ENTER:
      case KEY_DOWN:
        if (gui_window_new_identity.ycursor < 3)
          {
            gui_window_new_identity.ycursor++;
            gui_window_new_identity.xcursor = 10;
          }
        break;
      case KEY_UP:
        if (gui_window_new_identity.ycursor > 0)
          {
            gui_window_new_identity.ycursor--;
            gui_window_new_identity.xcursor = 10;
          }
        break;
      case KEY_RIGHT:
        if (gui_window_new_identity.xcursor < (x - gui_window_new_identity.x0 - 1))
          gui_window_new_identity.xcursor++;
        break;
      case KEY_LEFT:
        if (gui_window_new_identity.xcursor > 0)
          gui_window_new_identity.xcursor--;
        break;

        /* case 20: *//* Ctrl-T */
      case 1:                  /* Ctrl-A */
        {
          int ycur = gui_window_new_identity.y0;
          int xcur = gui_window_new_identity.x0 + 10;
          char sipurl[200];
          char telurl[200];
          char email[200];
          char phone[200];

          mvinnstr (ycur, xcur, sipurl, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, telurl, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, email, x - gui_window_new_identity.x0 - 10);
          ycur++;
          mvinnstr (ycur, xcur, phone, x - gui_window_new_identity.x0 - 10);

          _josua_add_contact (sipurl, telurl, email, phone);
          /* mvinnstr(ycur, xcur, tmp, 199); */
        }
        break;
      case 4:                  /* Ctrl-D */
        {
          char buf[200];

          attrset (COLOR_PAIR (0));
          snprintf (buf, 199, "%199.199s", " ");
          mvaddnstr (gui_window_new_identity.y0 +
                     gui_window_new_identity.ycursor,
                     gui_window_new_identity.x0 + 10, buf,
                     x - gui_window_new_identity.x0 - 10 - 1);
          gui_window_new_identity.xcursor = 10;
        }
        break;
      case 5:                  /* Ctrl-E */
        gui_window_new_identity.xcursor = 10;
        gui_window_new_identity.ycursor = 0;
        window_new_identity_print ();
        break;
      default:
        /*
           fprintf(stderr, "c=%i", c);
           exit(0);
         */
        if (gui_window_new_identity.xcursor < (x - gui_window_new_identity.x0 - 1))
          {
            gui_window_new_identity.xcursor++;
            attrset (COLOR_PAIR (0));
            echochar (c);
        } else
          beep ();
        return -1;
    }

  return 0;
}
int window_new_identity_print(gui_t* gui, int wid)
{
    int y,x;
    char buf[250];

    int pos;
    char c, *ch;

    ogmp_curses_t* ocui = gui->topui;

    curseson();
    cbreak();
    noecho();
    nonl();
    keypad(stdscr,TRUE);

    gui->parent = wid;

    getmaxyx(stdscr,y,x);

    attrset(A_NORMAL);

    /* Window Title */
    snprintf(buf, 250, "%199.199s", " ");

    attrset(COLOR_PAIR(4));
    mvaddnstr(gui->y0, gui->x0, buf, (x-gui->x0-1));
    snprintf(buf, x-gui->x0-1, "Create new Identity");
    mvaddstr(gui->y0, gui->x0+1, buf);

    /* Window Body */
    pos = editline_pos(newid_edit[cursor_newid]);
    editline_char(newid_edit[cursor_newid], &ch);
    if(!*ch)
        c = ' ';
    else
        c = *ch;

    attrset(COLOR_PAIR(0));

    snprintf(buf, 250, "%199.199s", " ");
    mvaddnstr(gui->y0+1, gui->x0, buf, (x-gui->x0-1));
    mvaddnstr(gui->y0+2, gui->x0, buf, (x-gui->x0-1));
    mvaddnstr(gui->y0+3, gui->x0, buf, (x-gui->x0-1));
    mvaddnstr(gui->y0+4, gui->x0, buf, (x-gui->x0-1));
    mvaddnstr(gui->y0+5, gui->x0, buf, (x-gui->x0-1));

    if(cursor_newid == NEWID_FULLNAME)
        attrset(COLOR_PAIR(10));
    else
        attrset(COLOR_PAIR(1));

    snprintf(buf, 250, "%29.29s", "Full name :");
    mvaddstr(gui->y0+1, gui->x0, buf);

    if(cursor_newid == NEWID_BOOKLOC)
        attrset(COLOR_PAIR(10));
    else
        attrset(COLOR_PAIR(1));

    snprintf(buf, 250, "%29.29s", "Phonebook location:");
    mvaddstr(gui->y0+2, gui->x0, buf);

    if(cursor_newid == NEWID_REGISTARY)
        attrset(COLOR_PAIR(10));
    else
        attrset(COLOR_PAIR(1));

    snprintf(buf, 250, "%29.29s", "Register server :");
    mvaddstr(gui->y0+3, gui->x0, buf);

    if(cursor_newid == NEWID_REGNAME)
        attrset(COLOR_PAIR(10));
    else
        attrset(COLOR_PAIR(1));

    snprintf(buf, 250, "%29.29s", "Register name :");
    mvaddstr(gui->y0+4, gui->x0, buf);

    if(cursor_newid == NEWID_REGSEC)
        attrset(COLOR_PAIR(10));
    else
        attrset(COLOR_PAIR(1));

    snprintf(buf, 250, "%29.29s", "Register period in seconds :");
    mvaddstr(gui->y0+5, gui->x0, buf);

    if(ocui->edit_profile)
    {
        char seconds[10];

        snprintf(seconds, 10, "%d", ocui->edit_profile->seconds);

        editline_set_line(newid_edit[NEWID_FULLNAME], ocui->edit_profile->fullname, ocui->edit_profile->fbyte);
        editline_set_line(newid_edit[NEWID_BOOKLOC], ocui->edit_profile->book_location, strlen(ocui->edit_profile->book_location));
        editline_set_line(newid_edit[NEWID_REGISTARY], ocui->edit_profile->registrar, strlen(ocui->edit_profile->registrar));
        editline_set_line(newid_edit[NEWID_REGNAME], ocui->edit_profile->regname, strlen(ocui->edit_profile->regname));
        editline_set_line(newid_edit[NEWID_REGSEC], seconds, strlen(seconds));
    }
    else if(ocui->clear_profile)
    {
        editline_clear(newid_edit[NEWID_FULLNAME]);

        editline_clear(newid_edit[NEWID_BOOKLOC]);
        editline_clear(newid_edit[NEWID_REGISTARY]);
        editline_clear(newid_edit[NEWID_REGNAME]);
        editline_clear(newid_edit[NEWID_REGSEC]);

        ocui->clear_profile = 0;
    }

    attrset(COLOR_PAIR(0));
    mvaddstr(gui->y0+1, gui->x0+30, newid_inputs[NEWID_FULLNAME]);

    attrset(COLOR_PAIR(0));
    mvaddstr(gui->y0+2, gui->x0+30, newid_inputs[NEWID_BOOKLOC]);

    attrset(COLOR_PAIR(0));
    mvaddstr(gui->y0+3, gui->x0+30, newid_inputs[NEWID_REGISTARY]);

    attrset(COLOR_PAIR(0));
    mvaddstr(gui->y0+4, gui->x0+30, newid_inputs[NEWID_REGNAME]);

    attrset(COLOR_PAIR(0));
    mvaddstr(gui->y0+5, gui->x0+30, newid_inputs[NEWID_REGSEC]);

    attrset(COLOR_PAIR(10));
    mvaddch(gui->y0+1+cursor_newid, gui->x0+30+pos, c);

    gui->gui_draw_commands(gui);

    return 0;
}