/*
  * The ability field is read-only
  */
 int
 get_abil(void *vp, WINDOW *win)
 {
	 int *abil = (int *) vp;
     register int oy, ox, ny, nx;
     register int op_bad;
 
     op_bad = TRUE;
     getyx(win, oy, ox);
     put_abil(abil, win);
     getyx(win, ny, nx);
     while(op_bad)	
     {
 	wmove(win, oy, ox);
 	draw(win);
 	switch (readchar(win))
 	{
 	    case '\n':
 	    case '\r':
 		op_bad = FALSE;
 		break;
 	    case '\033':
 	    case '\007':
 		return QUIT;
 	    case '-':
 		return MINUS;
 	    default:
 		mvwaddstr(win, ny, nx + 5, "(no change allowed)");
 	}
     }
     wmove(win, ny, nx + 5);
     wclrtoeol(win);
     wmove(win, ny, nx);
     waddch(win, '\n');
     return NORM;
 }
Ejemplo n.º 2
0
/*
 * Print a new line of text. Called by dialog_textbox() and print_page().
 */
static void
print_line (WINDOW * win, int row, int width)
{
    int y, x;
    char *line;

    line = get_line ();
    line += MIN (strlen (line), hscroll);	/* Scroll horizontally */
    wmove (win, row, 0);	/* move cursor to correct line */
    waddch (win, ' ');
    waddnstr (win, line, MIN (strlen (line), width - 2));

    getyx (win, y, x);
    /* Clear 'residue' of previous line */
#if OLD_NCURSES
    {
	int i;
	for (i = 0; i < width - x; i++)
	    waddch (win, ' ');
    }
#else
    wclrtoeol(win);
#endif
}
Ejemplo n.º 3
0
static void lua_paint_info(struct window *wnd, const struct state *st)
{
    struct lua_State *L = paint_state;
    int nx = st->cursor.x, ny = st->cursor.y;
    pnormalize(&nx, &ny, st->cursor.pl);
    lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
    lua_pushinteger(L, nx);
    lua_pushinteger(L, ny);
    if (lua_pcall(L, 2, 1, 0) != 0) {
        const char *error = lua_tostring(L, -1);
        log_error("paint function failed: %s\n", error);
        lua_pop(L, 1);
        tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
    }
    else {
        const char *result = lua_tostring(L, -1);
        WINDOW *win = wnd->handle;
        int size = getmaxx(win) - 2;
        int line = 0, maxline = getmaxy(win) - 2;
        const char *str = result;
        wxborder(win);

        while (*str && line < maxline) {
            const char *end = strchr(str, '\n');
            if (!end)
                break;
            else {
                int bytes = (int)(end - str);
                if (bytes < size) bytes = size;
                mvwaddnstr(win, line++, 1, str, bytes);
                wclrtoeol(win);
                str = end + 1;
            }
        }
    }
}
Ejemplo n.º 4
0
void padTest(WINDOW *dummy)
{
    WINDOW *pad, *spad;

    pad = newpad(50, 100);
    wattron(pad, A_REVERSE);
    mvwaddstr(pad, 5, 2, "This is a new pad");
    wattrset(pad, 0);
    mvwaddstr(pad, 8, 0,
        "The end of this line should be truncated here:except  now");
    mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
    wmove(pad, 10, 1);
    wclrtoeol(pad);
    mvwaddstr(pad, 10, 1, " Press any key to continue");
    prefresh(pad, 0, 0, 0, 0, 10, 45);
    keypad(pad, TRUE);
    raw();
    wgetch(pad);

    spad = subpad(pad, 12, 25, 7, 52);
    mvwaddstr(spad, 2, 2, "This is a new subpad");
    box(spad, 0, 0);
    prefresh(pad, 0, 0, 0, 0, 15, 75);
    keypad(pad, TRUE);
    raw();
    wgetch(pad);

    mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
    mvwaddstr(pad, 40, 1, " Press any key to continue");
    prefresh(pad, 30, 0, 0, 0, 10, 45);
    keypad(pad, TRUE);
    raw();
    wgetch(pad);

    delwin(pad);
}
Ejemplo n.º 5
0
/* Update status and title window. */
static bool
update_status_window(struct view *view, const char *context, const char *msg, va_list args)
{
	if (input_mode)
		return false;

	if (!status_empty || *msg) {
		wmove(status_win, 0, 0);
		if (view && view->has_scrolled && use_scroll_status_wclear)
			wclear(status_win);
		if (*msg) {
			vwprintw(status_win, msg, args);
			status_empty = false;
		} else {
			status_empty = true;
		}
		wclrtoeol(status_win);

		if (context && *context) {
			size_t contextlen = strlen(context);
			int x, y, width, ___;

			getyx(status_win, y, x);
			getmaxyx(status_win, ___, width);
			(void) ___;
			if (contextlen < width - x) {
				mvwprintw(status_win, 0, width - contextlen, "%s", context);
				wmove(status_win, y, x);
			}
		}

		return true;
	}

	return false;
}
Ejemplo n.º 6
0
static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
{
  uint64_t offset=0;
  unsigned int nbr_subdir=0;
  sector_cluster_t sector_cluster[10];
  alloc_data_t *current_search_space;
  unsigned char *buffer_start=(unsigned char *)MALLOC(READ_SIZE);
  unsigned char *buffer=buffer_start;
  current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
  if(current_search_space!=list_search_space)
    offset=current_search_space->start;
  if(verbose>0)
    info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, verbose);
#ifdef HAVE_NCURSES
  wmove(stdscr,22,0);
  wattrset(stdscr, A_REVERSE);
  waddstr(stdscr,"  Stop  ");
  wattroff(stdscr, A_REVERSE);
#endif
  disk->pread(disk, buffer_start, READ_SIZE, offset);
  while(current_search_space!=list_search_space && nbr_subdir<10)
  {
    const uint64_t old_offset=offset;
#ifdef HAVE_NCURSES
    if((offset&(1024*disk->sector_size-1))==0)
    {
      wmove(stdscr,9,0);
      wclrtoeol(stdscr);
      wprintw(stdscr,"Search subdirectory %10lu/%lu %u",(unsigned long)(offset/disk->sector_size),(unsigned long)(partition->part_size/disk->sector_size),nbr_subdir);
      wrefresh(stdscr);
    }
#endif
    if(memcmp(buffer,         ".          ", 8+3)==0 &&
	memcmp(&buffer[0x20], "..         ", 8+3)==0)
    {
      const unsigned long int cluster=(buffer[0*0x20+0x15]<<24) + (buffer[0*0x20+0x14]<<16) +
	(buffer[0*0x20+0x1B]<<8) + buffer[0*0x20+0x1A];
      log_info("sector %lu, cluster %lu\n",
	  (unsigned long)(offset/disk->sector_size), cluster);
      sector_cluster[nbr_subdir].cluster=cluster;
      sector_cluster[nbr_subdir].sector=offset/disk->sector_size;
      log_flush();
      nbr_subdir++;
    }
    get_next_sector(list_search_space, &current_search_space, &offset, 512);
    buffer+=512;
    if( old_offset+512!=offset ||
        buffer+512>buffer_start+READ_SIZE)
    {
      buffer=buffer_start;
      if(verbose>1)
      {
        log_verbose("Reading sector %10llu/%llu\n",
	    (unsigned long long)((offset-partition->part_offset)/disk->sector_size),
	    (unsigned long long)((partition->part_size-1)/disk->sector_size));
      }
      if(disk->pread(disk, buffer_start, READ_SIZE, offset) != READ_SIZE)
      {
      }
    }
  } /* end while(current_search_space!=list_search_space) */
  free(buffer_start);
  return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size, UP_UNK);
}
Ejemplo n.º 7
0
/*
* lome6 periodical timer function for display and one wire convert command
*
* if onewire is supported start onewire temperature convert
* if lcd is supported display various information
*/
void lome6_timer(void) {

#ifdef LOME6_ONEWIRE_SUPPORT
	// read 1w temperatures
	iTemperaturePSU = lome6_get_temperature(&romcodePSU);
	iTemperatureAIR = lome6_get_temperature(&romcodeAIR);
	iTemperatureRAM = lome6_get_temperature(&romcodeRAM);
#endif // LOME6_ONEWIRE_SUPPORT

#ifdef LOME6_LCD_SUPPORT
	wclear(ttyWindow);
	
	if (iLCDPage == 0) {

		// display uptime and date+time
		uint32_t working_hours = (clock_get_time() - clock_get_startup()) / 60;

		struct clock_datetime_t datetime;
		clock_current_localtime(&datetime);

		wprintw_P(ttyWindow, PSTR("%02d:%02d %02d.%02d.%04d"), datetime.hour, datetime.min, datetime.day, datetime.month, (datetime.year + 1900));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("Uptime: %02lu:%02d"), working_hours / 60, working_hours % 60);
		wclrtoeol(ttyWindow);
		
#ifndef LOME6_ONEWIRE_SUPPORT
		if (!PIN_HIGH(POWER_STATE))
			iLCDPage = 4;
		else
			iLCDPage = 0;
#else
		iLCDPage++;
#endif

#ifdef LOME6_ONEWIRE_SUPPORT
	} else if (iLCDPage == 1) {

		// display onewire temperature sensor data
		wprintw_P(ttyWindow, PSTR("Temperature"));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("AIR: %02d.%d"), iTemperatureAIR / 10, iTemperatureAIR % 10);
		wclrtoeol(ttyWindow);

		iLCDPage++;

	} else if (iLCDPage == 2) {

		// display onewire temperature sensor data
		wprintw_P(ttyWindow, PSTR("Temperature:"));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("RAM: %02d.%d"), iTemperatureRAM / 10, iTemperatureRAM % 10);
		wclrtoeol(ttyWindow);

		iLCDPage++;

	} else if (iLCDPage == 3) {

		// display onewire temperature sensor data
		wprintw_P(ttyWindow, PSTR("Temperature"));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("PSU: %02d.%d"), iTemperaturePSU / 10, iTemperaturePSU % 10);
		wclrtoeol(ttyWindow);

		iLCDPage++;

#endif //LOME6_ONEWIRE_SUPPORT
	} else if (iLCDPage == 4) {
	
		// display temperature data
		wprintw_P(ttyWindow, PSTR("Temperature"));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("CPU: %02d.%d"), iTemperatureCPU / 10, iTemperatureCPU % 10);
		wclrtoeol(ttyWindow);
		iLCDPage++;

	} else if (iLCDPage == 5) {

		// display temperature data
		wprintw_P(ttyWindow, PSTR("Temperature"));
		wclrtoeol(ttyWindow);
		wmove(ttyWindow, 1, 0);
		wprintw_P(ttyWindow, PSTR("SB: %02d.%d"), iTemperatureSB / 10, iTemperatureSB % 10);
		wclrtoeol(ttyWindow);
		iLCDPage = 0;

	}

	// start a new convert in next round
	ow_temp_start_convert_nowait(NULL);
#endif // LOME6_LCD_SUPPORT

}
Ejemplo n.º 8
0
/*
 * Display a symbol on somebody's window, processing some control
 * characters while we are at it.
 */
void
display(xwin_t *win, wchar_t *wc)
{

	/*
	 * Alas, can't use variables in C switch statement.
	 * Workaround these 3 cases with goto.
	 */
	if (*wc == win->kill)
		goto kill;
	else if (*wc == win->cerase)
		goto cerase;
	else if (*wc == win->werase)
		goto werase;

	switch (*wc) {
	case L'\n':
	case L'\r':
		wadd_wch(win->x_win, makecchar(L'\n'));
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case 004:
		if (win == &my_win) {
			/* Ctrl-D clears the screen. */
			werase(my_win.x_win);
			getyx(my_win.x_win, my_win.x_line, my_win.x_col);
			wrefresh(my_win.x_win);
			werase(his_win.x_win);
			getyx(his_win.x_win, his_win.x_line, his_win.x_col);
			wrefresh(his_win.x_win);
		}
		return;

	/* Erase character. */
	case 010:	/* BS */
	case 0177:	/* DEL */
cerase:
		wmove(win->x_win, win->x_line, max(--win->x_col, 0));
		getyx(win->x_win, win->x_line, win->x_col);
		waddch(win->x_win, ' ');
		wmove(win->x_win, win->x_line, win->x_col);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case 027:	/* ^W */
werase:
	    {
		/*
		 * On word erase search backwards until we find
		 * the beginning of a word or the beginning of
		 * the line.
		 */
		int endcol, xcol, c;

		endcol = win->x_col;
		xcol = endcol - 1;
		while (xcol >= 0) {
			c = readwin(win->x_win, win->x_line, xcol);
			if (c != ' ')
				break;
			xcol--;
		}
		while (xcol >= 0) {
			c = readwin(win->x_win, win->x_line, xcol);
			if (c == ' ')
				break;
			xcol--;
		}
		wmove(win->x_win, win->x_line, xcol + 1);
		for (int i = xcol + 1; i < endcol; i++)
			waddch(win->x_win, ' ');
		wmove(win->x_win, win->x_line, xcol + 1);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;
	    }

	case 025:	/* ^U */
kill:
		wmove(win->x_win, win->x_line, 0);
		wclrtoeol(win->x_win);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case L'\f':
		if (win == &my_win)
			wrefresh(curscr);
		return;

	case L'\7':
		write(STDOUT_FILENO, wc, sizeof(*wc));
		return;
	}


	if (iswprint(*wc) || *wc == L'\t')
		wadd_wch(win->x_win, makecchar(*wc));
	else
		beep();

	getyx(win->x_win, win->x_line, win->x_col);
	wrefresh(win->x_win);
}
Ejemplo n.º 9
0
int dialog_inputbox(WINDOW *main_window,
		const char *title, const char *prompt,
		const char *init, char *result, int result_len)
{
	int prompt_lines = 0;
	int prompt_width = 0;
	WINDOW *win;
	WINDOW *prompt_win;
	WINDOW *form_win;
	PANEL *panel;
	int i, x, y;
	int res = -1;
	int cursor_position = strlen(init);


	/* find the widest line of msg: */
	prompt_lines = get_line_no(prompt);
	for (i = 0; i < prompt_lines; i++) {
		const char *line = get_line(prompt, i);
		int len = get_line_length(line);
		prompt_width = max(prompt_width, len);
	}

	if (title)
		prompt_width = max(prompt_width, strlen(title));

	/* place dialog in middle of screen */
	y = (LINES-(prompt_lines+4))/2;
	x = (COLS-(prompt_width+4))/2;

	strncpy(result, init, result_len);

	/* create the windows */
	win = newwin(prompt_lines+6, prompt_width+7, y, x);
	prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2);
	form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
	keypad(form_win, TRUE);

	wattrset(form_win, attributes[INPUT_FIELD]);

	wattrset(win, attributes[INPUT_BOX]);
	box(win, 0, 0);
	wattrset(win, attributes[INPUT_HEADING]);
	if (title)
		mvwprintw(win, 0, 3, "%s", title);

	/* print message */
	wattrset(prompt_win, attributes[INPUT_TEXT]);
	fill_window(prompt_win, prompt);

	mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
	mvwprintw(form_win, 0, 0, "%s", result);

	/* create panels */
	panel = new_panel(win);

	/* show the cursor */
	curs_set(1);

	touchwin(win);
	refresh_all_windows(main_window);
	while ((res = wgetch(form_win))) {
		int len = strlen(result);
		switch (res) {
		case 10: /* ENTER */
		case 27: /* ESCAPE */
		case KEY_F(F_HELP):
		case KEY_F(F_EXIT):
		case KEY_F(F_BACK):
			break;
		case 127:
		case KEY_BACKSPACE:
			if (cursor_position > 0) {
				memmove(&result[cursor_position-1],
						&result[cursor_position],
						len-cursor_position+1);
				cursor_position--;
			}
			break;
		case KEY_DC:
			if (cursor_position >= 0 && cursor_position < len) {
				memmove(&result[cursor_position],
						&result[cursor_position+1],
						len-cursor_position+1);
			}
			break;
		case KEY_UP:
		case KEY_RIGHT:
			if (cursor_position < len &&
			    cursor_position < min(result_len, prompt_width))
				cursor_position++;
			break;
		case KEY_DOWN:
		case KEY_LEFT:
			if (cursor_position > 0)
				cursor_position--;
			break;
		default:
			if ((isgraph(res) || isspace(res)) &&
					len-2 < result_len) {
				/* insert the char at the proper position */
				memmove(&result[cursor_position+1],
						&result[cursor_position],
						len+1);
				result[cursor_position] = res;
				cursor_position++;
			} else {
				mvprintw(0, 0, "unknow key: %d\n", res);
			}
			break;
		}
		wmove(form_win, 0, 0);
		wclrtoeol(form_win);
		mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
		mvwprintw(form_win, 0, 0, "%s", result);
		wmove(form_win, 0, cursor_position);
		touchwin(win);
		refresh_all_windows(main_window);

		if (res == 10) {
			res = 0;
			break;
		} else if (res == 27 || res == KEY_F(F_BACK) ||
				res == KEY_F(F_EXIT)) {
			res = KEY_EXIT;
			break;
		} else if (res == KEY_F(F_HELP)) {
			res = 1;
			break;
		}
	}

	/* hide the cursor */
	curs_set(0);
	del_panel(panel);
	delwin(prompt_win);
	delwin(form_win);
	delwin(win);
	return res;
}
Ejemplo n.º 10
0
void inputTest(WINDOW *win)
{
    int w, h, bx, by, sw, sh, i, c, num = 0;
    int line_to_use = 3;
    char buffer[80];
    WINDOW *subWin;
    static const char spinner[4] = "/-\\|";
    int spinner_count = 0;

    wclear(win);

    getmaxyx(win, h, w);
    getbegyx(win, by, bx);

    sw = w / 3;
    sh = h / 3;

    if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))
        == NULL)
        return;

#ifdef A_COLOR
    if (has_colors())
    {
        init_pair(2, COLOR_WHITE, COLOR_RED);
        wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
    }
    else
#endif
        wbkgd(subWin, A_BOLD);

    box(subWin, ACS_VLINE, ACS_HLINE);
    wrefresh(win);

    nocbreak();

    wclear (win);
    mvwaddstr(win, 1, 1,
        "Press keys (or mouse buttons) to show their names");
    mvwaddstr(win, 2, 1, "Press spacebar to finish");
    wrefresh(win);

    keypad(win, TRUE);
    raw();
    noecho();

    wtimeout(win, 200);

#ifdef PDCURSES
    mouse_set(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION);
    PDC_save_key_modifiers(TRUE);
//  PDC_return_key_modifiers(TRUE);
#endif
    curs_set(0);        /* turn cursor off */

    while (1)
    {
        while (1)
        {
            c = wgetch(win);

            if (c == ERR)
            {
                spinner_count++;
                if (spinner_count == 4)
                    spinner_count = 0;
                mvwaddch(win, line_to_use, 3, spinner[spinner_count]);
                wrefresh(win);
            }
            else
                break;
        }
#ifdef PDCURSES
//      wmove(win, line_to_use + 1, 18);
//      wclrtoeol(win);
#endif
        mvwaddstr(win, line_to_use, 5, "Key Pressed: ");
        wclrtoeol(win);

        wprintw( win, "(%x) ", c);
        if( has_key( c))
            wprintw(win, "%s", keyname(c));
        else if (isprint(c) || c > 0xff)
            waddch( win, c);
        else
            wprintw(win, "%s", unctrl(c));
#ifdef PDCURSES
        if (c == KEY_MOUSE)
        {
            int button = 0, status = 0;
            request_mouse_pos();

            if (BUTTON_CHANGED(1))
                button = 1;
            else if (BUTTON_CHANGED(2))
                button = 2;
            else if (BUTTON_CHANGED(3))
                button = 3;
            else if (BUTTON_CHANGED(4))   /* added 21 Jan 2011: BJG */
                button = 4;
            else if (BUTTON_CHANGED(5))
                button = 5;
            if( button)
                status = (button > 3 ? Mouse_status.xbutton[(button) - 4] :
                                       Mouse_status.button[(button) - 1]);

            wmove(win, line_to_use, 5);
            wclrtoeol(win);
            wprintw(win, "Button %d: ", button);

            if (MOUSE_MOVED)
                waddstr(win, "moved: ");
            else if (MOUSE_WHEEL_UP)
                waddstr(win, "wheel up: ");
            else if (MOUSE_WHEEL_DOWN)
                waddstr(win, "wheel dn: ");
            else if (MOUSE_WHEEL_LEFT)
                waddstr(win, "wheel lt: ");
            else if (MOUSE_WHEEL_RIGHT)
                waddstr(win, "wheel rt: ");
            else if ((status & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
                waddstr(win, "pressed: ");
            else if ((status & BUTTON_ACTION_MASK) == BUTTON_CLICKED)
                waddstr(win, "clicked: ");
            else if ((status & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
                waddstr(win, "double: ");
            else if ((status & BUTTON_ACTION_MASK) == BUTTON_TRIPLE_CLICKED)
                waddstr(win, "triple: ");
            else
                waddstr(win, "released: ");

            wprintw(win, "Posn: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
            if (button && (status & BUTTON_MODIFIER_MASK))
            {
                if (status & BUTTON_SHIFT)
                    waddstr(win, " SHIFT");

                if (status & BUTTON_CONTROL)
                    waddstr(win, " CONTROL");

                if (status & BUTTON_ALT)
                    waddstr(win, " ALT");
            }

        }
        else if (PDC_get_key_modifiers())
        {
            waddstr(win, " Modifier(s):");
            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT)
                waddstr(win, " SHIFT");

            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL)
                waddstr(win, " CONTROL");

            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT)
                waddstr(win, " ALT");

            if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK)
                waddstr(win, " NUMLOCK");
        }
#endif
        wrefresh(win);

        if (c == ' ')
            break;
        line_to_use++;
        if( line_to_use == 10)
           line_to_use = 3;
    }

    wtimeout(win, -1);  /* turn off timeout() */
    curs_set(1);        /* turn cursor back on */

#ifdef PDCURSES
    mouse_set(0L);
    PDC_save_key_modifiers(FALSE);
//  PDC_return_key_modifiers(FALSE);
#endif
    wclear(win);
    mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
    mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
    wrefresh(win);

    werase(subWin);
    box(subWin, ACS_VLINE, ACS_HLINE);

    for (i = 0; i < 5; i++)
    {
        mvwprintw(subWin, 1, 1, "Time = %d", i);
        wrefresh(subWin);
        napms(1000);
        flushinp();
    }

    delwin(subWin);
    werase(win);
    flash();
    wrefresh(win);
    napms(500);
    flushinp();

    mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
    wmove(win, 9, 10);
    wrefresh(win);
    echo();

    keypad(win, TRUE);
    raw();
    wgetnstr(win, buffer, 3);
    flushinp();

    wmove(win, 9, 10);
    wdelch(win);
    mvwaddstr(win, 4, 1, "The character should now have been deleted");
    Continue(win);

    refresh();
    wclear(win);
    echo();
    buffer[0] = '\0';
    mvwaddstr(win, 3, 2, "The window should have moved");
    mvwaddstr(win, 4, 2,
              "This text should have appeared without you pressing a key");
    mvwaddstr(win, 6, 2, "Enter a number then a string separated by space");
    mvwin(win, 2, 1);
    wrefresh(win);
    mvwscanw(win, 7, 6, "%d %s", &num, buffer);
    mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num);
    Continue(win);

    refresh();
    wclear(win);
    echo();
    mvwaddstr(win, 3, 2, "Enter a 5 character string: ");
    wgetnstr(win, buffer, 5);
    mvwprintw(win, 4, 2, "String: %s", buffer);
    Continue(win);
}
Ejemplo n.º 11
0
void main_set_status_text(char *txt)
{
	mvwprintw(status_wnd, 0, 0, txt);
	wclrtoeol(status_wnd);
	wrefresh(status_wnd);
}
Ejemplo n.º 12
0
/*         sonst i8086_ERR_ILGOPCODE              */
int printCode(i8086core *core, i8086command **cmds, codeView *cv)
{
  unsigned char opcode, i, pos, read=0;
  //unsigned char dispLn=0;
  //i8086Parameter para, data;
  //unsigned char str[6];
  //unsigned short ret=0;
  unsigned short startAdr;
  unsigned short cs;
  unsigned char *cmddata;
  char *output;
  unsigned char cmdsize;

   if (args & HIDE_CODE_VIEWER) /* pruefen ob Codeviewer aktiviert ist */
    return i8086_SUC_EXECCMD;

  cs = i8086GetSegRegister_fast(core, i8086_REG_CS, 1);

  if ( (core->pc+cs > cv->endAdr) || (core->pc+cs < cv->startAdr) ) /* Viewersegment setzen */
    startAdr = core->pc+cs;                                 /* pc ist ueber bzw. unter Windowgrenzen gekommen */
  else
    startAdr = cv->startAdr;

  for (pos=0; pos<16; pos++)
  {
    opcode = core->mem[startAdr+read];         /* opcode lesen     */

    if (core->pc+cs==startAdr+read)               /* aktuellen OpCode sichtbar machen */
    {
      wattron(codeWin, A_STANDOUT);
    }

    if (startAdr+read==breakpoint)
    mvwprintw(codeWin, 1+pos, 1, ".");
    else
    mvwprintw(codeWin, 1+pos, 1, " ");
    mvwprintw(codeWin, 1+pos, 2, "%0004x", startAdr+read); /* Adressen ausgeben */
    wclrtoeol(codeWin);
    wattroff(codeWin, A_STANDOUT);

    if (cmds[opcode]==NULL)                    /* illegaler Opcode */
    {
      int j;
      //sprintf(str, "%hd", opcode);
      //i8086error(i8086_ERR_STR_ILGOPCODE, str);
      mvwprintw(codeWin, 1+pos, 7, "%s", "ILGOPC"); /* Befehlname ausgeben */
      for (j=pos+2; j<17; j++) /* folgende Zeilen loeschen. */
      {
        wmove(codeWin, j, 2);
        wclrtoeol(codeWin);
      }
      box(codeWin, ACS_VLINE, ACS_HLINE);
      mvwprintw(codeWin, 0, 2, "[Code]");
      wrefresh(codeWin);
      return i8086_ERR_ILGOPCODE;
    }

	cmddata=malloc(10);
	output=malloc(40);
    	cmddata[0]=opcode;
	cmdsize=cmds[opcode]->size;

	for (i=1; i<cmdsize; i++)            /* Parameter byteweise einlesen */
	{
      		cmddata[i] = core->mem[startAdr+read+i];
    	}

	if (cmds[opcode]->hasMod!=0)
	{
		cmdsize+=getAdditionalCmdLength(core, opcode, cmddata[1]);

		for (i=cmds[opcode]->size; i<cmdsize; i++)            /* Parameter byteweise einlesen */
		{
	     		cmddata[i] = core->mem[startAdr+read+i];
	    	}
	}

 	disasm (cmddata, output, 16, startAdr+read, 0, 0);;
	mvwprintw(codeWin, 1+pos, 7, "%s",  output);

	free(output);
	free(cmddata);

	read+=cmdsize;

	if (pos == 14)
		cv->endAdr = startAdr+read;       /* Endadresse fuer naechsten Durchlauf setzen */

    //mvwprintw(codeWin, 1+pos, 7, "%s", cmds[opcode]->name); /* Befehlname ausgeben */
  }


  cv->startAdr = startAdr;              /* Startadresse fuer naechsten Durchlauf setzen */
  box(codeWin, ACS_VLINE, ACS_HLINE);
  mvwprintw(codeWin, 0, 2, "[Code]");
  wrefresh(codeWin);

  return i8086_SUC_EXECCMD;
}
Ejemplo n.º 13
0
static void interface_editor_ncurses(disk_t *disk)
{
  int done = 0;
  uint64_t hd_offset=0;
  unsigned char *buffer=(unsigned char *)MALLOC(disk->sector_size);
  log_info("%s\n",disk->description(disk));
  aff_copy(stdscr);
  wmove(stdscr,4,0);
  wprintw(stdscr,"%s", disk->description_short(disk));
  while (done==0)
  {
    static const struct MenuItem menuEditor[]=
    {
      { 'C', "Change location", "" },
      { 'D', "Dump", "Dump sector" },
      { 'Q', "Quit",""},
      { 0, NULL, NULL }
    };
    switch ( wmenuSelect(stdscr, INTER_EDIT_Y+1, INTER_EDIT_Y, INTER_EDIT_X, menuEditor, 8, "CDQ", MENU_HORIZ | MENU_BUTTON, 0))
    {
      case 'c':
      case 'C':
	interface_editor_location(disk,&hd_offset);
	break;
      case 'd':
      case 'D':
	{
	  int menu_pos=KEY_DOWN;
	  while(done==0)
	  {
	    wmove(stdscr,5,0);
	    wclrtoeol(stdscr);
	    wprintw(stdscr,"%lu ", (unsigned long)(hd_offset/disk->sector_size));
	    aff_LBA2CHS(disk, hd_offset/disk->sector_size);
	    if((unsigned)disk->pread(disk, buffer, disk->sector_size, hd_offset) != disk->sector_size)
	    {
	      wprintw(stdscr,msg_PART_RD_ERR);
	    }
	    {
	      menu_pos=dump_editor(buffer, disk->sector_size, menu_pos);
	      switch(menu_pos)
	      {
		case KEY_UP:
		  if(hd_offset>0)
		    hd_offset-=disk->sector_size;
		  else
		    menu_pos=KEY_DOWN;
		  break;
		case KEY_DOWN:
		  if(hd_offset<disk->disk_size)
		    hd_offset+=disk->sector_size;
		  else
		    menu_pos=KEY_UP;
		  break;
		default:
		  done = 1;
		  break;
	      }
	    }
	  }
	  done = 0;
	}
	break;
      case key_ESC:
      case 'q':
      case 'Q':
	done = 1;
	break;
    }
  }
  free(buffer);
}
Ejemplo n.º 14
0
static int dump_editor(const unsigned char *nom_dump,const unsigned int lng, const int menu_pos)
{
  unsigned int pos;
  int done=0;
  unsigned int menu;
  const struct MenuItem menuDump[]=
  {
	{ 'P', "Previous",""},
	{ 'N', "Next","" },
	{ 'Q',"Quit","Quit dump section"},
	{ 0, NULL, NULL }
  };
  /* write dump to log file*/
  dump_log(nom_dump, lng);
  /* ncurses interface */
  pos=(menu_pos==KEY_DOWN?0:lng/0x10-EDIT_MAX_LINES);
  menu=(menu_pos==KEY_DOWN?1:0);
  mvwaddstr(stdscr, EDIT_Y, EDIT_X, msg_DUMP_HEXA);
  do
  {
    	unsigned int i,j;
  	unsigned char car;
	for (i=pos; (i<lng/0x10)&&((i-pos)<EDIT_MAX_LINES); i++)
	{
	  wmove(stdscr,EDIT_Y+i-pos,EDIT_X);
	  wclrtoeol(stdscr);
	  wprintw(stdscr,"%04X ",i*0x10);
	  for(j=0; j< 0x10;j++)
	  {
		car=*(nom_dump+i*0x10+j);
		wprintw(stdscr,"%02x", car);
		if(j%4==(4-1))
		  wprintw(stdscr," ");
	  }
	  wprintw(stdscr,"  ");
	  for(j=0; j< 0x10;j++)
	  {
		car=*(nom_dump+i*0x10+j);
		if ((car<32)||(car >= 127))
		  wprintw(stdscr,".");
		else
		  wprintw(stdscr,"%c",  car);
	  }
	}
	switch (wmenuSelect(stdscr, INTER_EDIT_Y+1, INTER_EDIT_Y, INTER_EDIT_X, menuDump, 8, "PNQ", MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu))
	{
	  case 'p':
	  case 'P':
	  case KEY_UP:
		menu=0;
		if(pos>0)
		  pos--;
		else
		  done=KEY_UP;
		break;
	  case 'n':
	  case 'N':
	  case KEY_DOWN:
		menu=1;
		if(pos<lng/0x10-EDIT_MAX_LINES)
		  pos++;
		else
		  done = KEY_DOWN;
		break;
	  case KEY_PPAGE:
		menu=0;
		if(pos==0)
		  done=KEY_UP;
		if(pos>EDIT_MAX_LINES-1)
		  pos-=EDIT_MAX_LINES-1;
		else
		  pos=0;
		break;
	  case KEY_NPAGE:
		menu=1;
		if(pos==lng/0x10-EDIT_MAX_LINES)
		  done=KEY_DOWN;
		if(pos<lng/0x10-EDIT_MAX_LINES-(EDIT_MAX_LINES-1))
		  pos+=EDIT_MAX_LINES-1;
		else
		  pos=lng/0x10-EDIT_MAX_LINES;
		break;
	  case key_ESC:
	  case 'q':
	  case 'Q':
		done = 'Q';
		break;
	}
  } while(done==0);
  return done;
}
Ejemplo n.º 15
0
static void interface_editor_location(const disk_t *disk, uint64_t *lba)
{
  const struct MenuItem menuGeometry[]=
  {
    { 'c', "Cylinders", "Change cylinder" },
    { 'h', "Heads", "Change head" },
    { 's', "Sectors", "Change sector" },
    { 'l', "Logical Sectors", "Change logical sector" },
    { 'd', "Done", "Done with changing" },
    { 0, NULL, NULL }
  };
  int default_option=4;
  while (1)
  {
    CHS_t location;
    char def[128];
    char response[128];
    unsigned long int tmp_val;
    int command;
    wmove(stdscr,5,0);
    wclrtoeol(stdscr);
    wprintw(stdscr,"%lu ", (unsigned long)(*lba/disk->sector_size));
    aff_LBA2CHS(disk, *lba / disk->sector_size);
    offset2CHS(disk, *lba, &location);
    wmove(stdscr,INTER_GEOM_Y, INTER_GEOM_X);
    wclrtoeol(stdscr);
    wrefresh(stdscr);
    command=wmenuSimple(stdscr, menuGeometry, default_option);
    switch (command) {
      case 'c':
      case 'C':
	sprintf(def, "%lu", location.cylinder);
	mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: ");
	if (get_string(stdscr, response, sizeof(response), def) > 0) {
	  tmp_val = atol(response);
	  if (tmp_val < disk->geom.cylinders) {
	    location.cylinder = tmp_val;
	    *lba=CHS2offset(disk,&location);
	  } else
	    wprintw(stdscr,"Illegal cylinders value");
	}
	default_option=1;
	break;
      case 'h':
      case 'H':
	sprintf(def, "%u", location.head);
	mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: ");
	if (get_string(stdscr, response, sizeof(response), def) > 0) {
	  tmp_val = atoi(response);
	  if (tmp_val < disk->geom.heads_per_cylinder) {
	    location.head = tmp_val;
	    *lba=CHS2offset(disk,&location);
	  } else
	    wprintw(stdscr,"Illegal heads value");
	}
	default_option=2;
	break;
      case 's':
      case 'S':
	sprintf(def, "%u", location.sector);
	mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track: ");
	if (get_string(stdscr, response, sizeof(response), def) > 0) {
	  tmp_val = atoi(response);
	  if (tmp_val > 0 && tmp_val <= disk->geom.sectors_per_head ) {
	    location.sector = tmp_val;
	    *lba=CHS2offset(disk,&location);
	  } else
	    wprintw(stdscr,"Illegal sectors value");
	}
	default_option=3;
	break;
      case 'l':
      case 'L':
	{
	  sprintf(def, "%lu", (unsigned long)(*lba / disk->sector_size));
	  mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the logical sector offset: ");
	  if (get_string(stdscr, response, sizeof(response), def) > 0) {
	    uint64_t l_sector;
	    l_sector= strtoul(response, NULL, 10);
	    l_sector*=disk->sector_size;
	    if (l_sector <= disk->disk_size) {
	      *lba=l_sector;
	    } else
	      wprintw(stdscr,"Illegal logical sector value");
	  }
	  default_option=4;
	}
	break;
      case key_ESC:
      case 'd':
      case 'D':
	return;
    }
  }
}
Ejemplo n.º 16
0
int
get_str(void *vopt, WINDOW *win)
{
    char *opt = (char *) vopt;
    char *sp;
    int oy, ox;
    int i;
    signed char c;
    static char buf[MAXSTR];

    getyx(win, oy, ox);
    wrefresh(win);
    /*
     * loop reading in the string, and put it in a temporary buffer
     */
    for (sp = buf; (c = readchar()) != '\n' && c != '\r' && c != ESCAPE;
	wclrtoeol(win), wrefresh(win))
    {
	if (c == -1)
	    continue;
	else if (c == erasechar() || c == 8 || c == 127)	/* process erase character */
	{
	    if (sp > buf)
	    {
		sp--;
		for (i = (int) strlen(unctrl(*sp)); i; i--)
		    waddch(win, '\b');
	    }
	    continue;
	}
	else if (c == killchar())	/* process kill character */
	{
	    sp = buf;
	    wmove(win, oy, ox);
	    continue;
	}
	else if (sp == buf)
	{
	    if (c == '-' && win != stdscr)
		break;
	    else if (c == '~')
	    {
		strcpy(buf, home);
		waddstr(win, home);
		sp += strlen(home);
		continue;
	    }
	}
	if (sp >= &buf[MAXINP] || !(isprint(c) || c == ' '))
	    putchar(CTRL('G'));
	else
	{
	    *sp++ = c;
	    waddstr(win, unctrl(c));
	}
    }
    *sp = '\0';
    if (sp > buf)	/* only change option if something has been typed */
	strucpy(opt, buf, (int) strlen(buf));
    mvwprintw(win, oy, ox, "%s\n", opt);
    wrefresh(win);
    if (win == stdscr)
	mpos += (int)(sp - buf);
    if (c == '-')
	return MINUS;
    else if (c == ESCAPE)
	return QUIT;
    else
	return NORM;
}
Ejemplo n.º 17
0
Archivo: display.c Proyecto: alama/GIMX
void display_calibration()
{
  char line[COLS];
  s_mouse_cal* mcal = cal_get_mouse(current_mouse, current_conf);

  if(current_cal == NONE)
  {
    mvaddstr(CAL_Y_P, CAL_X_P + 1, _("Mouse calibration (Ctrl+F1 to edit)"));
  }
  else
  {
    mvaddstr(CAL_Y_P, CAL_X_P + 1, _("Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)"));
  }
  clrtoeol();
  wmove(wcal, 1, 1);
  if(GE_GetMKMode() == GE_MK_MODE_MULTIPLE_INPUTS)
  {
    waddstr(wcal, "Mouse:");
    if(current_cal == MC)
    {
      wattron(wcal, COLOR_PAIR(4));
    }
    snprintf(line, COLS, " %s (%d) (F1) ", GE_MouseName(current_mouse), GE_MouseVirtualId(current_mouse));
    waddstr(wcal, line);
    if(current_cal == MC)
    {
      wattron(wcal, COLOR_PAIR(1));
    }
  }
  waddstr(wcal, _("Profile:"));
  if(current_cal == CC)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  snprintf(line, COLS, " %d (F2)", current_conf + 1);
  waddstr(wcal, line);
  if(current_cal == CC)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  wclrtoeol(wcal);
  mvwaddstr(wcal, 2, 1, _("Dead zone:"));
  if(current_cal == DZX)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, " x=");
  if(mcal->dzx)
  {
    snprintf(line, COLS, "%d", *mcal->dzx);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _("N/A"));
  }
  waddstr(wcal, " (F3)");
  if(current_cal == DZX)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  if(current_cal == DZY)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, " y=");
  if(mcal->dzy)
  {
    snprintf(line, COLS, "%d", *mcal->dzy);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _("N/A"));
  }
  waddstr(wcal, " (F4)");
  if(current_cal == DZY)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  if(current_cal == DZS)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, _(" shape="));
  if(mcal->dzs)
  {
    if (*mcal->dzs == E_SHAPE_CIRCLE)
    {
      waddstr(wcal, _("circle"));
    }
    else
    {
      waddstr(wcal, _("rectangle"));
    }
  }
  else
  {
    waddstr(wcal, _(" N/A"));
  }
  waddstr(wcal, " (F5)");
  if(current_cal == DZS)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  wclrtoeol(wcal);
  mvwaddstr(wcal, 3, 1, _("Acceleration:"));
  if(current_cal == TEST)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, _(" test (F6)"));
  if(current_cal == TEST)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  if(current_cal == EX)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, " x=");
  if(mcal->ex)
  {
    snprintf(line, COLS, "%.2f", *mcal->ex);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _("N/A"));
  }
  waddstr(wcal, " (F7)");
  if(current_cal == EX)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  if(current_cal == EY)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, " y=");
  if(mcal->ey)
  {
    snprintf(line, COLS, "%.2f", *mcal->ey);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _("N/A"));
  }
  waddstr(wcal, " (F8)");
  if(current_cal == EY)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  wclrtoeol(wcal);
  mvwaddstr(wcal, 4, 1, _("Sensitivity:"));
  if(current_cal == MX)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  if(mcal->mx)
  {
    snprintf(line, COLS, " %.2f", *mcal->mx);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _(" N/A"));
  }
  waddstr(wcal, " (F9)");
  if(current_cal == MX)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  wclrtoeol(wcal);
  mvwaddstr(wcal, 5, 1, "X/Y:");
  if(current_cal == RD || current_cal == VEL)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, _(" circle test"));
  if(current_cal == RD || current_cal == VEL)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  waddstr(wcal, ", ");
  if(current_cal == RD)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  snprintf(line, COLS, _("radius=%d (F10)"), mcal->rd);
  waddstr(wcal, line);
  if(current_cal == RD)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  waddstr(wcal, ", ");
  if(current_cal == VEL)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  snprintf(line, COLS, _("velocity=%d (F11)"), mcal->vel);
  waddstr(wcal, line);
  if(current_cal == VEL)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  if(current_cal == MY)
  {
    wattron(wcal, COLOR_PAIR(4));
  }
  waddstr(wcal, _(" ratio="));
  if(mcal->mx && mcal->my)
  {
    snprintf(line, COLS, "%.2f", *mcal->my / *mcal->mx);
    waddstr(wcal, line);
  }
  else
  {
    waddstr(wcal, _("N/A"));
  }
  waddstr(wcal, " (F12)");
  if(current_cal == MY)
  {
    wattron(wcal, COLOR_PAIR(1));
  }
  wclrtoeol(wcal);
  box(wcal, 0 , 0);
  wnoutrefresh(wcal);
}
Ejemplo n.º 18
0
static NCURSES_INLINE int
wadd_wch_nosync(WINDOW *win, cchar_t ch)
/* the workhorse function -- add a character to the given window */
{
    NCURSES_SIZE_T x, y;
    wchar_t *s;
    int tabsize = 8;
#if USE_REENTRANT
    SCREEN *sp = _nc_screen_of(win);
#endif

    /*
     * If we are using the alternate character set, forget about locale.
     * Otherwise, if the locale claims the code is printable, treat it that
     * way.
     */
    if ((AttrOf(ch) & A_ALTCHARSET)
	|| iswprint((wint_t) CharOf(ch)))
	return wadd_wch_literal(win, ch);

    /*
     * Handle carriage control and other codes that are not printable, or are
     * known to expand to more than one character according to unctrl().
     */
    x = win->_curx;
    y = win->_cury;

    switch (CharOf(ch)) {
    case '\t':
#if USE_REENTRANT
	tabsize = *ptrTabsize(sp);
#else
	tabsize = TABSIZE;
#endif
	x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize)));
	/*
	 * Space-fill the tab on the bottom line so that we'll get the
	 * "correct" cursor position.
	 */
	if ((!win->_scroll && (y == win->_regbottom))
	    || (x <= win->_maxx)) {
	    cchar_t blank = blankchar;
	    AddAttr(blank, AttrOf(ch));
	    while (win->_curx < x) {
		if (wadd_wch_literal(win, blank) == ERR)
		    return (ERR);
	    }
	    break;
	} else {
	    wclrtoeol(win);
	    win->_flags |= _WRAPPED;
	    if (newline_forces_scroll(win, &y)) {
		x = win->_maxx;
		if (win->_scroll) {
		    scroll(win);
		    x = 0;
		}
	    } else {
		x = 0;
	    }
	}
	break;
    case '\n':
	wclrtoeol(win);
	if (newline_forces_scroll(win, &y)) {
	    if (win->_scroll)
		scroll(win);
	    else
		return (ERR);
	}
	/* FALLTHRU */
    case '\r':
	x = 0;
	win->_flags &= ~_WRAPPED;
	break;
    case '\b':
	if (x == 0)
	    return (OK);
	x--;
	win->_flags &= ~_WRAPPED;
	break;
    default:
	if ((s = wunctrl(&ch)) != 0) {
	    while (*s) {
		cchar_t sch;
		SetChar(sch, *s++, AttrOf(ch));
		if_EXT_COLORS(SetPair(sch, GetPair(ch)));
		if (wadd_wch_literal(win, sch) == ERR)
		    return ERR;
	    }
	    return OK;
	}
	return ERR;
    }

    win->_curx = x;
    win->_cury = y;

    return OK;
}
Ejemplo n.º 19
0
static void prompt_onInit(ToxWindow* self) {
  scrollok(self->window, 1);

  print_usage(self);
  wclrtoeol(self->window);
}
Ejemplo n.º 20
0
save() {

	reg char	*sp;
	reg int		outf;
	reg time_t	*tp;
	char		buf[80];
	time_t		tme;
	STAT		junk;

	tp = &tme;
	if (Fromfile && getyn(SAMEFILEPROMPT))
		strcpy(buf, Fromfile);
	else {
over:
		prompt(FILEPROMPT);
		leaveok(Board, FALSE);
		refresh();
		sp = buf;
		while ((*sp = readch()) != '\n') {
			if (*sp == killchar())
				goto over;
			else if (*sp == erasechar()) {
				if (--sp < buf)
					sp = buf;
				else {
					addch('\b');
					/*
					 * if the previous char was a control
					 * char, cover up two characters.
					 */
					if (*sp < ' ')
						addch('\b');
					clrtoeol();
				}
			}
			else
				addstr(unctrl(*sp++));
			refresh();
		}
		*sp = '\0';
		leaveok(Board, TRUE);
	}

	/*
	 * check for existing files, and confirm overwrite if needed
	 */

	if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
	    && getyn(OVERWRITEFILEPROMPT) == FALSE))
		return FALSE;

	if ((outf = creat(buf, 0644)) < 0) {
		error(strerror(errno));
		return FALSE;
	}
	mvwaddstr(Score, ERR_Y, ERR_X, buf);
	wrefresh(Score);
	time(tp);			/* get current time		*/
	strcpy(buf, ctime(tp));
	for (sp = buf; *sp != '\n'; sp++)
		continue;
	*sp = '\0';
	varpush(outf, write);
	close(outf);
	wprintw(Score, " [%s]", buf);
	wclrtoeol(Score);
	wrefresh(Score);
	return TRUE;
}
Ejemplo n.º 21
0
void outputTest(WINDOW *win)
{
    WINDOW *win1;
    char Buffer[80];
    chtype ch;
    int by, bx;

    nl();
    wclear(win);
    mvwaddstr(win, 1, 1, "You should now have a screen in the upper "
                         "left corner, and this text should have wrapped");
    waddstr(win,"\nThis text should be down\n");
    waddstr(win,  "and broken into two here ^");
    Continue(win);

    wclear(win);
    wattron(win, A_BOLD);
    mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
    mvwaddstr(win, 8, 1, "Press any key to continue");
    wrefresh(win);
    wgetch(win);

    getbegyx(win, by, bx);

    if (LINES < 24 || COLS < 75)
    {
        mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a");
        mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
        Continue(win);
    }
    else
    {
        win1 = newwin(10, 50, 14, 25);

        if (win1 == NULL)
        {
            endwin();
            return;
        }

#ifdef A_COLOR
        if (has_colors())
        {
            init_pair(3, COLOR_BLUE, COLOR_WHITE);
            wbkgd(win1, COLOR_PAIR(3));
        }
        else
#endif
            wbkgd(win1, A_NORMAL);

        wclear(win1);
        mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
        copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
        box(win1, ACS_VLINE, ACS_HLINE);
        wmove(win1, 8, 26);
        wrefresh(win1);
        wgetch(win1);

        wclear(win1);

        wattron(win1, A_BLINK);
        mvwaddstr(win1, 4, 1,
                  "This blinking text should appear in only the second window");
        wattroff(win1, A_BLINK);

        mvwin(win1, by, bx);
        overlay(win, win1);
        mvwin(win1, 14, 25);
        wmove(win1, 8, 26);
        wrefresh(win1);
        wgetch(win1);

        delwin(win1);
    }

    clear();
    wclear(win);
    wrefresh(win);
    mvwaddstr(win, 6, 2, "This line shouldn't appear");
    mvwaddstr(win, 4, 2, "Only half of the next line is visible");
    mvwaddstr(win, 5, 2, "Only half of the next line is visible");
    wmove(win, 6, 1);
    wclrtobot(win);
    wmove(win, 5, 20);
    wclrtoeol(win);
    mvwaddstr(win, 8, 2, "This line also shouldn't appear");
    wmove(win, 8, 1);
    winsdelln(win, -1);
    Continue(win);

    wmove(win, 5, 9);
    ch = winch(win);

    wclear(win);
    wmove(win, 6, 2);
    waddstr(win, "The next char should be l:  ");
    winsch(win, ch);
    Continue(win);

    mvwinsstr(win, 6, 2, "A1B2C3D4E5");
    Continue(win);

    wmove(win, 5, 1);
    winsdelln(win, 1);
    mvwaddstr(win, 5, 2, "The lines below should have moved down");
    Continue(win);

    wclear(win);
    wmove(win, 2, 2);
    wprintw(win, "This is a formatted string in a window: %d %s\n",
            42, "is it");
    mvwaddstr(win, 10, 1, "Enter a string: ");
    wrefresh(win);
    echo();
    wscanw(win, "%s", Buffer);

    printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
    mvaddstr(10, 1, "Enter a string: ");
    scanw("%s", Buffer);

    wclear(win);
    curs_set(2);
    mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode");
    Continue(win);

    wclear(win);
    curs_set(0);
    mvwaddstr(win, 1, 1, "The cursor should have disappeared");
    Continue(win);

    wclear(win);
    curs_set(1);
    mvwaddstr(win, 1, 1, "The cursor should be normal");
    Continue(win);

#ifdef A_COLOR
    if (has_colors())
    {
        wclear(win);
        mvwaddstr(win, 1, 1, "Colors should change after you press a key");
        Continue(win);

        init_pair(1, COLOR_RED, COLOR_WHITE);
        wrefresh(win);
    }
#endif
    werase(win);
    mvwaddstr(win, 1, 1, "Information About Your Terminal");
    mvwaddstr(win, 3, 1, termname());
    mvwaddstr(win, 4, 1, longname());

    if (termattrs() & A_BLINK)
        mvwaddstr(win, 5, 1, "This terminal claims to support blinking.");
    else
        mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");

    mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
    wrefresh(win);

    mvwinnstr(win, 7, 5, Buffer, 18);
    mvaddstr(LINES - 2, 10, Buffer);
    refresh();
    Continue(win);
}
Ejemplo n.º 22
0
void mrutils::ColChooser::Column::highlight(int hid, bool refreshInput,
    bool selectFirst, bool refreshWindow) {

    mrutils::mutexAcquire(cc.updateMutex);

    int start, end, d, id; bool addMatches = false;

    if (hid > tail) {
        start = tail + 1;
        end  = choices.size();

        headMatches += tail == -1 ? 0 : MIN(cc.lines-1,(unsigned)searchMatches.size()-headMatches);

        if (headMatches+1 >= searchMatches.size()) {
            addMatches = true;
            head = tail = -1;
        } else {
            head = searchMatches[headMatches];
            tail = searchMatches[MIN((unsigned)searchMatches.size()-1,headMatches + cc.lines-2)];
        }
    } else {
        if (hid < head) {
            headMatches = MAX(0u, headMatches - cc.lines+1);
            head = searchMatches[headMatches];
            tail = searchMatches[MIN((unsigned)searchMatches.size()-1,headMatches + cc.lines-2)];
        }

        start = headMatches;
        end = searchMatches.size();
    }

    d = headMatches;
    selMatches = -1;

    wattrset((WINDOW*)chooserWin,ATR_BLANK);

    for (int i = start; i < end && d-headMatches < cc.lines-1; ++i) {
        if (addMatches) {
            if (applySearch && !mrutils::stristr(choices[i].c_str(), search)) {
                continue;
            }

            if (d == headMatches) head = i; tail = i;
            searchMatches.push_back(i);
        }

        id = searchMatches[d];
        wmove((WINDOW*)chooserWin,d++ - headMatches,cc.colStart); wclrtoeol((WINDOW*)chooserWin);

        if (id == hid) {
            selMatches = d-1;

            wattrset((WINDOW*)chooserWin,ATR_SELECTED);
            waddnstr((WINDOW*)chooserWin,choices[id].c_str(), colWidth);
            wattrset((WINDOW*)chooserWin,ATR_BLANK);

            int left = colWidth - choices[id].size();
            if (left > 0)
                wchgat((WINDOW*)chooserWin,left, 0, COL_SELECTED, NULL);
        } else {
            bool targeted = colNumber+1 == cc.data.size() && cc.targeted[id];
            if (targeted)
                wattrset((WINDOW*)chooserWin,ATR_TARGETED);
            waddnstr((WINDOW*)chooserWin,choices[id].c_str(), colWidth);
            wattrset((WINDOW*)chooserWin,ATR_BLANK);

            int left = colWidth - choices[id].size();
            if (left > 0) {
                if (targeted)
                    wchgat((WINDOW*)chooserWin,left, 0, COL_TARGETED, NULL);
                else 
                    wchgat((WINDOW*)chooserWin,left, 0, COL_BLANK, NULL);
            }
        }
    }

    if (selMatches == -1 && selectFirst) {
        selMatches = headMatches;
        wmove((WINDOW*)chooserWin,0,cc.colStart);
        wchgat((WINDOW*)chooserWin, colWidth, A_BLINK, COL_SELECTED, NULL);
    }

    for (int i = d - headMatches; i < cc.lines-1; ++i) { 
        wmove((WINDOW*)chooserWin,i,cc.colStart); wclrtoeol((WINDOW*)chooserWin);
    }

    // set the depth selection
    if ( selMatches < 0 ||
         selMatches >= searchMatches.size() )
        cc.depth[colNumber] = -1;
    else 
        cc.depth[colNumber] = searchMatches[selMatches] + cc.startIndex;

    // build next column
    if (cc.data.size() > colNumber + 1 
        && hid >= 0 && cc.depth[colNumber] >= 0) {


        mvwvline((WINDOW*)chooserWin, 0, 
                cc.colStart + colWidth, ACS_VLINE, cc.lines-1);

        std::vector<std::string>& choices = cc.data[colNumber+1].choices;

        if (refreshWindow) {
            cc.targeted.clear();
            cc.targets.clear();

            choices.clear();
            (cc.optionsFn)(cc, cc.optionData);
            if (cc.building >= 0) cc.build();
        }

        int colWidth = cc.data[colNumber+1].colWidth;
        int rows = MIN((unsigned)choices.size(), cc.lines-1);

        for (int i = 0; i < rows; ++i) {
            bool targeted = colNumber+2 == cc.data.size() && cc.targeted[i];
            if (targeted)
                wattrset((WINDOW*)chooserWin,ATR_TARGETED);
            wmove((WINDOW*)chooserWin,i,cc.colStart+this->colWidth+1); 
            waddnstr((WINDOW*)chooserWin,choices[i].c_str(), colWidth);
            if (targeted) {
                wchgat((WINDOW*)chooserWin,-1, 0, COL_TARGETED, NULL);
                wattrset((WINDOW*)chooserWin,ATR_BLANK);
            }
        }
    }

    if (refreshInput) { cc.printPrompt(cc.name.c_str()); }
    else {
        if (refreshWindow) wrefresh((WINDOW*)chooserWin);
        move(cc.maxLines-1,0);
    }

    if (colNumber == cc.data.size()-1 && cc.changeFn != NULL) {
        (cc.changeFn)(cc, cc.changeData);
    }

    mrutils::mutexRelease(cc.updateMutex);
}
Ejemplo n.º 23
0
EIF_INTEGER c_ecurses_wclrtoeol (EIF_POINTER w)
{
    return  wclrtoeol  ((WINDOW *)w) ;
};
Ejemplo n.º 24
0
void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space)
{
  list_part_t *list_part;
#ifdef HAVE_NCURSES
  list_part_t *current_element;
  unsigned int current_element_num;
  int done=0;
  int command;
  unsigned int offset=0;
  unsigned int menu=0;
  static const struct MenuItem menuMain[]=
  {
	{'S',"Search","Start file recovery"},
	{'O',"Options","Modify options"},
	{'F',"File Opt","Modify file options"},
	{'G',"Geometry", "Change disk geometry" },
	{'Q',"Quit","Return to disk selection"},
	{0,NULL,NULL}
  };
#endif
  params->blocksize=0;
  list_part=init_list_part(params->disk, options);
  if(list_part==NULL)
    return;
  log_all_partitions(params->disk, list_part);
  if(params->cmd_run!=NULL)
  {
    if(menu_photorec_cli(list_part, params, options, list_search_space) > 0)
    {
      if(params->recup_dir==NULL)
      {
	char *res;
#ifdef HAVE_NCURSES
	res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
#else
	res=get_default_location();
#endif
	if(res!=NULL)
	{
	  params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
	  strcpy(params->recup_dir,res);
	  strcat(params->recup_dir,"/");
	  strcat(params->recup_dir,DEFAULT_RECUP_DIR);
	  free(res);
	}
      }
      if(params->recup_dir!=NULL)
	photorec(params, options, list_search_space);
    }
  }
  if(params->cmd_run!=NULL)
  {
    part_free_list(list_part);
    return;
  }
#ifdef HAVE_NCURSES
  if(list_part->next!=NULL)
  {
    current_element_num=1;
    current_element=list_part->next;
  }
  else
  {
    current_element_num=0;
    current_element=list_part;
  }
  while(done==0)
  { /* ncurses interface */
    list_part_t *element;
    unsigned int i;
    aff_copy(stdscr);
    wmove(stdscr,4,0);
    wprintw(stdscr,"%s",params->disk->description_short(params->disk));
    mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    mousemask(ALL_MOUSE_EVENTS, NULL);
#endif
    for(i=0,element=list_part; element!=NULL && i<offset+INTER_SELECT;element=element->next,i++)
    {
      if(i<offset)
	continue;
      wmove(stdscr,7+i-offset,0);
      wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
      if(element==current_element)
      {
	wattrset(stdscr, A_REVERSE);
	waddstr(stdscr, ">");
	aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
	wattroff(stdscr, A_REVERSE);
      } else
      {
	waddstr(stdscr, " ");
	aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
      }
    }
    wmove(stdscr,7+INTER_SELECT,5);
    wclrtoeol(stdscr);
    if(element!=NULL)
      wprintw(stdscr, "Next");
    command = wmenuSelect(stdscr, INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8,
	(options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    if(command == KEY_MOUSE)
    {
      MEVENT event;
      if(getmouse(&event) == OK)
      {	/* When the user clicks left mouse button */
	if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED))
	{
	  if(event.y >=7 && event.y<7+INTER_SELECT)
	  {
	    /* Disk selection */
	    while(current_element_num > event.y-(7-offset) && current_element->prev!=NULL)
	    {
	      current_element=current_element->prev;
	      current_element_num--;
	    }
	    while(current_element_num < event.y-(7-offset) && current_element->next!=NULL)
	    {
	      current_element=current_element->next;
	      current_element_num++;
	    }
	    if(event.bstate & BUTTON1_DOUBLE_CLICKED)
	      command='S';
	  }
	  else
	    command = menu_to_command(INTER_SELECT_Y+1, INTER_SELECT_Y, INTER_SELECT_X, menuMain, 8,
		(options->expert==0?"SOFQ":"SOFGQ"), MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, event.y, event.x);
	}
      }
    }
#endif
    switch(command)
    {
      case KEY_UP:
	if(current_element!=NULL && current_element->prev!=NULL)
	{
	  current_element=current_element->prev;
	  current_element_num--;
	}
	break;
      case KEY_PPAGE:
	for(i=0; (signed)i<INTER_SELECT && current_element->prev!=NULL; i++)
	{
	  current_element=current_element->prev;
	  current_element_num--;
	}
	break;
      case KEY_DOWN:
	if(current_element->next!=NULL)
	{
	  current_element=current_element->next;
	  current_element_num++;
	}
	break;
      case KEY_NPAGE:
	for(i=0; (signed)i<INTER_SELECT && current_element->next!=NULL; i++)
	{
	  current_element=current_element->next;
	  current_element_num++;
	}
	break;
      case 's':
      case 'S':
	if(current_element!=NULL)
	{
	  params->partition=current_element->part;
	  ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, &params->carve_free_space_only);
	  menu=0;
	  if(params->recup_dir==NULL)
	  {
	    char *res;
	    res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
	    if(res!=NULL)
	    {
	      params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
	      strcpy(params->recup_dir,res);
	      strcat(params->recup_dir,"/");
	      strcat(params->recup_dir,DEFAULT_RECUP_DIR);
	      free(res);
	    }
	  }
	  if(params->recup_dir!=NULL)
	  {
	    if(td_list_empty(&list_search_space->list))
	    {
	      init_search_space(list_search_space, params->disk, params->partition);
	    }
	    if(params->carve_free_space_only>0)
	    {
	      aff_copy(stdscr);
	      wmove(stdscr,5,0);
	      wprintw(stdscr, "Filesystem analysis, please wait...\n");
	      wrefresh(stdscr);
	      params->blocksize=remove_used_space(params->disk, params->partition, list_search_space);
	      /* Only free space is carved, list_search_space is modified.
	       * To carve the whole space, need to quit and reselect the params->partition */
	      done = 1;
	    }
	    photorec(params, options, list_search_space);
	  }
	}
	break;
      case 'o':
      case 'O':
	{
	  interface_options_photorec_ncurses(options);
	  menu=1;
	}
	break;
      case 'f':
      case 'F':
	interface_file_select_ncurses(options->list_file_format);
	menu=2;
	break;
      case 'g':
      case 'G':
	if(options->expert!=0)
	  if(change_geometry_ncurses(params->disk))
	    done=1;
	break;
      case 'a':
      case 'A':
	if(params->disk->arch != &arch_none)
	{
	  list_part=add_partition_ncurses(params->disk, list_part);
	  current_element=list_part;
	  current_element_num=0;
	}
	break;
      case 'q':
      case 'Q':
	done = 1;
	break;
    }
    if(current_element_num<offset)
      offset=current_element_num;
    if(current_element_num>=offset+INTER_SELECT)
      offset=current_element_num-INTER_SELECT+1;
  }
#endif
  log_info("\n");
  part_free_list(list_part);
}
Ejemplo n.º 25
0
static list_part_t *ask_structure_ncurses(disk_t *disk_car,list_part_t *list_part, const int verbose, char **current_cmd)
{
  int offset=0;
  int pos_num=0;
  list_part_t *pos=list_part;
  int rewrite=1;
  int old_LINES=LINES;
  while(1)
  {
    int i;
    int command;
    list_part_t *parts;
    int structure_status;
    if(old_LINES!=LINES)
    {
      rewrite=1;
      old_LINES=LINES;
    }
    if(rewrite)
    {
      aff_copy(stdscr);
      wmove(stdscr,4,0);
      wprintw(stdscr,"%s",disk_car->description(disk_car));
      mvwaddstr(stdscr,5,0,msg_PART_HEADER);
      rewrite=0;
    }
    structure_status=disk_car->arch->test_structure(list_part);
    for(i=0,parts=list_part;
	parts!=NULL && i<offset+INTER_STRUCTURE;
	i++, parts=parts->next)
    {
      if(i<offset)
	continue;
      wmove(stdscr,6+i-offset,0);
      wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
      if(parts==pos)
	wattrset(stdscr, A_REVERSE);
      if(structure_status==0 && parts->part->status!=STATUS_DELETED && has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(2));
      if(parts==pos)
	waddstr(stdscr, ">");
      else
	waddstr(stdscr, " ");
      aff_part(stdscr, AFF_PART_STATUS, disk_car, parts->part);
      if(structure_status==0 && parts->part->status!=STATUS_DELETED && has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      if(parts==pos)
      {
	char buffer_part_size[100];
	wattroff(stdscr, A_REVERSE);
	wmove(stdscr,LINES-1,0);
	wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
	if(parts->part->info[0]!='\0')
	{
	  wprintw(stdscr,"%s, ",parts->part->info);
	}
	size_to_unit(parts->part->part_size, buffer_part_size);
	wprintw(stdscr,"%s", buffer_part_size);
      }
    }
    if(structure_status==0)
    {
      if(list_part!=NULL)
	mvwaddstr(stdscr,LINES-6,0,msg_STRUCT_OK);
    }
    else
    {
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(1));
      mvwaddstr(stdscr,LINES-6,0,msg_STRUCT_BAD);
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
    }
    if(list_part!=NULL && disk_car->arch->msg_part_type!=NULL)
    {
      mvwaddstr(stdscr,LINES-6,16,"Use ");
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"Up");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr,"/");
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"Down");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr," Arrow keys to select partition.");
      mvwaddstr(stdscr,LINES-5,0,"Use ");
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"Left");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr,"/");
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"Right");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr," Arrow keys to CHANGE partition characteristics:");
      mvwaddstr(stdscr,LINES-4,0,disk_car->arch->msg_part_type);
    }
    wmove(stdscr,LINES-3,0);
    wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
    waddstr(stdscr,"Keys ");
    /* If the disk can't be partionned, there is no partition to add and no partition to save */
    if(disk_car->arch != &arch_none)
    {
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"A");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr,": add partition, ");
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      waddstr(stdscr,"L");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr,": load backup, ");
    }
    if(list_part==NULL)
    {
      waddstr(stdscr,"Enter: to continue");
    }
    else
    {
      if(pos->part->arch==NULL || pos->part->arch==disk_car->arch)
      {
	if(has_colors())
	  wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
	waddstr(stdscr,"T");
	if(has_colors())
	  wbkgdset(stdscr,' ' | COLOR_PAIR(0));
	waddstr(stdscr,": change type, ");
      }
      switch(pos->part->upart_type)
      {
	case UP_EXFAT:
	case UP_EXT2:
	case UP_EXT3:
	case UP_EXT4:
	case UP_RFS:
	case UP_RFS2:
	case UP_RFS3:
	case UP_FAT12:
	case UP_FAT16:
	case UP_FAT32:
	case UP_NTFS:
	  if(has_colors())
	    wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
	  waddstr(stdscr,"P");
	  if(has_colors())
	    wbkgdset(stdscr,' ' | COLOR_PAIR(0));
	  waddstr(stdscr,": list files, ");
	  break;
	default:
	  break;
      }
      if(has_colors())
	wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(0));
      mvwaddstr(stdscr,LINES-2,5, "Enter");
      if(has_colors())
	wbkgdset(stdscr,' ' | COLOR_PAIR(0));
      waddstr(stdscr,": to continue");
    }
    wrefresh(stdscr);
    command=wgetch(stdscr);
    switch(command)
    {
      case KEY_UP:
	if(list_part!=NULL)
	{
	  only_one_bootable(list_part,pos);
	  if(pos->prev!=NULL)
	  {
	    pos=pos->prev;
	    pos_num--;
	  }
	}
	break;
      case KEY_DOWN:
	if(list_part!=NULL)
	{
	  only_one_bootable(list_part,pos);
	  if(pos->next!=NULL)
	  {
	    pos=pos->next;
	    pos_num++;
	  }
	}
	break;
      case KEY_PPAGE:
	if(list_part!=NULL)
	{
	  only_one_bootable(list_part,pos);
	  for(i=0; i<INTER_STRUCTURE && pos->prev!=NULL; i++)
	  {
	    pos=pos->prev;
	    pos_num--;
	  }
	}
	break;
      case KEY_NPAGE:
	if(list_part!=NULL)
	{
	  only_one_bootable(list_part,pos);
	  for(i=0; i<INTER_STRUCTURE && pos->next!=NULL; i++)
	  {
	    pos=pos->next;
	    pos_num++;
	  }
	}
	break;
      case KEY_RIGHT:
      case '+':
      case ' ':
	if(list_part!=NULL)
	{
	  if(pos->part->arch==NULL || pos->part->arch==disk_car->arch)
	    disk_car->arch->set_next_status(disk_car,pos->part);
	}
	break;
      case KEY_LEFT:
      case '-':
	if(list_part!=NULL)
	{
	  if(pos->part->arch==NULL || pos->part->arch==disk_car->arch)
	    disk_car->arch->set_prev_status(disk_car,pos->part);
	}
	break;
      case 'a':
      case 'A':
	if(disk_car->arch != &arch_none)
	{
	  list_part=add_partition_ncurses(disk_car, list_part);
	  rewrite=1;
	  offset=0;
	  pos_num=0;
	  pos=list_part;
	}
	break;
      case 't':
      case 'T':
	if(list_part!=NULL)
	{
	  rewrite=1;
	  change_part_type_ncurses(disk_car, pos->part);
	}
	break;
      case 'p':
      case 'P':
	if(list_part!=NULL)
        {
          const partition_t *partition=pos->part;
          if(partition->sb_offset==0 || partition->sb_size==0)
            dir_partition(disk_car,partition,verbose, current_cmd);
          else
          {
            io_redir_add_redir(disk_car,
                partition->part_offset+partition->sborg_offset,
                partition->sb_size,
                partition->part_offset+partition->sb_offset,
                NULL);
            dir_partition(disk_car,partition,verbose, current_cmd);
            io_redir_del_redir(disk_car, partition->part_offset+partition->sborg_offset);
          }
	  rewrite=1;
        }
	break;
      case 'b':
      case 'B':
	if(partition_save(disk_car,list_part,verbose)<0)
	  display_message("Can't create backup.log.\n");
	else
	  display_message("Results saved in backup.log.\n");
	rewrite=1;
        break;
      case 'l':
      case 'L':
	if(disk_car->arch != &arch_none)
	{
	  list_part=interface_load(disk_car,list_part,verbose);
	  rewrite=1;
	  offset=0;
	  pos_num=0;
	  pos=list_part;
	}
        break;
      case 'q':
      case '\r':
      case '\n':
      case KEY_ENTER:
#ifdef PADENTER
      case PADENTER:
#endif
      case 'M':
	return list_part;
      default:
/*	log_trace("ask_structure command=%x\n",command); */
	break;
    }
    if(pos_num<offset)
      offset=pos_num;
    if(pos_num>=offset+INTER_STRUCTURE)
      offset=pos_num-INTER_STRUCTURE+1;
  }
}
Ejemplo n.º 26
0
static void prompt_onDraw(ToxWindow *self, Tox *m)
{
    curs_set(1);

    int x, y, x2, y2;
    getyx(self->window, y, x);
    getmaxyx(self->window, y2, x2);

    size_t i;

    for (i = 0; i < prompt_buf_pos; ++i) {
        if ((prompt_buf[i] == '\n') && (y != 0))
            --y;
    }

    StatusBar *statusbar = (StatusBar *) self->stb;
    werase(statusbar->topline);
    mvwhline(statusbar->topline, 1, 0, '-', x2);
    wmove(statusbar->topline, 0, 0);

    if (statusbar->is_online) {
        int colour = WHITE;
        char *status_text = "Unknown";

        switch(statusbar->status) {
        case TOX_USERSTATUS_NONE:
            status_text = "Online";
            colour = GREEN;
            break;
        case TOX_USERSTATUS_AWAY:
            status_text = "Away";
            colour = YELLOW;
            break;
        case TOX_USERSTATUS_BUSY:
            status_text = "Busy";
            colour = RED;
            break;
        }

        wattron(statusbar->topline, A_BOLD);
        wprintw(statusbar->topline, " %s ", statusbar->nick);
        wattron(statusbar->topline, A_BOLD);
        wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
        wprintw(statusbar->topline, "[%s]", status_text);
        wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
    } else {
        wattron(statusbar->topline, A_BOLD);
        wprintw(statusbar->topline, "%s ", statusbar->nick);
        wattroff(statusbar->topline, A_BOLD);
        wprintw(statusbar->topline, "[Offline]");
    }

    wattron(statusbar->topline, A_BOLD);
    wprintw(statusbar->topline, " | %s |", statusbar->statusmsg);
    wattroff(statusbar->topline, A_BOLD);

    wprintw(statusbar->topline, "\n");

    wattron(self->window, COLOR_PAIR(GREEN));
    mvwprintw(self->window, y, 0, "# ");
    wattroff(self->window, COLOR_PAIR(GREEN));
    mvwprintw(self->window, y, 2, "%s", prompt_buf);
    wclrtoeol(self->window);
    
    wrefresh(self->window);
}
Ejemplo n.º 27
0
static int fat_unformat_aux(struct ph_param *params, const struct ph_options *options, const uint64_t start_offset, alloc_data_t *list_search_space)
{
  int ind_stop=0;
  uint64_t offset;
  uint64_t offset_end;
  unsigned char *buffer_start;
  unsigned char *buffer;
  time_t start_time;
  time_t previous_time;
  const unsigned int blocksize=params->blocksize;
  const unsigned int read_size=(blocksize>65536?blocksize:65536);
  alloc_data_t *current_search_space;
  file_recovery_t file_recovery;
  disk_t *disk=params->disk;
  const partition_t *partition=params->partition;

  reset_file_recovery(&file_recovery);
  file_recovery.blocksize=blocksize;
  buffer_start=(unsigned char *)MALLOC(READ_SIZE);
  buffer=buffer_start;
  start_time=time(NULL);
  previous_time=start_time;
  current_search_space=td_list_entry(list_search_space->list.prev, alloc_data_t, list);
  if(current_search_space==list_search_space)
  {
    free(buffer_start);
    return 0;
  }
  offset_end=current_search_space->end;
  current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
  offset=set_search_start(params, &current_search_space, list_search_space);
  if(options->verbose>0)
    info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, options->verbose);
  disk->pread(disk, buffer, READ_SIZE, offset);
  for(;offset < offset_end; offset+=blocksize)
  {
    if(memcmp(buffer,         ".          ", 8+3)==0 &&
	memcmp(&buffer[0x20], "..         ", 8+3)==0)
    {
      file_data_t *dir_list;
      dir_list=dir_fat_aux(buffer,read_size,0,0);
      if(dir_list!=NULL)
      {
	const file_data_t *current_file;
	log_info("Sector %llu\n", (long long unsigned)offset/disk->sector_size);
	dir_aff_log(NULL, dir_list);
	del_search_space(list_search_space, offset, offset + blocksize -1);
	current_file=dir_list;
	while(current_file!=NULL)
	{
	  if(strcmp(current_file->name,".")==0 &&
	      LINUX_S_ISDIR(current_file->stat.st_mode)!=0 &&
	      current_file!=dir_list)
	    current_file=NULL;
	  else if(current_file->stat.st_ino>2 &&
	      LINUX_S_ISREG(current_file->stat.st_mode)!=0)
	  {
	    const uint64_t file_start=start_offset + (uint64_t)(current_file->stat.st_ino - 2) * blocksize;
#ifdef DJGPP
	    const uint64_t file_end=file_start+(current_file->file_size+blocksize-1)/blocksize*blocksize - 1;
#else
	    const uint64_t file_end=file_start+(current_file->stat.st_size+blocksize-1)/blocksize*blocksize - 1;
#endif
	    if(file_end < partition->part_offset + partition->part_size)
	    {
	      if(fat_copy_file(disk, partition, blocksize, start_offset, params->recup_dir, params->dir_num, current_file)==0)
	      {
		params->file_nbr++;
		del_search_space(list_search_space, file_start, file_end);
	      }
	      current_file=current_file->next;
	    }
	    else
	      current_file=NULL;
	  }
	  else
	    current_file=current_file->next;
	}
	delete_list_file(dir_list);
      }
    }
    buffer+=blocksize;
    if(buffer+read_size>buffer_start+READ_SIZE)
    {
      buffer=buffer_start;
      if(options->verbose>1)
      {
        log_verbose("Reading sector %10llu/%llu\n",
	    (unsigned long long)((offset-partition->part_offset)/disk->sector_size),
	    (unsigned long long)((partition->part_size-1)/disk->sector_size));
      }
      if(disk->pread(disk, buffer, READ_SIZE, offset) != READ_SIZE)
      {
#ifdef HAVE_NCURSES
	wmove(stdscr,11,0);
	wclrtoeol(stdscr);
	wprintw(stdscr,"Error reading sector %10lu\n",
	    (unsigned long)((offset-partition->part_offset)/disk->sector_size));
#endif
      }
#ifdef HAVE_NCURSES
      {
        time_t current_time;
        current_time=time(NULL);
        if(current_time>previous_time)
        {
	  const time_t elapsed_time=current_time - params->real_start_time;
          previous_time=current_time;
	  wmove(stdscr,9,0);
	  wclrtoeol(stdscr);
	  log_info("Reading sector %10llu/%llu, %u files found\n",
	      (unsigned long long)((offset-partition->part_offset)/disk->sector_size),
	      (unsigned long long)(partition->part_size/disk->sector_size), params->file_nbr);
	  wprintw(stdscr,"Reading sector %10llu/%llu, %u files found\n",
	      (unsigned long long)((offset-partition->part_offset)/disk->sector_size),
	      (unsigned long long)(partition->part_size/disk->sector_size), params->file_nbr);
	  wmove(stdscr,10,0);
	  wclrtoeol(stdscr);
	  wprintw(stdscr,"Elapsed time %uh%02um%02us",
	      (unsigned)(elapsed_time/60/60),
	      (unsigned)(elapsed_time/60%60),
	      (unsigned)(elapsed_time%60));
	  if(offset-partition->part_offset!=0)
	  {
	    wprintw(stdscr," - Estimated time to completion %uh%02um%02u\n",
		(unsigned)((partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset)/3600),
		(unsigned)(((partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset)/60)%60),
		(unsigned)((partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset))%60);
	  }
	  wrefresh(stdscr);
	  if(check_enter_key_or_s(stdscr))
	  {
	    log_info("PhotoRec has been stopped\n");
	    params->offset=offset;
	    offset = offset_end;
	    ind_stop=1;
	  }
	}
      }
#endif
    }
  }
  free(buffer_start);
  return ind_stop;
}
Ejemplo n.º 28
0
static void prompt_onInit(ToxWindow *self, Tox *m)
{
    scrollok(self->window, true);
    print_prompt_help(self);
    wclrtoeol(self->window);
}
Ejemplo n.º 29
0
int clrtoeol(void)
{
    PDC_LOG(("clrtoeol() - called\n"));

    return wclrtoeol(stdscr);
}
Ejemplo n.º 30
0
void Scrollpad::flush()
{
	auto &w = static_cast<Window &>(*this);
	const auto &s = m_buffer.str();
	const auto &ps = m_buffer.properties();
	auto p = ps.begin();
	size_t i = 0;
	
	auto load_properties = [&]() {
		for (; p != ps.end() && p->position() == i; ++p)
			w << *p;
	};
	auto write_whitespace = [&]() {
		for (; i < s.length() && iswspace(s[i]); ++i)
		{
			load_properties();
			w << s[i];
		}
	};
	auto write_word = [&](bool load_properties_) {
		for (; i < s.length() && !iswspace(s[i]); ++i)
		{
			if (load_properties_)
				load_properties();
			w << s[i];
		}
	};
	auto write_buffer = [&](bool generate_height_only) -> size_t {
		int new_y;
		size_t height = 1;
		size_t old_i;
		auto old_p = p;
		int x, y;
		i = 0;
		p = ps.begin();
		y = getY();
		while (i < s.length())
		{
			// write all whitespaces.
			write_whitespace();
			
			// if we are generating height, check difference
			// between previous Y coord and current one and
			// update height accordingly.
			if (generate_height_only)
			{
				new_y = getY();
				height += new_y - y;
				y = new_y;
			}
			
			if (i == s.length())
				break;
			
			// save current string position state and get current
			// coordinates as we are before the beginning of a word.
			old_i = i;
			old_p = p;
			x = getX();
			y = getY();
			
			// write word to test if it overflows, but do not load properties
			// yet since if it overflows, we do not want to load them twice.
			write_word(false);
			
			// restore previous indexes state
			i = old_i;
			p = old_p;
			
			// get new Y coord to see if word overflew into next line.
			new_y = getY();
			if (new_y != y)
			{
				if (generate_height_only)
				{
					// if it did, let's update height...
					++height;
				}
				else
				{
					// ...or go to old coordinates, erase
					// part of the string from previous line...
					goToXY(x, y);
					wclrtoeol(m_window);
				}
				
				// ...start at the beginning of next line...
				++y;
				goToXY(0, y);
				
				// ...write word again, this time with properties...
				write_word(true);
				
				if (generate_height_only)
				{
					// ... and check for potential
					// difference in Y coordinates again.
					new_y = getY();
					height += new_y - y;
				}
			}
			else
			{
				// word didn't overflow, rewrite it with properties.
				goToXY(x, y);
				write_word(true);
			}
			
			if (generate_height_only)
			{
				// move to the first line, since when we do
				// generation, m_real_height = m_height and we
				// don't have many lines to use.
				goToXY(getX(), 0);
				y = 0;
			}
		}
		// load remaining properties if there are any
		for (; p != ps.end(); ++p)
			w << *p;
		return height;
	};
	m_real_height = std::max(write_buffer(true), m_height);
	if (m_real_height > m_height)
		recreate(m_width, m_real_height);
	else
		werase(m_window);
	write_buffer(false);
}