commit - 1447784d8a78f52a72317eb9365fafedc8ef0c71
commit + 743e70b89c5512fa45ad7d31096ab4b7d4638065
blob - aa5bd63e1d7de92199c8859981ce6b974925f99f
blob + fd72225cf932c57b7920907fc2d654a78d3b6386
--- rover.c
+++ rover.c
/* Update the listing view. */
static void
-update()
+update_view()
{
int i, j;
int ishidden, isdir;
refresh();
clear();
rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
- update();
+ update_view();
}
/* Comparison used to sort listing entries. */
else
for (i = 0; i < rover.nfiles; i++)
MARKED(i) = 0;
- update();
+ update_view();
}
static void
buffer[length] = '\0';
}
return 1;
+}
+
+static void
+update_input(char *prompt, color_t color)
+{
+ int plen, ilen;
+
+ plen = strlen(prompt);
+ ilen = strlen(INPUT);
+ color_set(RVC_PROMPT, NULL);
+ mvaddstr(LINES - 1, 0, prompt);
+ color_set(color, NULL);
+ mvaddstr(LINES - 1, plen, INPUT);
+ mvaddch(LINES - 1, ilen + plen, ' ');
+ move(LINES - 1, ilen + plen);
+ color_set(DEFAULT, NULL);
}
static void
else if (!strcmp(key, RVK_DOWN)) {
if (!rover.nfiles) continue;
FSEL = (FSEL + 1) % rover.nfiles;
- update();
+ update_view();
}
else if (!strcmp(key, RVK_UP)) {
if (!rover.nfiles) continue;
FSEL = FSEL ? FSEL - 1 : rover.nfiles - 1;
- update();
+ update_view();
}
else if (!strcmp(key, RVK_JUMP_DOWN)) {
if (!rover.nfiles) continue;
if (SCROLL > rover.nfiles - HEIGHT)
SCROLL = rover.nfiles - HEIGHT;
}
- update();
+ update_view();
}
else if (!strcmp(key, RVK_JUMP_UP)) {
if (!rover.nfiles) continue;
SCROLL -= RV_JUMP;
if (SCROLL < 0)
SCROLL = 0;
- update();
+ update_view();
}
else if (!strcmp(key, RVK_CD_DOWN)) {
if (!rover.nfiles) continue;
SCROLL = rover.nfiles - HEIGHT;
}
dirname[0] = '\0';
- update();
+ update_view();
}
}
else if (!strcmp(key, RVK_HOME)) {
}
else if (!strcmp(key, RVK_SEARCH)) {
int oldsel, oldscroll, length;
+ char *prompt = "search: ";
if (!rover.nfiles) continue;
oldsel = FSEL;
oldscroll = SCROLL;
strcpy(INPUT, "");
- color_set(RVC_PROMPT, NULL);
- mvaddstr(LINES - 1, 0, "search: ");
+ update_input(prompt, DEFAULT);
curs_set(TRUE);
- color_set(DEFAULT, NULL);
while (igetstr(INPUT, INPUTSZ)) {
int sel;
- color_t color;
+ color_t color = RED;
length = strlen(INPUT);
if (length) {
for (sel = 0; sel < rover.nfiles; sel++)
SCROLL = sel - 3;
}
}
- else
- color = RED;
}
else {
FSEL = oldsel;
SCROLL = oldscroll;
}
- update();
- color_set(color, NULL);
- mvaddstr(LINES - 1, 8, INPUT);
- mvaddch(LINES - 1, length + 8, ' ');
- move(LINES - 1, length + 8);
- color_set(DEFAULT, NULL);
+ update_view();
+ update_input(prompt, color);
}
curs_set(FALSE);
- mvhline(LINES - 1, 0, ' ', length + 8);
- update();
+ mvhline(LINES - 1, 0, ' ', STATUSPOS);
+ update_view();
}
else if (!strcmp(key, RVK_TG_FILES)) {
FLAGS ^= SHOW_FILES;
cd(1);
}
else if (!strcmp(key, RVK_NEW_FILE)) {
- int ok, length;
+ int ok = 0;
+ char *prompt = "new file: ";
strcpy(INPUT, "");
- color_set(RVC_PROMPT, NULL);
- mvaddstr(LINES - 1, 0, "new file: ");
+ update_input(prompt, DEFAULT);
curs_set(TRUE);
- color_set(DEFAULT, NULL);
while (igetstr(INPUT, INPUTSZ)) {
ok = 1;
for (i = 0; i < rover.nfiles; i++)
ok = 0;
break;
}
- length = strlen(INPUT);
- color_set(ok ? GREEN : RED, NULL);
- mvaddstr(LINES - 1, 10, INPUT);
- mvaddch(LINES - 1, length + 10, ' ');
- move(LINES - 1, length + 10);
- color_set(DEFAULT, NULL);
+ update_input(prompt, ok ? GREEN : RED);
}
curs_set(FALSE);
- mvhline(LINES - 1, 0, ' ', length + 10);
- if (length) {
+ mvhline(LINES - 1, 0, ' ', STATUSPOS);
+ if (strlen(INPUT)) {
if (ok) addfile(INPUT);
else message("File already exists.", RED);
}
cd(1);
}
else if (!strcmp(key, RVK_NEW_DIR)) {
- int ok, length;
+ int ok = 0;
+ char *prompt = "new directory: ";
strcpy(INPUT, "");
- color_set(RVC_PROMPT, NULL);
- mvaddstr(LINES - 1, 0, "new directory: ");
+ update_input(prompt, DEFAULT);
curs_set(TRUE);
- color_set(DEFAULT, NULL);
while (igetstr(INPUT, INPUTSZ)) {
ok = 1;
for (i = 0; i < rover.nfiles; i++)
ok = 0;
break;
}
- length = strlen(INPUT);
- color_set(ok ? GREEN : RED, NULL);
- mvaddstr(LINES - 1, 15, INPUT);
- mvaddch(LINES - 1, length + 15, ' ');
- move(LINES - 1, length + 15);
- color_set(DEFAULT, NULL);
+ update_input(prompt, ok ? GREEN : RED);
}
curs_set(FALSE);
- mvhline(LINES - 1, 0, ' ', length + 15);
- if (length) {
+ mvhline(LINES - 1, 0, ' ', STATUSPOS);
+ if (strlen(INPUT)) {
if (ok) adddir(INPUT);
else message("File already exists.", RED);
}
add_mark(&rover.marks, CWD, FNAME(FSEL));
MARKED(FSEL) = !MARKED(FSEL);
FSEL = (FSEL + 1) % rover.nfiles;
- update();
+ update_view();
}
else if (!strcmp(key, RVK_INVMARK)) {
for (i = 0; i < rover.nfiles; i++) {
add_mark(&rover.marks, CWD, FNAME(i));
MARKED(i) = !MARKED(i);
}
- update();
+ update_view();
}
else if (!strcmp(key, RVK_MARKALL)) {
for (i = 0; i < rover.nfiles; i++)
add_mark(&rover.marks, CWD, FNAME(i));
MARKED(i) = 1;
}
- update();
+ update_view();
}
else if (!strcmp(key, RVK_DELETE)) {
process_marked(NULL, delfile, deldir);