X-Git-Url: https://git.distorted.org.uk/~mdw/tig/blobdiff_plain/a643fbd72dc16eb863c4a564c23e7a54a5e9dd73..0f11e3a9f4d936964061dd9106652167c7cb0cba:/tig.c diff --git a/tig.c b/tig.c index cf65447..01cc75c 100644 --- a/tig.c +++ b/tig.c @@ -12,7 +12,7 @@ */ #ifndef VERSION -#define VERSION "tig-0.3" +#define VERSION "tig-0.4.git" #endif #ifndef DEBUG @@ -770,6 +770,7 @@ static struct key key_table[] = { { "Down", KEY_DOWN }, { "Insert", KEY_IC }, { "Delete", KEY_DC }, + { "Hash", '#' }, { "Home", KEY_HOME }, { "End", KEY_END }, { "PageUp", KEY_PPAGE }, @@ -946,8 +947,22 @@ option_set_command(int argc, char *argv[]) } if (!strcmp(argv[0], "commit-encoding")) { - string_copy(opt_encoding, argv[2]); - return OK; + char *arg = argv[2]; + int delimiter = *arg; + int i; + + switch (delimiter) { + case '"': + case '\'': + for (arg++, i = 0; arg[i]; i++) + if (arg[i] == delimiter) { + arg[i] = 0; + break; + } + default: + string_copy(opt_encoding, arg); + return OK; + } } config_msg = "Unknown variable name"; @@ -1032,7 +1047,7 @@ read_option(char *opt, int optlen, char *value, int valuelen) /* Check for comment markers, since read_properties() will * only ensure opt and value are split at first " \t". */ - optlen = strcspn(opt, "#;"); + optlen = strcspn(opt, "#"); if (optlen == 0) return OK; @@ -1042,7 +1057,7 @@ read_option(char *opt, int optlen, char *value, int valuelen) } else { /* Look for comment endings in the value. */ - int len = strcspn(value, "#;"); + int len = strcspn(value, "#"); if (len < valuelen) { valuelen = len; @@ -2592,6 +2607,68 @@ init_display(void) wbkgdset(status_win, get_line_attr(LINE_STATUS)); } +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; +} /* * Repository references @@ -2841,23 +2918,8 @@ main(int argc, char *argv[]) * status_win restricted. */ switch (request) { case REQ_PROMPT: - report(":"); - /* Temporarily switch to line-oriented and echoed - * input. */ - nocbreak(); - echo(); - - if (wgetnstr(status_win, opt_cmd + 4, sizeof(opt_cmd) - 4) == OK) { - memcpy(opt_cmd, "git ", 4); - opt_request = REQ_VIEW_PAGER; - } else { - report("Prompt interrupted by loading view, " - "press 'z' to stop loading views"); + if (read_prompt() == ERR) request = REQ_SCREEN_UPDATE; - } - - noecho(); - cbreak(); break; case REQ_SCREEN_RESIZE: