Exemple #1
0
/* Our main help-viewer function. */
void do_help(void)
{
    int kbinput = ERR;
    bool old_no_help = ISSET(NO_HELP);
    size_t line = 0;
	/* The line number in help_text of the first displayed help
	 * line.  This variable is zero-based. */
    size_t last_line = 0;
	/* The line number in help_text of the last help line.  This
	 * variable is zero-based. */
    int oldmenu = currmenu;
	/* The menu we were called from. */
    const char *ptr;
	/* The current line of the help text. */
    size_t old_line = (size_t)-1;
	/* The line we were on before the current line. */
    functionptrtype func;
	/* The function of the key the user typed in. */

    /* Don't show a cursor in the help screen. */
    curs_set(0);
    blank_edit();
    blank_statusbar();

    /* Set help_text as the string to display. */
    help_init();

    assert(help_text != NULL);

    if (ISSET(NO_HELP)) {
	/* Make sure that the help screen's shortcut list will actually
	 * be displayed. */
	UNSET(NO_HELP);
	window_init();
    }

    bottombars(MHELP);
    wnoutrefresh(bottomwin);

    while (TRUE) {
	size_t i;

	ptr = help_text;

	/* Find the line number of the last line of the help text. */
	for (last_line = 0; *ptr != '\0'; last_line++) {
	    ptr += help_line_len(ptr);
	    if (*ptr == '\n')
		ptr++;
	}

	if (last_line > 0)
	    last_line--;

	/* Redisplay if the text was scrolled or an invalid key was pressed. */
	if (line != old_line || kbinput == ERR) {
	    blank_edit();

	    ptr = help_text;

	    /* Advance in the text to the first line to be displayed. */
	    for (i = 0; i < line; i++) {
		ptr += help_line_len(ptr);
		if (*ptr == '\n')
		    ptr++;
	    }

	    /* Now display as many lines as the window will hold. */
	    for (i = 0; i < editwinrows && *ptr != '\0'; i++) {
		size_t j = help_line_len(ptr);

		mvwaddnstr(edit, i, 0, ptr, j);
		ptr += j;
		if (*ptr == '\n')
		    ptr++;
	    }
	}

	wnoutrefresh(edit);

	old_line = line;

	lastmessage = HUSH;

	kbinput = get_kbinput(edit);

#ifndef NANO_TINY
	if (kbinput == KEY_WINCH) {
	    kbinput = ERR;
	    continue;    /* Redraw the screen. */
	}
#endif

#ifndef DISABLE_MOUSE
	if (kbinput == KEY_MOUSE) {
	    int mouse_x, mouse_y;
	    get_mouseinput(&mouse_x, &mouse_y, TRUE);
	    continue;    /* Redraw the screen. */
	}
#endif

	func = parse_help_input(&kbinput);

	if (func == total_refresh) {
	    total_redraw();
	} else if (func == do_up_void) {
	    if (line > 0)
		line--;
	} else if (func == do_down_void) {
	    if (line + (editwinrows - 1) < last_line)
		line++;
	} else if (func == do_page_up) {
	    if (line > editwinrows - 2)
		line -= editwinrows - 2;
	    else
		line = 0;
	} else if (func == do_page_down) {
	    if (line + (editwinrows - 1) < last_line)
		line += editwinrows - 2;
	} else if (func == do_first_line) {
	    line = 0;
	} else if (func == do_last_line) {
	    if (line + (editwinrows - 1) < last_line)
		line = last_line - (editwinrows - 1);
	} else if (func == do_exit) {
	    /* Exit from the help viewer. */
	    break;
	} else
	    unbound_key(kbinput);
    }

    if (old_no_help) {
	blank_bottombars();
	wnoutrefresh(bottomwin);
	currmenu = oldmenu;
	SET(NO_HELP);
	window_init();
    } else
	bottombars(oldmenu);

#ifndef DISABLE_BROWSER
    if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR)
	browser_refresh();
    else
#endif
	edit_refresh();

    /* We're exiting from the help screen. */
    free(help_text);
}
Exemple #2
0
/* Set width to the number of files that we can display per line, if
 * necessary, and display the list of files. */
void browser_refresh(void)
{
    size_t i;
    int line = 0, col = 0;
	/* The current line and column while the list is getting displayed. */
    char *foo;
	/* The additional information that we'll display about a file. */

    /* Perhaps window dimensions have changed; reinitialize the browser. */
    browser_init(path_save, opendir(path_save));
    qsort(filelist, filelist_len, sizeof(char *), diralphasort);

    /* Make sure the selected file is within range. */
    if (selected >= filelist_len)
	selected = filelist_len - 1;

    titlebar(path_save);
    blank_edit();

    wmove(edit, 0, 0);

    i = width * editwinrows * ((selected / width) / editwinrows);

    for (; i < filelist_len && line < editwinrows; i++) {
	struct stat st;
	const char *filetail = tail(filelist[i]);
		/* The filename we display, minus the path. */
	size_t filetaillen = strlenpt(filetail);
		/* The length of the filename in columns. */
	size_t foolen;
		/* The length of the file information in columns. */
	int foomaxlen = 7;
		/* The maximum length of the file information in
		 * columns: seven for "--", "(dir)", or the file size,
		 * and 12 for "(parent dir)". */
	bool dots = (COLS >= 15 && filetaillen >= longest - foomaxlen);
		/* Do we put an ellipsis before the filename?  Don't set
		 * this to TRUE if we have fewer than 15 columns (i.e.
		 * one column for padding, plus seven columns for a
		 * filename other than ".."). */
	char *disp = display_string(filetail, dots ? filetaillen -
		longest + foomaxlen + 4 : 0, longest, FALSE);
		/* If we put an ellipsis before the filename, reserve
		 * one column for padding, plus seven columns for "--",
		 * "(dir)", or the file size, plus three columns for the
		 * ellipsis. */

	/* Start highlighting the currently selected file or directory. */
	if (i == selected)
	    wattron(edit, hilite_attribute);

	blank_line(edit, line, col, longest);

	/* If dots is TRUE, we will display something like "...ename". */
	if (dots)
	    mvwaddstr(edit, line, col, "...");
	mvwaddstr(edit, line, dots ? col + 3 : col, disp);

	free(disp);

	col += longest;

	/* Show information about the file.  We don't want to report
	 * file sizes for links, so we use lstat(). */
	if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) {
	    /* If the file doesn't exist (i.e. it's been deleted while
	     * the file browser is open), or it's a symlink that doesn't
	     * point to a directory, display "--". */
	    if (stat(filelist[i], &st) == -1 || !S_ISDIR(st.st_mode))
		foo = mallocstrcpy(NULL, "--");
	    /* If the file is a symlink that points to a directory,
	     * display it as a directory. */
	    else
		/* TRANSLATORS: Try to keep this at most 7 characters. */
		foo = mallocstrcpy(NULL, _("(dir)"));
	} else if (S_ISDIR(st.st_mode)) {
	    /* If the file is a directory, display it as such. */
	    if (strcmp(filetail, "..") == 0) {
		/* TRANSLATORS: Try to keep this at most 12 characters. */
		foo = mallocstrcpy(NULL, _("(parent dir)"));
		foomaxlen = 12;
	    } else
		foo = mallocstrcpy(NULL, _("(dir)"));
	} else {
	    unsigned long result = st.st_size;
	    char modifier;

	    foo = charalloc(foomaxlen + 1);

	    if (st.st_size < (1 << 10))
		modifier = ' ';  /* bytes */
	    else if (st.st_size < (1 << 20)) {
		result >>= 10;
		modifier = 'K';  /* kilobytes */
	    } else if (st.st_size < (1 << 30)) {
		result >>= 20;
		modifier = 'M';  /* megabytes */
	    } else {
Exemple #3
0
/* Set width to the number of files that we can display per line, if
 * necessary, and display the list of files. */
void browser_refresh(void)
{
	size_t i;
	int col = 0;
	/* The maximum number of columns that the filenames will take up. */
	int line = 0;
	/* The maximum number of lines that the filenames will take up. */
	std::string foo;
	/* The file information that we'll display. */

	blank_edit();

	wmove(edit, 0, 0);

	i = width * editwinrows * ((selected / width) / editwinrows);

	for (; i < filelist.size() && line < editwinrows; i++) {
		struct stat st;
		std::string filetail = tail(filelist[i]);
		/* The filename we display, minus the path. */
		int foomaxlen = 7;
		/* The maximum length of the file information in
		 * columns: seven for "--", "(dir)", or the file size,
		 * and 12 for "(parent dir)". */
		bool dots = (COLS >= 15 && filetail.length() >= longest - foomaxlen);
		/* Do we put an ellipsis before the filename?  Don't set
		 * this to true if we have fewer than 15 columns (i.e.
		 * one column for padding, plus seven columns for a
		 * filename other than ".."). */
		std::string disp = display_string(filetail, dots ? filetail.length() - longest + foomaxlen + 4 : 0, longest, false);
		/* If we put an ellipsis before the filename, reserve one column
		 * for padding, plus seven columns for "--", "(dir)", or the file
		 * size, plus three columns for the ellipsis. */

		/* Start highlighting the currently selected file or
		 * directory. */
		if (i == selected) {
			wattron(edit, highlight_attribute);
		}

		blank_line(edit, line, col, longest);

		/* If dots is true, we will display something like "...ename". */
		if (dots) {
			mvwaddstr(edit, line, col, "...");
		}
		mvwaddstr(edit, line, dots ? col + 3 : col, disp.c_str());

		col += longest;

		/* Show information about the file.  We don't want to report
		 * file sizes for links, so we use lstat(). */
		if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) {
			/* If the file doesn't exist (i.e. it's been deleted while
			 * the file browser is open), or it's a symlink that doesn't
			 * point to a directory, display "--". */
			if (stat(filelist[i], &st) == -1 || !S_ISDIR(st.st_mode)) {
				foo = "--";
			} else {
			/* If the file is a symlink that points to a directory,
			 * display it as a directory. */
			/* TRANSLATORS: Try to keep this at most 7
			 * characters. */
				foo = _("(dir)");
			}
		} else if (S_ISDIR(st.st_mode)) {
			/* If the file is a directory, display it as such. */
			if (filetail == "..") {
				/* TRANSLATORS: Try to keep this at most 12 characters. */
				foo = _("(parent dir)");
				foomaxlen = 12;
			} else {
				foo = _("(dir)");
			}
		} else {
			unsigned long result = st.st_size;
			char modifier;

			foo = charalloc(foomaxlen + 1);

			if (st.st_size < (1 << 10)) {
				modifier = ' '; // bytes
			} else if (st.st_size < (1 << 20)) {
				result >>= 10;
				modifier = 'K'; // kilobytes
			} else if (st.st_size < (1 << 30)) {
				result >>= 20;
				modifier = 'M'; // megabytes
			} else {