char *deal_with_termcap(t_shell *sh) { t_prompt *prompt; int ret; char buff[4]; char *str; prompt = init_prompt(); stock_prompt(prompt, 0); prompt_print(prompt, 1); str = NULL; while ((ret = read(0, buff, BUFF_SIZE) != -1)) { prompt_shell(sh, prompt, buff); if (buff[0] == 4 && !prompt->cmd[0]) exit_eof(sh, prompt); if (buff[0] == 10) { str = input_return(sh, prompt); break ; } ft_bzero(buff, 4); } free_prompt(&prompt); return (str); }
char *my_prompt(t_glob *glob) { t_prompt *prompt; char *str; str = NULL; prompt = init_prompt(glob); if (prompt) str = prompt_dispatcher(glob, prompt); if (str && my_strlen(str) > 0) add_hist_beg(glob, str); else { xfree(str); return (NULL); } free_prompt(prompt); return (str); }
//------------------------------------------------------------------------------ static char* call_readline_impl(const char* prompt) { static int initialised = 0; int expand_result; char* text; char* expanded; char* prepared_prompt; char cwd_cache[MAX_PATH]; // Initialisation if (!initialised) { initialise_clink_settings(); initialise_lua(); load_history(); rl_catch_signals = 0; rl_startup_hook = initialise_hook; initialised = 1; } // If no prompt was provided assume the line is prompted already and // extract it. If a prompt was provided filter it through Lua. prepared_prompt = NULL; if (prompt == NULL) { prepared_prompt = extract_prompt(1); // Even though we're not going to display filtered result the extracted // prompt is run through Lua. This is a little bit of a hack, but helps // to keep behaviour consistent. if (prepared_prompt != NULL) { char buffer[1024]; str_cpy(buffer, prepared_prompt, sizeof(buffer)); lua_filter_prompt(buffer, sizeof_array(buffer)); } } else { prepared_prompt = filter_prompt(prompt); } GetCurrentDirectory(sizeof_array(cwd_cache), cwd_cache); // Call readline do { rl_already_prompted = (prompt == NULL); text = readline(prepared_prompt ? prepared_prompt : ""); if (!text) { goto call_readline_epilogue; } // Expand history designators in returned buffer. expanded = NULL; expand_result = history_expand(text, &expanded); if (expand_result < 0) { free(expanded); } else { free(text); text = expanded; // If there was some expansion then display the expanded result. if (expand_result > 0) { hooked_fprintf(NULL, "History expansion: %s\n", text); } } add_to_history(text); } while (!text || expand_result == 2); call_readline_epilogue: free_prompt(prepared_prompt); SetCurrentDirectory(cwd_cache); return text; }
//------------------------------------------------------------------------------ static char* call_readline_impl(const char* prompt) { static int initialised = 0; int expand_result; char* text; char* expanded; char* prepared_prompt; char cwd_cache[MAX_PATH]; // Turn off EOL wrapping as Readline will take care of it. { HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleMode(handle_stdout, ENABLE_PROCESSED_OUTPUT); } // Initialisation if (!initialised) { initialise_clink_settings(); initialise_lua(); initialise_fwrite(); load_history(); history_inhibit_expansion_function = history_expand_control; rl_catch_signals = 0; rl_startup_hook = initialise_hook; initialised = 1; } // If no prompt was provided assume the line is prompted already and // extract it. If a prompt was provided filter it through Lua. prepared_prompt = NULL; if (prompt == NULL) { prepared_prompt = extract_prompt(1); // Even though we're not going to display filtered result the extracted // prompt is run through Lua. This is a little bit of a hack, but helps // to keep behaviour consistent. if (prepared_prompt != NULL) { char buffer[1024]; str_cpy(buffer, prepared_prompt, sizeof(buffer)); lua_filter_prompt(buffer, sizeof_array(buffer)); } } else { prepared_prompt = filter_prompt(prompt); } GetCurrentDirectory(sizeof_array(cwd_cache), cwd_cache); do { // Call readline rl_already_prompted = (prompt == NULL); text = readline(prepared_prompt ? prepared_prompt : ""); if (!text) { goto call_readline_epilogue; } // Expand history designators in returned buffer. expanded = NULL; expand_result = expand_from_history(text, &expanded); if (expand_result > 0 && expanded != NULL) { free(text); text = expanded; // If there was some expansion then display the expanded result. if (expand_result > 0) { hooked_fprintf(NULL, "History expansion: %s\n", text); } } // Should we read the history from disk. if (get_clink_setting_int("history_io")) { load_history(); add_to_history(text); save_history(); } else add_to_history(text); } while (!text || expand_result == 2); call_readline_epilogue: free_prompt(prepared_prompt); SetCurrentDirectory(cwd_cache); return text; }