+static int
+read_prompt(void)
+{
+ enum { READING, STOP, CANCEL } status = READING;
+ char buf[sizeof(opt_cmd) - STRING_SIZE("git \0")];
+ int pos = 0;
+
+ while (status == READING) {
+ struct view *view;
+ int i, key;
+
+ foreach_view (view, i)
+ update_view(view);
+
+ report(":%.*s", pos, buf);
+ /* Refresh, accept single keystroke of input */
+ key = wgetch(status_win);
+ switch (key) {
+ case KEY_RETURN:
+ case KEY_ENTER:
+ case '\n':
+ status = pos ? STOP : CANCEL;
+ break;
+
+ case KEY_BACKSPACE:
+ if (pos > 0)
+ pos--;
+ else
+ status = CANCEL;
+ break;
+
+ case KEY_ESC:
+ status = CANCEL;
+ break;
+
+ case ERR:
+ break;
+
+ default:
+ if (pos >= sizeof(buf)) {
+ report("Input string too long");
+ return ERR;
+ }
+
+ if (isprint(key))
+ buf[pos++] = (char) key;
+ }
+ }
+
+ if (status == CANCEL) {
+ /* Clear the status window */
+ report("");
+ return ERR;
+ }
+
+ buf[pos++] = 0;
+ if (!string_format(opt_cmd, "git %s", buf))
+ return ERR;
+ opt_request = REQ_VIEW_PAGER;
+
+ return OK;
+}