Merge branch 'js/flush-prompt-before-interative-input'
The interactive input from various codepaths are consolidated and any prompt possibly issued earlier are fflush()ed before we read. * js/flush-prompt-before-interative-input: interactive: explicitly `fflush` stdout before expecting input interactive: refactor code asking the user for interactive inputmaint
						commit
						33feaca6bf
					
				|  | @ -9,6 +9,7 @@ | ||||||
| #include "lockfile.h" | #include "lockfile.h" | ||||||
| #include "dir.h" | #include "dir.h" | ||||||
| #include "run-command.h" | #include "run-command.h" | ||||||
|  | #include "prompt.h" | ||||||
|  |  | ||||||
| static void init_color(struct repository *r, struct add_i_state *s, | static void init_color(struct repository *r, struct add_i_state *s, | ||||||
| 		       const char *slot_name, char *dst, | 		       const char *slot_name, char *dst, | ||||||
|  | @ -289,13 +290,12 @@ static ssize_t list_and_choose(struct add_i_state *s, | ||||||
| 		fputs(singleton ? "> " : ">> ", stdout); | 		fputs(singleton ? "> " : ">> ", stdout); | ||||||
| 		fflush(stdout); | 		fflush(stdout); | ||||||
|  |  | ||||||
| 		if (strbuf_getline(&input, stdin) == EOF) { | 		if (git_read_line_interactively(&input) == EOF) { | ||||||
| 			putchar('\n'); | 			putchar('\n'); | ||||||
| 			if (immediate) | 			if (immediate) | ||||||
| 				res = LIST_AND_CHOOSE_QUIT; | 				res = LIST_AND_CHOOSE_QUIT; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		strbuf_trim(&input); |  | ||||||
|  |  | ||||||
| 		if (!input.len) | 		if (!input.len) | ||||||
| 			break; | 			break; | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ | ||||||
| #include "color.h" | #include "color.h" | ||||||
| #include "diff.h" | #include "diff.h" | ||||||
| #include "compat/terminal.h" | #include "compat/terminal.h" | ||||||
|  | #include "prompt.h" | ||||||
|  |  | ||||||
| enum prompt_mode_type { | enum prompt_mode_type { | ||||||
| 	PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK, | 	PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK, | ||||||
|  | @ -1158,9 +1159,8 @@ static int read_single_character(struct add_p_state *s) | ||||||
| 		return res; | 		return res; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (strbuf_getline(&s->answer, stdin) == EOF) | 	if (git_read_line_interactively(&s->answer) == EOF) | ||||||
| 		return EOF; | 		return EOF; | ||||||
| 	strbuf_trim_trailing_newline(&s->answer); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
| #include "color.h" | #include "color.h" | ||||||
| #include "pathspec.h" | #include "pathspec.h" | ||||||
| #include "help.h" | #include "help.h" | ||||||
|  | #include "prompt.h" | ||||||
|  |  | ||||||
| static int force = -1; /* unset */ | static int force = -1; /* unset */ | ||||||
| static int interactive; | static int interactive; | ||||||
|  | @ -420,7 +421,6 @@ static int find_unique(const char *choice, struct menu_stuff *menu_stuff) | ||||||
| 	return found; | 	return found; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Parse user input, and return choice(s) for menu (menu_stuff). |  * Parse user input, and return choice(s) for menu (menu_stuff). | ||||||
|  * |  * | ||||||
|  | @ -580,9 +580,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff) | ||||||
| 			       clean_get_color(CLEAN_COLOR_RESET)); | 			       clean_get_color(CLEAN_COLOR_RESET)); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (strbuf_getline_lf(&choice, stdin) != EOF) { | 		if (git_read_line_interactively(&choice) == EOF) { | ||||||
| 			strbuf_trim(&choice); |  | ||||||
| 		} else { |  | ||||||
| 			eof = 1; | 			eof = 1; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
|  | @ -662,9 +660,7 @@ static int filter_by_patterns_cmd(void) | ||||||
| 		clean_print_color(CLEAN_COLOR_PROMPT); | 		clean_print_color(CLEAN_COLOR_PROMPT); | ||||||
| 		printf(_("Input ignore patterns>> ")); | 		printf(_("Input ignore patterns>> ")); | ||||||
| 		clean_print_color(CLEAN_COLOR_RESET); | 		clean_print_color(CLEAN_COLOR_RESET); | ||||||
| 		if (strbuf_getline_lf(&confirm, stdin) != EOF) | 		if (git_read_line_interactively(&confirm) == EOF) | ||||||
| 			strbuf_trim(&confirm); |  | ||||||
| 		else |  | ||||||
| 			putchar('\n'); | 			putchar('\n'); | ||||||
|  |  | ||||||
| 		/* quit filter_by_pattern mode if press ENTER or Ctrl-D */ | 		/* quit filter_by_pattern mode if press ENTER or Ctrl-D */ | ||||||
|  | @ -760,9 +756,7 @@ static int ask_each_cmd(void) | ||||||
| 			qname = quote_path_relative(item->string, NULL, &buf); | 			qname = quote_path_relative(item->string, NULL, &buf); | ||||||
| 			/* TRANSLATORS: Make sure to keep [y/N] as is */ | 			/* TRANSLATORS: Make sure to keep [y/N] as is */ | ||||||
| 			printf(_("Remove %s [y/N]? "), qname); | 			printf(_("Remove %s [y/N]? "), qname); | ||||||
| 			if (strbuf_getline_lf(&confirm, stdin) != EOF) { | 			if (git_read_line_interactively(&confirm) == EOF) { | ||||||
| 				strbuf_trim(&confirm); |  | ||||||
| 			} else { |  | ||||||
| 				putchar('\n'); | 				putchar('\n'); | ||||||
| 				eof = 1; | 				eof = 1; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								prompt.c
								
								
								
								
							
							
						
						
									
										12
									
								
								prompt.c
								
								
								
								
							|  | @ -74,3 +74,15 @@ char *git_prompt(const char *prompt, int flags) | ||||||
| 	} | 	} | ||||||
| 	return r; | 	return r; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int git_read_line_interactively(struct strbuf *line) | ||||||
|  | { | ||||||
|  | 	int ret; | ||||||
|  |  | ||||||
|  | 	fflush(stdout); | ||||||
|  | 	ret = strbuf_getline_lf(line, stdin); | ||||||
|  | 	if (ret != EOF) | ||||||
|  | 		strbuf_trim_trailing_newline(line); | ||||||
|  |  | ||||||
|  | 	return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								prompt.h
								
								
								
								
							
							
						
						
									
										2
									
								
								prompt.h
								
								
								
								
							|  | @ -6,4 +6,6 @@ | ||||||
|  |  | ||||||
| char *git_prompt(const char *prompt, int flags); | char *git_prompt(const char *prompt, int flags); | ||||||
|  |  | ||||||
|  | int git_read_line_interactively(struct strbuf *line); | ||||||
|  |  | ||||||
| #endif /* PROMPT_H */ | #endif /* PROMPT_H */ | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								shell.c
								
								
								
								
							
							
						
						
									
										4
									
								
								shell.c
								
								
								
								
							|  | @ -4,6 +4,7 @@ | ||||||
| #include "strbuf.h" | #include "strbuf.h" | ||||||
| #include "run-command.h" | #include "run-command.h" | ||||||
| #include "alias.h" | #include "alias.h" | ||||||
|  | #include "prompt.h" | ||||||
|  |  | ||||||
| #define COMMAND_DIR "git-shell-commands" | #define COMMAND_DIR "git-shell-commands" | ||||||
| #define HELP_COMMAND COMMAND_DIR "/help" | #define HELP_COMMAND COMMAND_DIR "/help" | ||||||
|  | @ -76,12 +77,11 @@ static void run_shell(void) | ||||||
| 		int count; | 		int count; | ||||||
|  |  | ||||||
| 		fprintf(stderr, "git> "); | 		fprintf(stderr, "git> "); | ||||||
| 		if (strbuf_getline_lf(&line, stdin) == EOF) { | 		if (git_read_line_interactively(&line) == EOF) { | ||||||
| 			fprintf(stderr, "\n"); | 			fprintf(stderr, "\n"); | ||||||
| 			strbuf_release(&line); | 			strbuf_release(&line); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		strbuf_trim(&line); |  | ||||||
| 		rawargs = strbuf_detach(&line, NULL); | 		rawargs = strbuf_detach(&line, NULL); | ||||||
| 		split_args = xstrdup(rawargs); | 		split_args = xstrdup(rawargs); | ||||||
| 		count = split_cmdline(split_args, &argv); | 		count = split_cmdline(split_args, &argv); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano