mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-10 20:20:38 +02:00
updates for several readline examples; update examples in readline documentation; update documentation for --rcfile option
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,15 @@
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
static void cb_linehandler (char *);
|
||||
static void signandler (int);
|
||||
|
||||
int running, sigwinch_received;
|
||||
int running;
|
||||
int sigwinch_received;
|
||||
const char *prompt = "rltest$ ";
|
||||
|
||||
/* Handle SIGWINCH and window size changes when readline is not active and
|
||||
@@ -73,9 +76,11 @@ main (int c, char **v)
|
||||
fd_set fds;
|
||||
int r;
|
||||
|
||||
/* Set the default locale values according to environment variables. */
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
/* Handle SIGWINCH */
|
||||
/* Handle window size changes when readline is not active and reading
|
||||
characters. */
|
||||
signal (SIGWINCH, sighandler);
|
||||
|
||||
/* Install the line handler. */
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
/* Used for select(2) */
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
/* Standard readline include files. */
|
||||
#if defined (READLINE_LIBRARY)
|
||||
# include "readline.h"
|
||||
@@ -22,6 +23,10 @@
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
static void cb_linehandler (char *);
|
||||
static void sigint_sighandler (int);
|
||||
static int sigint_handler (int);
|
||||
@@ -51,18 +56,18 @@ cb_readline (void)
|
||||
fd_set fds;
|
||||
int r, err;
|
||||
char *not_done = "";
|
||||
|
||||
|
||||
/* Install the line handler. */
|
||||
rl_callback_handler_install (prompt, cb_linehandler);
|
||||
|
||||
if (RL_ISSTATE (RL_STATE_ISEARCH))
|
||||
fprintf(stderr, "cb_readline: after handler install, state (ISEARCH) = %d", rl_readline_state);
|
||||
else if (RL_ISSTATE (RL_STATE_NSEARCH))
|
||||
fprintf(stderr, "cb_readline: after handler install, state (NSEARCH) = %d", rl_readline_state);
|
||||
/* MULTIKEY VIMOTION NUMERICARG _rl_callback_func */
|
||||
if (RL_ISSTATE (RL_STATE_ISEARCH))
|
||||
fprintf(stderr, "cb_readline: after handler install, state (ISEARCH) = %lu", rl_readline_state);
|
||||
else if (RL_ISSTATE (RL_STATE_NSEARCH))
|
||||
fprintf(stderr, "cb_readline: after handler install, state (NSEARCH) = %lu", rl_readline_state);
|
||||
/* MULTIKEY VIMOTION NUMERICARG _rl_callback_func */
|
||||
|
||||
FD_ZERO (&fds);
|
||||
FD_SET (fileno (rl_instream), &fds);
|
||||
FD_SET (fileno (rl_instream), &fds);
|
||||
|
||||
input_string = not_done;
|
||||
|
||||
@@ -76,10 +81,10 @@ else if (RL_ISSTATE (RL_STATE_NSEARCH))
|
||||
while (r == 0)
|
||||
{
|
||||
struct timeval timeout = {0, 100000};
|
||||
struct timeval *timeoutp = NULL;
|
||||
struct timeval *timeoutp = NULL;
|
||||
|
||||
timeoutp = &timeout;
|
||||
FD_SET (fileno (rl_instream), &fds);
|
||||
FD_SET (fileno (rl_instream), &fds);
|
||||
r = select (FD_SETSIZE, &fds, NULL, NULL, timeoutp);
|
||||
err = errno;
|
||||
}
|
||||
@@ -115,7 +120,6 @@ sigint_handler (int s)
|
||||
rl_cleanup_after_signal ();
|
||||
rl_callback_handler_remove ();
|
||||
saw_signal = 0;
|
||||
fprintf(stderr, "sigint_handler: readline state = %d\r\n", rl_readline_state);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
/* Need a configure check here to turn this into a real application. */
|
||||
#if 1 /* LINUX */
|
||||
#include <pty.h>
|
||||
#else
|
||||
@@ -31,10 +32,14 @@
|
||||
|
||||
#ifdef READLINE_LIBRARY
|
||||
# include "readline.h"
|
||||
# include "history.h"
|
||||
#else
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
int tty_reset(int fd);
|
||||
|
||||
/**
|
||||
* Master/Slave PTY used to keep readline off of stdin/stdout.
|
||||
*/
|
||||
@@ -301,7 +306,8 @@ tty_off_xon_xoff (int fd)
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int tty_reset(int fd)
|
||||
int
|
||||
tty_reset(int fd)
|
||||
{
|
||||
if(ttystate != TCBREAK)
|
||||
return (0);
|
||||
|
||||
Reference in New Issue
Block a user