REQ_(SCROLL_PAGE_DOWN, "Scroll one page down"), \
\
REQ_GROUP("Misc") \
+ REQ_(NONE, "Do nothing"), \
REQ_(PROMPT, "Bring up the prompt"), \
- REQ_(SCREEN_UPDATE, "Update the screen"), \
REQ_(SCREEN_REDRAW, "Redraw the screen"), \
REQ_(SCREEN_RESIZE, "Resize the screen"), \
REQ_(SHOW_VERSION, "Show version information"), \
{ ':', REQ_PROMPT },
/* wgetch() with nodelay() enabled returns ERR when there's no input. */
- { ERR, REQ_SCREEN_UPDATE },
+ { ERR, REQ_NONE },
- /* Use the ncurses SIGWINCH handler. */
+ /* Using the ncurses SIGWINCH handler. */
{ KEY_RESIZE, REQ_SCREEN_RESIZE },
};
redraw_display();
break;
- case REQ_SCREEN_UPDATE:
+ case REQ_NONE:
doupdate();
return TRUE;
wbkgdset(status_win, get_line_attr(LINE_STATUS));
}
-static int
-read_prompt(void)
+static char *
+read_prompt(const char *prompt)
{
enum { READING, STOP, CANCEL } status = READING;
- char buf[sizeof(opt_cmd) - STRING_SIZE("git \0")];
+ static char buf[sizeof(opt_cmd) - STRING_SIZE("git \0")];
int pos = 0;
while (status == READING) {
foreach_view (view, i)
update_view(view);
- report(":%.*s", pos, buf);
+ report("%s%.*s", prompt, pos, buf);
/* Refresh, accept single keystroke of input */
key = wgetch(status_win);
switch (key) {
default:
if (pos >= sizeof(buf)) {
report("Input string too long");
- return ERR;
+ return NULL;
}
if (isprint(key))
if (status == CANCEL) {
/* Clear the status window */
report("");
- return ERR;
+ return NULL;
}
buf[pos++] = 0;
- if (!string_format(opt_cmd, "git %s", buf))
- return ERR;
- if (strncmp(buf, "show", 4) && isspace(buf[4]))
- opt_request = REQ_VIEW_DIFF;
- else
- opt_request = REQ_VIEW_PAGER;
- return OK;
+ return buf;
}
/*
* status_win restricted. */
switch (request) {
case REQ_PROMPT:
- if (read_prompt() == ERR)
- request = REQ_SCREEN_UPDATE;
- break;
+ {
+ char *cmd = read_prompt(":");
+
+ if (cmd && string_format(opt_cmd, "git %s", cmd)) {
+ if (strncmp(cmd, "show", 4) && isspace(cmd[4])) {
+ opt_request = REQ_VIEW_DIFF;
+ } else {
+ opt_request = REQ_VIEW_PAGER;
+ }
+ break;
+ }
+ request = REQ_NONE;
+ break;
+ }
case REQ_SCREEN_RESIZE:
{
int height, width;