Add doc example for disabling automatic use of topo-order for the graph
[tig.git] / src / prompt.c
blob7fe99977f7a00856eb33444d345398e1cb7f7798
1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include "tig/tig.h"
15 #include "tig/view.h"
16 #include "tig/draw.h"
17 #include "tig/display.h"
18 #include "tig/options.h"
19 #include "tig/prompt.h"
20 #include "tig/pager.h"
21 #include "tig/types.h"
23 #ifdef HAVE_READLINE
24 #include <readline/readline.h>
25 #include <readline/history.h>
26 #endif /* HAVE_READLINE */
28 static char *
29 prompt_input(const char *prompt, struct input *input)
31 enum input_status status = INPUT_OK;
32 unsigned char chars_length[SIZEOF_STR];
33 struct key key;
34 size_t promptlen = strlen(prompt);
35 int pos = 0, chars = 0;
37 input->buf[pos] = 0;
39 while (status == INPUT_OK || status == INPUT_SKIP) {
41 update_status("%s%.*s", prompt, pos, input->buf);
43 if (get_input(pos + promptlen, &key, FALSE) == OK) {
44 int len = strlen(key.data.bytes);
46 if (pos + len >= sizeof(input->buf)) {
47 report("Input string too long");
48 return NULL;
51 string_ncopy_do(input->buf + pos, sizeof(input->buf) - pos, key.data.bytes, len);
52 pos += len;
53 chars_length[chars++] = len;
54 status = input->handler(input, &key);
55 if (status != INPUT_OK) {
56 pos -= len;
57 chars--;
58 } else {
59 int changed_pos = strlen(input->buf);
61 if (changed_pos != pos) {
62 pos = changed_pos;
63 chars_length[chars - 1] = changed_pos - (pos - len);
66 } else {
67 status = input->handler(input, &key);
68 if (status == INPUT_DELETE) {
69 int len = chars_length[--chars];
71 pos -= len;
72 status = INPUT_OK;
73 } else {
74 int changed_pos = strlen(input->buf);
76 if (changed_pos != pos) {
77 pos = changed_pos;
78 chars_length[chars++] = changed_pos - pos;
82 input->buf[pos] = 0;
85 report_clear();
87 if (status == INPUT_CANCEL)
88 return NULL;
90 input->buf[pos++] = 0;
92 return input->buf;
95 static enum input_status
96 prompt_default_handler(struct input *input, struct key *key)
98 if (key->modifiers.multibytes)
99 return INPUT_SKIP;
101 switch (key->data.value) {
102 case KEY_RETURN:
103 case KEY_ENTER:
104 case '\n':
105 return *input->buf ? INPUT_STOP : INPUT_CANCEL;
107 case KEY_BACKSPACE:
108 return *input->buf ? INPUT_DELETE : INPUT_CANCEL;
110 case KEY_ESC:
111 return INPUT_CANCEL;
113 default:
114 return INPUT_SKIP;
118 static enum input_status
119 prompt_yesno_handler(struct input *input, struct key *key)
121 unsigned long c = key_to_unicode(key);
123 if (c == 'y' || c == 'Y')
124 return INPUT_STOP;
125 if (c == 'n' || c == 'N')
126 return INPUT_CANCEL;
127 return prompt_default_handler(input, key);
130 bool
131 prompt_yesno(const char *prompt)
133 char prompt2[SIZEOF_STR];
134 struct input input = { prompt_yesno_handler, NULL };
136 if (!string_format(prompt2, "%s [Yy/Nn]", prompt))
137 return FALSE;
139 return !!prompt_input(prompt2, &input);
142 struct incremental_input {
143 struct input input;
144 input_handler handler;
145 bool edit_mode;
148 static enum input_status
149 read_prompt_handler(struct input *input, struct key *key)
151 struct incremental_input *incremental = (struct incremental_input *) input;
153 if (incremental->edit_mode && !key->modifiers.multibytes)
154 return prompt_default_handler(input, key);
156 if (!unicode_width(key_to_unicode(key), 8))
157 return INPUT_SKIP;
159 if (!incremental->handler)
160 return INPUT_OK;
162 return incremental->handler(input, key);
165 char *
166 read_prompt_incremental(const char *prompt, bool edit_mode, input_handler handler, void *data)
168 static struct incremental_input incremental = { { read_prompt_handler } };
170 incremental.input.data = data;
171 incremental.handler = handler;
172 incremental.edit_mode = edit_mode;
174 return prompt_input(prompt, (struct input *) &incremental);
177 #ifdef HAVE_READLINE
178 static void
179 readline_display(void)
181 update_status("%s%s", rl_display_prompt, rl_line_buffer);
182 wrefresh(status_win);
185 static char *
186 readline_variable_generator(const char *text, int state)
188 static const char *vars[] = {
189 #define FORMAT_VAR(name, ifempty, initval) "%(" #name ")"
190 ARGV_ENV_INFO(FORMAT_VAR),
191 #undef FORMAT_VAR
192 NULL
195 static int index, len;
196 const char *name;
197 char *variable = NULL; /* No match */
199 /* If it is a new word to complete, initialize */
200 if (!state) {
201 index = 0;
202 len = strlen(text);
205 /* Return the next name which partially matches */
206 while ((name = vars[index])) {
207 index++;
209 /* Complete or format a variable */
210 if (strncmp(name, text, len) == 0) {
211 if (strlen(name) > len)
212 variable = strdup(name);
213 else
214 variable = argv_format_arg(&argv_env, text);
215 break;
219 return variable;
222 static char *
223 readline_action_generator(const char *text, int state)
225 static const char *actions[] = {
226 "!",
227 "source",
228 "color",
229 "bind",
230 "set",
231 "toggle",
232 "save-display",
233 "exec",
234 #define REQ_GROUP(help)
235 #define REQ_(req, help) #req
236 REQ_INFO,
237 #undef REQ_GROUP
238 #undef REQ_
239 NULL
242 static int index, len;
243 const char *name;
244 char *match = NULL; /* No match */
246 /* If it is a new word to complete, initialize */
247 if (!state) {
248 index = 0;
249 len = strlen(text);
252 /* Return the next name which partially matches */
253 while ((name = actions[index])) {
254 name = enum_name(name);
255 index++;
257 if (strncmp(name, text, len) == 0) {
258 /* Ignore exact completion */
259 if (strlen(name) > len)
260 match = strdup(name);
261 break;
265 return match;
268 static char *
269 readline_set_generator(const char *text, int state)
271 static const char *words[] = {
272 #define DEFINE_OPTION_NAME(name, type, flags) #name " = ",
273 OPTION_INFO(DEFINE_OPTION_NAME)
274 #undef DEFINE_OPTION_NAME
275 NULL
278 static int index, len;
279 const char *name;
280 char *match = NULL; /* No match */
282 /* If it is a new word to complete, initialize */
283 if (!state) {
284 index = 0;
285 len = strlen(text);
288 /* Return the next name which partially matches */
289 while ((name = words[index])) {
290 name = enum_name(name);
291 index++;
293 if (strncmp(name, text, len) == 0) {
294 /* Ignore exact completion */
295 if (strlen(name) > len)
296 match = strdup(name);
297 break;
301 return match;
304 static char *
305 readline_toggle_generator(const char *text, int state)
307 static const char **words;
308 static int index, len;
309 const char *name;
310 char *match = NULL; /* No match */
312 if (!words) {
313 /* TODO: Only complete column options that are defined
314 * for the view. */
316 #define DEFINE_OPTION_WORD(name, type, flags) argv_append(&words, #name);
317 #define DEFINE_COLUMN_OPTIONS_WORD(name, type, flags) #name,
318 #define DEFINE_COLUMN_OPTIONS_WORDS(name, id, options) \
319 if (VIEW_COLUMN_##id != VIEW_COLUMN_SECTION) { \
320 const char *vars[] = { \
321 options(DEFINE_COLUMN_OPTIONS_WORD) \
322 }; \
323 char buf[SIZEOF_STR]; \
324 int i; \
325 for (i = 0; i < ARRAY_SIZE(vars); i++) { \
326 if (enum_name_prefixed(buf, sizeof(buf), #name, vars[i])) \
327 argv_append(&words, buf); \
331 OPTION_INFO(DEFINE_OPTION_WORD)
332 COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_WORDS);
335 /* If it is a new word to complete, initialize */
336 if (!state) {
337 index = 0;
338 len = strlen(text);
341 /* Return the next name which partially matches */
342 while ((name = words[index])) {
343 name = enum_name(name);
344 index++;
346 if (strncmp(name, text, len) == 0) {
347 /* Ignore exact completion */
348 if (strlen(name) > len)
349 match = strdup(name);
350 break;
354 return match;
357 static int
358 readline_getc(FILE *stream)
360 return get_input_char();
363 static char **
364 readline_completion(const char *text, int start, int end)
366 /* Do not append a space after a completion */
367 rl_completion_suppress_append = 1;
370 * If the word is at the start of the line,
371 * then it is a tig action to complete.
373 if (start == 0)
374 return rl_completion_matches(text, readline_action_generator);
377 * If the line begins with "toggle", then we complete toggle options.
379 if (start >= 7 && strncmp(rl_line_buffer, "toggle ", 7) == 0)
380 return rl_completion_matches(text, readline_toggle_generator);
383 * If the line begins with "set", then we complete set options.
384 * (unless it is already completed)
386 if (start >= 4 && strncmp(rl_line_buffer, "set ", 4) == 0 &&
387 !strchr(rl_line_buffer, '='))
388 return rl_completion_matches(text, readline_set_generator);
391 * Otherwise it might be a variable name...
393 if (strncmp(text, "%(", 2) == 0)
394 return rl_completion_matches(text, readline_variable_generator);
397 * ... or finally fall back to filename completion.
399 return NULL;
402 static void
403 readline_display_matches(char **matches, int num_matches, int max_length)
405 unsigned int i;
407 wmove(status_win, 0, 0);
408 waddstr(status_win, "matches: ");
410 /* matches[0] is the incomplete word */
411 for (i = 1; i < num_matches + 1; ++i) {
412 waddstr(status_win, matches[i]);
413 waddch(status_win, ' ');
416 wgetch(status_win);
417 wrefresh(status_win);
420 static void
421 readline_init(void)
423 /* Allow conditional parsing of the ~/.inputrc file. */
424 rl_readline_name = "tig";
426 /* Word break caracters (we removed '(' to match variables) */
427 rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{";
429 /* Custom display function */
430 rl_redisplay_function = readline_display;
431 rl_getc_function = readline_getc;
433 /* Completion support */
434 rl_attempted_completion_function = readline_completion;
436 rl_completion_display_matches_hook = readline_display_matches;
439 char *
440 read_prompt(const char *prompt)
442 static char *line = NULL;
444 if (line) {
445 free(line);
446 line = NULL;
449 line = readline(prompt);
451 if (line && !*line) {
452 free(line);
453 line = NULL;
456 if (line)
457 add_history(line);
459 return line;
462 void
463 prompt_init(void)
465 readline_init();
467 #else
468 char *
469 read_prompt(const char *prompt)
471 return read_prompt_incremental(prompt, TRUE, NULL, NULL);
474 void
475 prompt_init(void)
478 #endif /* HAVE_READLINE */
480 bool
481 prompt_menu(const char *prompt, const struct menu_item *items, int *selected)
483 enum input_status status = INPUT_OK;
484 struct key key;
485 int size = 0;
487 while (items[size].text)
488 size++;
490 assert(size > 0);
492 while (status == INPUT_OK) {
493 const struct menu_item *item = &items[*selected];
494 char hotkey[] = { '[', (char) item->hotkey, ']', ' ', 0 };
495 int i;
497 update_status("%s (%d of %d) %s%s", prompt, *selected + 1, size,
498 item->hotkey ? hotkey : "", item->text);
500 switch (get_input(COLS - 1, &key, FALSE)) {
501 case KEY_RETURN:
502 case KEY_ENTER:
503 case '\n':
504 status = INPUT_STOP;
505 break;
507 case KEY_LEFT:
508 case KEY_UP:
509 *selected = *selected - 1;
510 if (*selected < 0)
511 *selected = size - 1;
512 break;
514 case KEY_RIGHT:
515 case KEY_DOWN:
516 *selected = (*selected + 1) % size;
517 break;
519 case KEY_ESC:
520 status = INPUT_CANCEL;
521 break;
523 default:
524 for (i = 0; items[i].text; i++)
525 if (items[i].hotkey == key.data.bytes[0]) {
526 *selected = i;
527 status = INPUT_STOP;
528 break;
533 report_clear();
535 return status != INPUT_CANCEL;
538 static struct option_info option_toggles[] = {
539 #define DEFINE_OPTION_TOGGLES(name, type, flags) { #name, STRING_SIZE(#name), #type, &opt_ ## name, flags },
540 OPTION_INFO(DEFINE_OPTION_TOGGLES)
543 static bool
544 find_arg(const char *argv[], const char *arg)
546 int i;
548 for (i = 0; argv && argv[i]; i++)
549 if (!strcmp(argv[i], arg))
550 return TRUE;
551 return FALSE;
554 static enum status_code
555 prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
556 struct option_info *toggle, enum view_flag *flags)
558 char name[SIZEOF_STR];
560 if (!enum_name_prefixed(name, sizeof(name), prefix, toggle->name))
561 return error("Failed to toggle option %s", toggle->name);
563 *flags = toggle->flags;
565 if (!strcmp(toggle->type, "bool")) {
566 bool *opt = toggle->value;
568 *opt = !*opt;
569 if (opt == &opt_mouse)
570 enable_mouse(*opt);
571 return success("set %s = %s", name, *opt ? "yes" : "no");
573 } else if (!strncmp(toggle->type, "enum", 4)) {
574 const char *type = toggle->type + STRING_SIZE("enum ");
575 enum author *opt = toggle->value;
576 const struct enum_map *map = find_enum_map(type);
578 *opt = (*opt + 1) % map->size;
579 return success("set %s = %s", name, enum_name(map->entries[*opt].name));
581 } else if (!strcmp(toggle->type, "int")) {
582 const char *arg = argv[2] ? argv[2] : "1";
583 int diff = atoi(arg);
584 int *opt = toggle->value;
586 if (!diff)
587 diff = *arg == '-' ? -1 : 1;
589 if (opt == &opt_diff_context && *opt < 0)
590 *opt = -*opt;
591 if (opt == &opt_diff_context && diff < 0) {
592 if (!*opt)
593 return error("Diff context cannot be less than zero");
594 if (*opt < -diff)
595 diff = -*opt;
598 if (strstr(name, "commit-title-overflow")) {
599 *opt = *opt ? -*opt : 50;
600 if (*opt < 0)
601 return success("set %s = no", name);
602 diff = 0;
605 *opt += diff;
606 return success("set %s = %d", name, *opt);
608 } else if (!strcmp(toggle->type, "double")) {
609 const char *arg = argv[2] ? argv[2] : "1.0";
610 double *opt = toggle->value;
611 int sign = 1;
612 double diff;
614 if (*arg == '-') {
615 sign = -1;
616 arg++;
619 if (parse_step(&diff, arg) != SUCCESS)
620 diff = strtod(arg, NULL);
622 *opt += sign * diff;
623 return success("set %s = %.2f", name, *opt);
625 } else if (!strcmp(toggle->type, "const char **")) {
626 const char ***opt = toggle->value;
627 bool found = TRUE;
628 int i;
630 if (argv_size(argv) <= 2) {
631 argv_free(*opt);
632 (*opt)[0] = NULL;
633 return SUCCESS;
636 for (i = 2; argv[i]; i++) {
637 if (!find_arg(*opt, argv[i])) {
638 found = FALSE;
639 break;
643 if (found) {
644 int next, pos;
646 for (next = 0, pos = 0; (*opt)[pos]; pos++) {
647 const char *arg = (*opt)[pos];
649 if (find_arg(argv + 2, arg)) {
650 free((void *) arg);
651 continue;
653 (*opt)[next++] = arg;
656 (*opt)[next] = NULL;
658 } else if (!argv_copy(opt, argv + 2)) {
659 return ERROR_OUT_OF_MEMORY;
661 return SUCCESS;
663 } else {
664 return error("Unsupported `:toggle %s` (%s)", name, toggle->type);
668 static enum status_code
669 prompt_toggle(struct view *view, const char *argv[], enum view_flag *flags)
671 const char *option = argv[1];
672 size_t optionlen = option ? strlen(option) : 0;
673 struct option_info template;
674 struct option_info *toggle;
675 struct view_column *column;
676 const char *column_name;
678 if (!option)
679 return error("%s", "No option name given to :toggle");
681 if (enum_equals_static("sort-field", option, optionlen) ||
682 enum_equals_static("sort-order", option, optionlen)) {
683 if (!view_has_flags(view, VIEW_SORTABLE)) {
684 return error("Sorting is not yet supported for the %s view", view->name);
685 } else {
686 bool sort_field = enum_equals_static("sort-field", option, optionlen);
687 struct sort_state *sort = &view->sort;
689 sort_view(view, sort_field);
690 return success("set %s = %s", option,
691 sort_field ? view_column_name(get_sort_field(view))
692 : sort->reverse ? "descending" : "ascending");
696 toggle = find_option_info(option_toggles, ARRAY_SIZE(option_toggles), "", option);
697 if (toggle)
698 return prompt_toggle_option(view, argv, "", toggle, flags);
700 for (column = view->columns; column; column = column->next) {
701 toggle = find_column_option_info(column->type, &column->opt, option, &template, &column_name);
702 if (toggle)
703 return prompt_toggle_option(view, argv, column_name, toggle, flags);
706 return error("`:toggle %s` not supported", option);
709 static void
710 prompt_update_display(enum view_flag flags)
712 struct view *view;
713 int i;
715 if (flags & VIEW_RESET_DISPLAY) {
716 resize_display();
717 redraw_display(TRUE);
720 foreach_displayed_view(view, i) {
721 if (view_has_flags(view, flags) && view_can_refresh(view))
722 reload_view(view);
723 else
724 redraw_view(view);
728 enum request
729 run_prompt_command(struct view *view, const char *argv[])
731 enum request request;
732 const char *cmd = argv[0];
733 size_t cmdlen = cmd ? strlen(cmd) : 0;
735 if (!cmd)
736 return REQ_NONE;
738 if (string_isnumber(cmd)) {
739 int lineno = view->pos.lineno + 1;
741 if (parse_int(&lineno, cmd, 0, view->lines + 1) == SUCCESS) {
742 if (!lineno)
743 lineno = 1;
744 select_view_line(view, lineno - 1);
745 report_clear();
746 } else {
747 report("Unable to parse '%s' as a line number", cmd);
749 } else if (iscommit(cmd)) {
750 int lineno;
752 if (!(view->ops->column_bits & view_column_bit(ID))) {
753 report("Jumping to commits is not supported by the %s view", view->name);
754 return REQ_NONE;
757 for (lineno = 0; lineno < view->lines; lineno++) {
758 struct view_column_data column_data = {};
759 struct line *line = &view->line[lineno];
761 if (view->ops->get_column_data(view, line, &column_data) &&
762 column_data.id &&
763 !strncasecmp(column_data.id, cmd, cmdlen)) {
764 string_ncopy(view->env->search, cmd, cmdlen);
765 select_view_line(view, lineno);
766 report_clear();
767 return REQ_NONE;
771 report("Unable to find commit '%s'", view->env->search);
772 return REQ_NONE;
774 } else if (cmdlen > 1 && (cmd[0] == '/' || cmd[0] == '?')) {
775 char search[SIZEOF_STR];
777 if (!argv_to_string(argv, search, sizeof(search), " ")) {
778 report("Failed to copy search string");
779 return REQ_NONE;
782 if (!strcmp(search + 1, view->env->search))
783 return cmd[0] == '/' ? REQ_FIND_NEXT : REQ_FIND_PREV;
785 string_ncopy(view->env->search, search + 1, strlen(search + 1));
786 return cmd[0] == '/' ? REQ_SEARCH : REQ_SEARCH_BACK;
788 } else if (cmdlen > 1 && cmd[0] == '!') {
789 struct view *next = &pager_view;
790 bool copied;
792 /* Trim the leading '!'. */
793 argv[0] = cmd + 1;
794 copied = argv_format(view->env, &next->argv, argv, FALSE, TRUE);
795 argv[0] = cmd;
797 if (!copied) {
798 report("Argument formatting failed");
799 } else {
800 /* When running random commands, initially show the
801 * command in the title. However, it maybe later be
802 * overwritten if a commit line is selected. */
803 argv_to_string(next->argv, next->ref, sizeof(next->ref), " ");
805 next->dir = NULL;
806 open_pager_view(view, OPEN_PREPARED | OPEN_WITH_STDERR);
809 } else if (!strcmp(cmd, "save-display")) {
810 const char *path = argv[1] ? argv[1] : "tig-display.txt";
812 if (!save_display(path))
813 report("Failed to save screen to %s", path);
814 else
815 report("Saved screen to %s", path);
817 } else if (!strcmp(cmd, "exec")) {
818 struct run_request req = { view->keymap, {}, argv + 1 };
819 enum status_code code = parse_run_request_flags(&req.flags, argv + 1);
821 if (code != SUCCESS) {
822 report("Failed to execute command: %s", get_status_message(code));
823 } else {
824 return exec_run_request(view, &req);
827 } else if (!strcmp(cmd, "toggle")) {
828 enum view_flag flags = VIEW_NO_FLAGS;
829 enum status_code code = prompt_toggle(view, argv, &flags);
830 const char *action = get_status_message(code);
832 if (code != SUCCESS) {
833 report("%s", action);
834 return REQ_NONE;
837 prompt_update_display(flags);
839 if (*action)
840 report("%s", action);
842 } else if (!strcmp(cmd, "script")) {
843 if (is_script_executing()) {
844 report("Scripts cannot be run from scripts");
845 } else if (!open_script(argv[1])) {
846 report("Failed to open %s", argv[1]);
849 } else {
850 struct key key = {};
851 enum status_code code;
852 enum view_flag flags = VIEW_NO_FLAGS;
854 /* Try :<key> */
855 key.modifiers.multibytes = 1;
856 string_ncopy(key.data.bytes, cmd, cmdlen);
857 request = get_keybinding(view->keymap, &key, 1);
858 if (request != REQ_NONE)
859 return request;
861 /* Try :<command> */
862 request = get_request(cmd);
863 if (request != REQ_UNKNOWN)
864 return request;
866 code = set_option(argv[0], argv_size(argv + 1), &argv[1]);
867 if (code != SUCCESS) {
868 report("%s", get_status_message(code));
869 return REQ_NONE;
872 if (!strcmp(cmd, "set")) {
873 struct option_info *toggle;
875 toggle = find_option_info(option_toggles, ARRAY_SIZE(option_toggles),
876 "", argv[1]);
878 if (toggle)
879 flags = toggle->flags;
882 if (flags) {
883 prompt_update_display(flags);
885 } else {
886 request = view_can_refresh(view) ? REQ_REFRESH : REQ_SCREEN_REDRAW;
887 if (!strcmp(cmd, "color"))
888 init_colors();
889 resize_display();
890 redraw_display(TRUE);
894 return REQ_NONE;
897 enum request
898 exec_run_request(struct view *view, struct run_request *req)
900 const char **argv = NULL;
901 bool confirmed = FALSE;
902 enum request request = REQ_NONE;
904 if (!argv_format(view->env, &argv, req->argv, FALSE, TRUE)) {
905 report("Failed to format arguments");
906 return REQ_NONE;
909 if (req->flags.internal) {
910 request = run_prompt_command(view, argv);
912 } else {
913 confirmed = !req->flags.confirm;
915 if (req->flags.confirm) {
916 char cmd[SIZEOF_STR], prompt[SIZEOF_STR];
917 const char *and_exit = req->flags.exit ? " and exit" : "";
919 if (argv_to_string(argv, cmd, sizeof(cmd), " ") &&
920 string_format(prompt, "Run `%s`%s?", cmd, and_exit) &&
921 prompt_yesno(prompt)) {
922 confirmed = TRUE;
926 if (confirmed && argv_remove_quotes(argv))
927 open_external_viewer(argv, NULL, req->flags.silent,
928 !req->flags.exit, FALSE, "");
931 if (argv)
932 argv_free(argv);
933 free(argv);
935 if (request == REQ_NONE) {
936 if (req->flags.confirm && !confirmed)
937 request = REQ_NONE;
939 else if (req->flags.exit)
940 request = REQ_QUIT;
942 else if (!req->flags.internal && watch_dirty(&view->watch))
943 request = REQ_REFRESH;
947 return request;
950 enum request
951 open_prompt(struct view *view)
953 char *cmd = read_prompt(":");
954 const char *argv[SIZEOF_ARG] = { NULL };
955 int argc = 0;
957 if (cmd && !argv_from_string(argv, &argc, cmd)) {
958 report("Too many arguments");
959 return REQ_NONE;
962 return run_prompt_command(view, argv);
965 /* vim: set ts=8 sw=8 noexpandtab: */