Beispiel #1
0
int
help()
{
	extern int nlines;
	int eof, i;
	FILE *fp;
	WINDOW *win;
	char buf[BUFSIZ];

	if ((fp = fopen(HELPFILE, "r")) == NULL)
		return(-1);
	win = newwin(0, 0, 0, 0);
	clearok(win, 1);

	eof = 0;
	if (ungetc(getc(fp), fp) == EOF) {
		wprintw(win, "There doesn't seem to be any help.");
		eof = 1;			/* Nothing there... */
	}

	while (!eof) {
		for (i = 0; i < nlines - 3; i++) {
			if (fgets(buf, sizeof(buf), fp) == (char *) NULL) {
				eof = 1;
				break;
			}
			if (buf[0] == '.' && buf[1] == '\n')
				break;
			wprintw(win, "%s", buf);
		}
		if (eof || ungetc(getc(fp), fp) == EOF) {
			eof = 1;
			break;
		}
		wmove(win, nlines - 1, 0);
		wprintw(win,
		    "Type <space> to continue, anything else to quit...");
		wrefresh(win);
		if ((inputch() & 0177) != ' ')
			break;
		wclear(win);
	}

	fclose(fp);
	if (eof) {
		wmove(win, nlines - 1, 0);
		wprintw(win, "Hit any key to continue...");
		wrefresh(win);
		inputch();
	}
	delwin(win);
	clearok(stdscr, 1);
	refresh();
	return(0);
}
Beispiel #2
0
static void nc_sigwinch(int s)
/* SIGWINCH signal handler */
{
    mpdm_t v;

#ifdef NCURSES_VERSION
    /* Make sure that window size changes... */
    struct winsize ws;

    int fd = open("/dev/tty", O_RDWR);

    if (fd == -1)
        return;                 /* This should never have to happen! */

    if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
        resizeterm(ws.ws_row, ws.ws_col);

    close(fd);
#else
    /* restart curses */
    /* ... */
#endif

    /* invalidate main window */
    clearok(stdscr, 1);
    refresh();

    /* re-set dimensions */
    v = mpdm_hget_s(mp, L"window");
    mpdm_hset_s(v, L"tx", MPDM_I(COLS));
    mpdm_hset_s(v, L"ty", MPDM_I(LINES));

    /* reattach */
    signal(SIGWINCH, nc_sigwinch);
}
Beispiel #3
0
/* Display information about the various key commands. Each element in
 * the keys array contains two sequential NUL-terminated strings,
 * describing the key and the associated command respectively. The
 * strings are arranged to line up into two columns.
 */
void displayhelp(char const *keys[], int keycount)
{
    int keywidth, descwidth;
    int	i, n;

    keywidth = 1;
    descwidth = 0;
    for (i = 0 ; i < keycount ; ++i) {
	n = strlen(keys[i]);
	if (n > keywidth)
	    keywidth = n;
	n = strlen(keys[i] + n + 1);
	if (n > descwidth)
	    descwidth = n;
    }

    erase();
    n = keywidth + descwidth + 2;
    if (n < 4)
	n = 4;
    mvaddstr(0, n / 2 + 2, "Keys");
    for (i = 0 ; i < n ; ++i)
	mvaddch(1, i, ACS_HLINE);
    for (i = 0 ; i < keycount ; ++i) {
	n = strlen(keys[i]);
	mvaddstr(i + 2, 0, keys[i]);
	mvaddstr(i + 2, keywidth + 2, keys[i] + n + 1);
    }

    mvaddstr(lastline, 0, "Press any key to return.");
    refresh();
    clearok(stdscr, TRUE);
}
Beispiel #4
0
int init_allwin()
{
    int ret =0;
    int i = 0;
    Win win[4] = {
            // x,y,width,height,name,title,WINDOW*
            {{0, 0, 60, 60}, {0, 0, 0.8, 1}, "L1", "", NULL}, 
            {{100, 0, 20, 20}, {0.8, 0, 0.2, 0.4}, "R1", "", NULL}, 
            {{100, 10, 20, 20}, {0.8, 0.4, 0.2, 0.4}, "R2", "", NULL}, 
            {{100, 15, 20, 20}, {0.8, 0.8, 0.2, 0.2}, "RCMD", "", NULL}, 
            };


    for (i=0; i<4; i++) {
        win[i].win = newwin(win[i].locate.y, win[i].locate.x, 0, 0);
        if (NULL == win) {
            printf("Init failed.\n");
            ret = -1;
            break;
        }
        if (strcmp(win[i].name, "L1") == 0) {
            scrollok(win[i].win, TRUE);
        } else {
            clearok(win[i].win, TRUE);
        }
        windows.insert(Windows::value_type(win[i].name, win[i]));

        Win frame;
        memcpy(&frame, &win[i], sizeof(Win));
        frame.win = newwin(win[i].locate.y, win[i].locate.x, 0, 0);
        frames.insert(Windows::value_type(win[i].name, frame));
    }
 
    return ret;
}
Beispiel #5
0
static void
low_level_change_screen_size (void)
{
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
#if defined TIOCGWINSZ
    struct winsize winsz;

    winsz.ws_col = winsz.ws_row = 0;
    /* Ioctl on the STDIN_FILENO */
    ioctl (0, TIOCGWINSZ, &winsz);
    if (winsz.ws_col && winsz.ws_row){
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
	resizeterm(winsz.ws_row, winsz.ws_col);
	clearok(stdscr,TRUE);	/* sigwinch's should use a semaphore! */
#else
	COLS = winsz.ws_col;
	LINES = winsz.ws_row;
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
	resize_subshell ();
#endif
    }
#endif /* TIOCGWINSZ */
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
}
Beispiel #6
0
/**
 * mutt_get_field_full - Ask the user for a string
 * @param[in]  field    Prompt
 * @param[in]  buf      Buffer for the result
 * @param[in]  buflen   Length of buffer
 * @param[in]  complete Flags, see #CompletionFlags
 * @param[in]  multiple Allow multiple selections
 * @param[out] files    List of files selected
 * @param[out] numfiles Number of files selected
 * @retval 1  Redraw the screen and call the function again
 * @retval 0  Selection made
 * @retval -1 Aborted
 */
int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionFlags complete,
                        bool multiple, char ***files, int *numfiles)
{
  int ret;
  int x;

  struct EnterState *es = mutt_enter_state_new();

  do
  {
    if (SigWinch)
    {
      SigWinch = 0;
      mutt_resize_screen();
      clearok(stdscr, TRUE);
      mutt_menu_current_redraw();
    }
    mutt_window_clearline(MuttMessageWindow, 0);
    SETCOLOR(MT_COLOR_PROMPT);
    addstr(field);
    NORMAL_COLOR;
    mutt_refresh();
    mutt_window_getxy(MuttMessageWindow, &x, NULL);
    ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es);
  } while (ret == 1);
  mutt_window_clearline(MuttMessageWindow, 0);
  mutt_enter_state_free(&es);

  return ret;
}
Beispiel #7
0
void
tty_change_screen_size (void)
{
#if defined(TIOCGWINSZ) && NCURSES_VERSION_MAJOR >= 4
    struct winsize winsz;

    winsz.ws_col = winsz.ws_row = 0;

#ifndef NCURSES_VERSION
    tty_noraw_mode ();
    tty_reset_screen ();
#endif

    /* Ioctl on the STDIN_FILENO */
    ioctl (fileno (stdout), TIOCGWINSZ, &winsz);
    if (winsz.ws_col != 0 && winsz.ws_row != 0)
    {
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
        resizeterm (winsz.ws_row, winsz.ws_col);
        clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
#else
        COLS = winsz.ws_col;
        LINES = winsz.ws_row;
#endif
    }
#endif /* defined(TIOCGWINSZ) || NCURSES_VERSION_MAJOR >= 4 */

#ifdef ENABLE_SUBSHELL
    if (mc_global.tty.use_subshell)
        tty_resize (mc_global.tty.subshell_pty);
#endif
}
void
tstp(int ignored)
{
    int y, x;
    int oy, ox;

	NOOP(ignored);

    /*
     * leave nicely
     */
    getyx(curscr, oy, ox);
    mvcur(0, COLS - 1, LINES - 1, 0);
    endwin();
    resetltchars();
    fflush(stdout);
	md_tstpsignal();

    /*
     * start back up again
     */
	md_tstpresume();
    raw();
    noecho();
    keypad(stdscr,1);
    playltchars();
    clearok(curscr, TRUE);
    wrefresh(curscr);
    getyx(curscr, y, x);
    mvcur(y, x, oy, ox);
    fflush(stdout);
    curscr->_cury = oy;
    curscr->_curx = ox;
}
void
shell(void)
{
    /*
     * Set the terminal back to original mode
     */
    move(LINES-1, 0);
    refresh();
    endwin();
    resetltchars();
    putchar('\n');
    in_shell = TRUE;
    after = FALSE;
    fflush(stdout);
    /*
     * Fork and do a shell
     */
    md_shellescape();

    noecho();
    raw();
    keypad(stdscr,1);
    playltchars();
    in_shell = FALSE;
    clearok(stdscr, TRUE);
}
Beispiel #10
0
/*
 * cl_refresh --
 *	Refresh the screen.
 *
 * PUBLIC: int cl_refresh __P((SCR *, int));
 */
int
cl_refresh(SCR *sp, int repaint)
{
	CL_PRIVATE *clp;
	WINDOW *win;
	SCR *psp, *tsp;
	size_t y, x;

	clp = CLP(sp);
	win = CLSP(sp) ? CLSP(sp) : stdscr;

	/*
	 * If we received a killer signal, we're done, there's no point
	 * in refreshing the screen.
	 */
	if (clp->killersig)
		return (0);

	/*
	 * If repaint is set, the editor is telling us that we don't know
	 * what's on the screen, so we have to repaint from scratch.
	 *
	 * If repaint set or the screen layout changed, we need to redraw
	 * any lines separating vertically split screens.  If the horizontal
	 * offsets are the same, then the split was vertical, and need to
	 * draw a dividing line.
	 */
	if (repaint || F_ISSET(clp, CL_LAYOUT)) {
		getyx(stdscr, y, x);
		for (psp = sp; psp != NULL; psp = TAILQ_NEXT(psp, q))
			for (tsp = TAILQ_NEXT(psp, q); tsp != NULL;
			    tsp = TAILQ_NEXT(tsp, q))
				if (psp->roff == tsp->roff) {
				    if (psp->coff + psp->cols + 1 == tsp->coff)
					cl_rdiv(psp);
				    else 
				    if (tsp->coff + tsp->cols + 1 == psp->coff)
					cl_rdiv(tsp);
				}
		(void)wmove(stdscr, y, x);
		F_CLR(clp, CL_LAYOUT);
	}

	/*
	 * In the curses library, doing wrefresh(curscr) is okay, but the
	 * screen flashes when we then apply the refresh() to bring it up
	 * to date.  So, use clearok().
	 */
	if (repaint)
		clearok(curscr, 1);
	/*
	 * Only do an actual refresh, when this is the focus window,
	 * i.e. the one holding the cursor. This assumes that refresh
	 * is called for that window after refreshing the others.
	 * This prevents the cursor being drawn in the other windows.
	 */
	return (wnoutrefresh(stdscr) == ERR || 
		wnoutrefresh(win) == ERR || 
		(sp == clp->focus && doupdate() == ERR));
}
Beispiel #11
0
/* Update the display and wait for an input event.
 */
int curses_runio(int *control)
{
    int ch, i;

    for (;;) {
	render();
	ch = tolower(getch());
	switch (ch) {
	  case '\r':
	  case '\n':
	  case KEY_ENTER:
	    *control = ctl_button;
	    return 1;
	  case KEY_MOUSE:
	    if (getmouseevent(control))
		return 1;
	    break;
	  case '?':
	  case KEY_F(1):
	    if (!runhelp())
		return 0;
	    break;
	  case '\022':
	    if (!runruleshelp())
		return 0;
	    break;
	  case '\026':
	    if (!runlicensedisplay())
		return 0;
	    break;
	  case '\001':
	    changediechars(+1);
	    break;
	  case '\f':
	    clearok(stdscr, TRUE);
	    break;
	  case KEY_RESIZE:
	    initlayout();
	    break;
	  case '\003':
	  case '\030':
	    return 0;
	  case 'q':
	  case '\033':
	    if (controls[ctl_button].value == bval_newgame)
		return 0;
	    break;
	  case ERR:
	    exit(1);
	  default:
	    for (i = 0 ; i < ctl_count ; ++i) {
		if (controls[i].key == ch) {
		    *control = i;
		    return 1;
		}
	    }
	}
    }
}
Beispiel #12
0
/* Signal handler for SIGWINCH.
 */
static void onresize(int sig)
{
    if (sig == SIGWINCH) {
	endwin();
	clearok(stdscr, TRUE);
	refresh();
    }
}
Beispiel #13
0
void redraw_all (void)
{
	int min_lines = TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3;
	struct winsize ws;
	int	save_col, save_lines;

	/* get the size of the terminal connected to stdout */
	ioctl(1, TIOCGWINSZ, &ws);
	/*
	 * Do it again because GDB doesn't stop before the first ioctl
	 * call, we want an up-to-date size when we're
	 * single-stepping.
	 */
	if (ioctl(1, TIOCGWINSZ, &ws) == 0) {
		if (ws.ws_row < min_lines)
			ws.ws_row = min_lines;
		if ((ws.ws_row != LINES) || (ws.ws_col != COLS)) {
			wmove (show_win,2,COLS-18);
			wclrtoeol(show_win);
			wrefresh(show_win);
			resizeterm(ws.ws_row, ws.ws_col);
			wresize(title_win, TITLE_WIN_LINES,COLS);
			wresize(show_win, SHOW_WIN_LINES,COLS);
			wresize(command_win, COMMAND_WIN_LINES,COLS);
			wresize(mt_win1, 1,COLS);
			wresize(mt_win2, 1,COLS);
			mvwin(mt_win2, LINES-COMMAND_WIN_LINES-1,0);
			mvwin(command_win, LINES-COMMAND_WIN_LINES,0);
			draw_title_win();
			show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
			show_pad_info.display_cols=COLS;
		}
	}
	clearok(title_win, 1);
	clearok(show_win, 1);
	clearok(command_win, 1);
	clearok(mt_win1, 1);
	clearok(mt_win2, 1);
	wrefresh(mt_win1);
	wrefresh(mt_win2);
	refresh_show_pad();
	refresh_show_win();
	refresh_title_win ();
	refresh_command_win ();
}
Beispiel #14
0
static void cont_catcher(int signo UNUSED)
{
    noecho();
    raw();
    clearok(stdscr, 1);
    move(crow, ccol);
    refresh();
    starttime();
}
Beispiel #15
0
void
n_shell()
{
	WINDOW *sh_win, *newwin();
	SIG_TYPE (*istat)(), (*qstat)();
	int sig_status, spid, w;
	char *shell, *shellpath, *getenv(), *strrchr();
	unsigned int sleep();
	void _exit();
					/* a full window */
	sh_win = newwin(LINES, COLS, 0, 0);

	touchwin(sh_win);
	waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
	wrefresh(sh_win);
					/* out of curses mode */
	resetterm();

	shellpath = getenv("SHELL");
	if (shellpath == NULL || *shellpath == '\0')
		shellpath = "/bin/sh";

	if (shell = strrchr(shellpath, '/'))
		shell++;
	else {
		shellpath = "/bin/sh";
		shell = "sh";
	}

	if (!(spid = fork())) {
		signal(SIGINT, SIG_DFL);
		signal(SIGQUIT, SIG_DFL);
#ifdef SETUGID
		setgid(getgid());
		setuid(getuid());
#endif /* SETUGID */
		execl(shellpath, shell, "-i", (char *) 0);
		_exit(1);
	}
	istat = signal(SIGINT, SIG_IGN);
	qstat = signal(SIGQUIT, SIG_IGN);

	while ((w = wait(&sig_status)) != spid && w != -1)
		;

	signal(SIGINT, istat);
	signal(SIGQUIT, qstat);
					/* back to curses mode */
	sleep(1);
	fixterm();

	clearok(curscr, TRUE);
	werase(sh_win);
	wrefresh(sh_win);
	delwin(sh_win);
	return;
}
Beispiel #16
0
// Get a valid word and put it in the buffer
void getword(char *q)
{
    int ch, col, done, i, row;
    char *p;

    done = 0;
    i = 0;
    p = q;
    addch('[');
    refresh();
    while (!done && i < MAXWORDLEN - 1) {
	ch = getch() & 0177;
	switch (ch) {
	    case '\177':      // <del>
	    case '\010':      // <bs>
		if (p == q)
		    break;
		p--;
		getyx(stdscr, row, col);
		move(row, col - 1);
		clrtoeol();
		break;
	    case '\025':      // <^u>
	    case '\027':      // <^w>
		if (p == q)
		    break;
		getyx(stdscr, row, col);
		move(row, col - (int) (p - q));
		p = q;
		clrtoeol();
		break;
	    case ' ':
	    case '\n':
	    case '\r':
		done = 1;
		break;
	    case '\014':      // <^l>
	    case '\022':      // <^r>
		clearok(stdscr, 1);
		refresh();
		break;
	    default:
		if (islower(ch)) {
		    *p++ = ch;
		    addch(ch);
		    i++;
		}
		break;
	}
	refresh();
    }
    *p = '\0';
    addch(']');
    refresh();
}
int
restore(char *file)
{
    FILE *infd;
    char    *sp;

    if (strcmp(file, "-r") == 0)
        file = file_name;

    if ((infd = fopen(file, "r")) == NULL)
    {
        perror(file);
        return(FALSE);
    }

    if ( restore_file(infd) == FALSE )
        return(FALSE);

    /*
     * we do not close the file so that we will have a hold of the inode
     * for as long as possible
     */

    if (remove(file) < 0)
    {
        printf("Cannot unlink file\n");
        return(FALSE);
    }

    if ((sp = getenv("OPTIONS")) != NULL)
        parse_opts(sp);

    strcpy(file_name, file);

    clearok(cw, TRUE);
    touchwin(cw);
    noecho();
    nonl();

    while(playing)
    {
        do_daemons(BEFORE);
        do_fuses(BEFORE);

        command();  /* Command execution */

        if (after)
            do_after_effects();
    }

    fatal("");

    return(FALSE);
}
void mutt_edit_file (const char *editor, const char *data)
{
  char cmd[LONG_STRING];
  
  endwin ();
  mutt_expand_file_fmt (cmd, sizeof (cmd), editor, data);
  if (mutt_system (cmd) == -1)
    mutt_error (_("Error running \"%s\"!"), cmd);
  keypad (stdscr, TRUE);
  clearok (stdscr, TRUE);
}
Beispiel #19
0
void
show_win(WINDOW *scr, char *message)
{
    mvwaddstr(scr, 0, 0, message);
    touchwin(scr);
    wmove(scr, hero.y, hero.x);
    wrefresh(scr);
    wait_for(' ');
    clearok(cw, TRUE);
    touchwin(cw);
}
PRIVATE void terminate_message ARGS1(int,sig)
{
	term_message=TRUE;
#ifdef VMS
	/* Reassert the AST */
	signal(SIGINT, terminate_message);
        /* Refresh the screen to get rid of the "interrupt" message */
	clearok(curscr, TRUE);
	refresh();
#endif /* VMS */
}
Beispiel #21
0
/* Restore windows when returning from an external command. */
void
wins_unprepare_external (void)
{
  reset_prog_mode ();
  clearok (curscr, TRUE);
  curs_set (0);
  ui_mode = UI_CURSES;
  wins_refresh ();
  if (notify_bar ())
    notify_start_main_thread ();
}
Beispiel #22
0
/*
 * This routine initializes the current and standard screen.
 */
WINDOW *
initscr()
{
	char	*sp;
	int 	nfd;

# ifdef DEBUG
	fprintf(outf, "INITSCR()\n");
# endif
	if (My_term)
		setterm(Def_term);
	else {
	        nfd = getdtablesize();
		for (_tty_ch = 0; _tty_ch < nfd; _tty_ch++)
			if (isatty(_tty_ch))
				break;
		gettmode();
		sp = getenv("TERM");
		if (! sp)
			sp = Def_term;
		setterm(sp);
# ifdef DEBUG
		fprintf(outf, "INITSCR: term = %s\n", sp);
# endif
	}
	_puts(TI);
	_puts(VS);
# ifdef SIGTSTP
	signal(SIGTSTP, (sig_t)tstp);
# endif
	if (curscr != NULL) {
# ifdef DEBUG
		fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
# endif
		delwin(curscr);
	}
# ifdef DEBUG
	fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
# endif
	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
		return ERR;
	clearok(curscr, TRUE);
	curscr->_flags &= ~_FULLLINE;
	if (stdscr != NULL) {
# ifdef DEBUG
		fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
# endif
		delwin(stdscr);
	}
	stdscr = newwin(LINES, COLS, 0, 0);
	return stdscr;
}
Beispiel #23
0
WINDOW *initscr()
{
  char *term;

  if ((term = getenv("TERM")) == NULL) return NULL;
  setterm(term);
  gettmode();
  if ((_cursvar.tmpwin = newwin(LINES, COLS, 0, 0)) == (WINDOW *)ERR) return NULL;
  if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)ERR) return NULL;
  if ((stdscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)ERR) return NULL;
  clearok(curscr, TRUE);
  return(stdscr);
}
Beispiel #24
0
void dump_ncurses(const void *nom_dump, unsigned int lng)
{
  WINDOW *window=newwin(LINES, COLS, 0, 0);	/* full screen */
  keypad(window, TRUE); /* Need it to get arrow key */
  aff_copy(window);
  dump(window, nom_dump, lng);
  dump_log(nom_dump,lng);
  delwin(window);
  (void) clearok(stdscr, TRUE);
#ifdef HAVE_TOUCHWIN
  touchwin(stdscr);
#endif
}
Beispiel #25
0
/*
 * print and then set options from the terminal
 */
void
option()
{
    OPTION	*op;
    int	retval;

    PC_GFX_SET_CURSOR(1);
    wclear(hw);
    touchwin(hw);
    /*
     * Display current values of options
     */
    for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
    {
	waddstr(hw, op->o_prompt);
	(*op->o_putfunc)(op->o_opt);
	waddch(hw, '\n');
    }
    /*
     * Set values
     */
    wmove(hw, 0, 0);
    for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
    {
	waddstr(hw, op->o_prompt);
	if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
	    if (retval == QUIT)
		break;
	    else if (op > optlist) {	/* MINUS */
		wmove(hw, (int)(op - optlist) - 1, 0);
		op -= 2;
	    }
	    else	/* trying to back up beyond the top */
	    {
		beep();
		wmove(hw, 0, 0);
		op--;
	    }
    }
    /* 
     * Switch back to original screen
     */
    mvwaddstr(hw, LINES-1, 0, "--Press space to continue--");
    draw(hw);
    wait_for(hw,' ');
    clearok(cw, TRUE);
    touchwin(cw);
    after = FALSE;
    status();
    PC_GFX_SET_CURSOR(0);
}
Beispiel #26
0
void
option()
{
    OPTION	*op;
    int		retval;

    wclear(hw);
    /*
     * Display current values of options
     */
    for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
    {
	pr_optname(op);
	(*op->o_putfunc)(op->o_opt);
	waddch(hw, '\n');
    }
    /*
     * Set values
     */
    wmove(hw, 0, 0);
    for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
    {
	pr_optname(op);
	retval = (*op->o_getfunc)(op->o_opt, hw);
	if (retval)
	{
	    if (retval == QUIT)
		break;
	    else if (op > optlist) {	/* MINUS */
		wmove(hw, (int)(op - optlist) - 1, 0);
		op -= 2;
	    }
	    else	/* trying to back up beyond the top */
	    {
		putchar('\007');
		wmove(hw, 0, 0);
		op--;
	    }
	}
    }
    /*
     * Switch back to original screen
     */
    wmove(hw, LINES - 1, 0);
    waddstr(hw, "--Press space to continue--");
    wrefresh(hw);
    wait_for(' ');
    clearok(curscr, TRUE);
    touchwin(stdscr);
    after = FALSE;
}
 /*
  * print and then set options from the terminal
  */
 void
 option(void)
 {
     register OPTION	*op;
     register int	retval;
 
     wclear(hw);
     touchwin(hw);
     /*
      * Display current values of options
      */
     for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
     {
 	waddstr(hw, op->o_prompt);
 	(*op->o_putfunc)(op->o_opt, hw);
 	waddch(hw, '\n');
     }
     /*
      * Set values
      */
     wmove(hw, 0, 0);
     for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
     {
 	waddstr(hw, op->o_prompt);
 	retval = (*op->o_getfunc)(op->o_opt, hw);
 	if (retval)
	{
 	    if (retval == QUIT)
 		break;
 	    else if (op > optlist) {	/* MINUS */
 		wmove(hw, (int)(op - optlist) - 1, 0);
 		op -= 2;
 	    }
 	    else	/* trying to back up beyond the top */
 	    {
 		putchar('\007');
 		wmove(hw, 0, 0);
 		op--;
 	    }
         }
     }
     /*
      * Switch back to original screen
      */
     mvwaddstr(hw, LINES-1, 0, spacemsg);
     draw(hw);
     wait_for(hw, ' ');
     clearok(cw, TRUE);
     touchwin(cw);
     after = FALSE;
 }
Beispiel #28
0
void
getstring(char *cp, int mx)
{
	char   *inptr;		/* pointer into string for next string */
	int     x, y;		/* original x, y coordinates on screen */
	int     ch;		/* input */

	getyx(stdscr, y, x);	/* get coordinates on screen */
	inptr = cp;
	*inptr = '\0';		/* clear string to start */
	--mx;			/* reserve room in string for nul terminator */

	do
		/* get characters and process */
	{
		if (Echo)
			mvaddstr(y, x, cp);	/* print string on screen */
		clrtoeol();	/* clear any data after string */
		refresh();	/* update screen */

		ch = getchar();	/* get character */

		switch (ch) {
		case CH_NEWLINE:	/* terminate string */
		case CH_RETURN:
			break;

		case CH_REDRAW:	/* redraw screen */
			clearok(stdscr, TRUE);
			continue;

		default:		/* put data in string */
			if (ch == Ch_Erase) {	/* back up one character */
				if (inptr > cp)
					--inptr;
				break;
			} else if (ch == Ch_Kill) { /* back up to original location */
				inptr = cp;
				break;
			} else if (isprint(ch) || Wizard) {
				/* printing char; put in string */
				*inptr++ = ch;
			}
		}

		*inptr = '\0';	/* terminate string */
	}
	while (ch != CH_NEWLINE && ch != CH_RETURN && inptr < cp + mx);
}
Beispiel #29
0
/*
 * initscr --
 *	Initialize the current and standard screen.
 */
WINDOW *
initscr()
{
	register char *sp;

#ifdef DEBUG
	__CTRACE("initscr\n");
#endif
	__echoit = 1;
        __pfast = __rawmode = __noqch = 0;

	if (gettmode() == ERR)
		return (NULL);

	/*
	 * If My_term is set, or can't find a terminal in the environment,
	 * use Def_term.
	 */
	if (My_term || (sp = getenv("TERM")) == NULL)
		sp = Def_term;
	if (setterm(sp) == ERR)
		return (NULL);

	/* Need either homing or cursor motion for refreshes */
	if (!HO && !CM) 
		return (NULL);

	if (curscr != NULL)
		delwin(curscr);
	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
		return (NULL);
	clearok(curscr, 1);

	if (stdscr != NULL)
		delwin(stdscr);
	if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
		delwin(curscr);
		return (NULL);
	}

	__set_stophandler();

#ifdef DEBUG
	__CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
#endif
	__startwin();

	return (stdscr);
}
Beispiel #30
0
/**
 * mutt_edit_file - Let the user edit a file
 * @param editor User's editor config
 * @param file   File to edit
 */
void mutt_edit_file(const char *editor, const char *file)
{
  char cmd[STR_COMMAND];

  mutt_endwin();
  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), editor, file);
  if (mutt_system(cmd) != 0)
  {
    mutt_error(_("Error running \"%s\""), cmd);
  }
  /* the terminal may have been resized while the editor owned it */
  mutt_resize_screen();
  keypad(stdscr, true);
  clearok(stdscr, true);
}