updates for several readline examples; update examples in readline documentation; update documentation for --rcfile option

This commit is contained in:
Chet Ramey
2024-07-02 14:34:40 -04:00
parent 5e28a1813c
commit dbff8b786e
10 changed files with 100 additions and 102 deletions
+8 -17
View File
@@ -54,8 +54,10 @@ Copyright (C) 1999 Jeff Solomon
#ifdef READLINE_LIBRARY
# include "readline.h"
# include "history.h"
#else
# include <readline/readline.h>
# include <readline/history.h>
#endif
#ifndef STDIN_FILENO
@@ -92,7 +94,7 @@ Copyright (C) 1999 Jeff Solomon
*/
void process_line(char *line);
int change_prompt(void);
int change_prompt(int, int);
char *get_prompt(void);
int prompt = 1;
@@ -101,7 +103,7 @@ tcflag_t old_lflag;
cc_t old_vtime;
struct termios term;
int
int
main(int c, char **v)
{
fd_set fds;
@@ -170,31 +172,20 @@ process_line(char *line)
}
int
change_prompt(void)
change_prompt(int count, int key)
{
/* toggle the prompt variable */
prompt = !prompt;
/* save away the current contents of the line */
strcpy(line_buf, rl_line_buffer);
/* install a new handler which will change the prompt and erase the current line */
rl_callback_handler_install(get_prompt(), process_line);
/* insert the old text on the new line */
rl_insert_text(line_buf);
/* redraw the current line - this is an undocumented function. It invokes the
* redraw-current-line command.
*/
rl_refresh_line(0, 0);
rl_set_prompt (get_prompt ());
return 0;
}
char *
get_prompt(void)
{
/* The prompts can even be different lengths! */
sprintf(prompt_buf, "%s",
sprintf(prompt_buf, "%s",
prompt ? "Hit ctrl-t to toggle prompt> " : "Pretty cool huh?> ");
return prompt_buf;
}