📄 rltech.texinfo
字号:
Ring the terminal bell, obeying the setting of @code{bell-style}.@end deftypefun@deftypefun int rl_alphabetic (int c)Return 1 if @var{c} is an alphabetic character.@end deftypefun@deftypefun void rl_display_match_list (char **matches, int len, int max)A convenience function for displaying a list of strings incolumnar format on Readline's output stream. @code{matches} is the listof strings, in argv format, such as a list of completion matches.@code{len} is the number of strings in @code{matches}, and @code{max}is the length of the longest string in @code{matches}. This function usesthe setting of @code{print-completions-horizontally} to select how thematches are displayed (@pxref{Readline Init File Syntax}).@end deftypefunThe following are implemented as macros, defined in @code{chardefs.h}.Applications should refrain from using them.@deftypefun int _rl_uppercase_p (int c)Return 1 if @var{c} is an uppercase alphabetic character.@end deftypefun@deftypefun int _rl_lowercase_p (int c)Return 1 if @var{c} is a lowercase alphabetic character.@end deftypefun@deftypefun int _rl_digit_p (int c)Return 1 if @var{c} is a numeric character.@end deftypefun@deftypefun int _rl_to_upper (int c)If @var{c} is a lowercase alphabetic character, return the correspondinguppercase character.@end deftypefun@deftypefun int _rl_to_lower (int c)If @var{c} is an uppercase alphabetic character, return the correspondinglowercase character.@end deftypefun@deftypefun int _rl_digit_value (int c)If @var{c} is a number, return the value it represents.@end deftypefun@node Miscellaneous Functions@subsection Miscellaneous Functions@deftypefun int rl_macro_bind (const char *keyseq, const char *macro, Keymap map)Bind the key sequence @var{keyseq} to invoke the macro @var{macro}.The binding is performed in @var{map}. When @var{keyseq} is invoked, the@var{macro} will be inserted into the line. This function is deprecated;use @code{rl_generic_bind()} instead.@end deftypefun@deftypefun void rl_macro_dumper (int readable)Print the key sequences bound to macros and their values, usingthe current keymap, to @code{rl_outstream}.If @var{readable} is non-zero, the list is formatted in such a waythat it can be made part of an @code{inputrc} file and re-read.@end deftypefun@deftypefun int rl_variable_bind (const char *variable, const char *value)Make the Readline variable @var{variable} have @var{value}.This behaves as if the readline command@samp{set @var{variable} @var{value}} had been executed in an @code{inputrc}file (@pxref{Readline Init File Syntax}).@end deftypefun@deftypefun void rl_variable_dumper (int readable)Print the readline variable names and their current valuesto @code{rl_outstream}.If @var{readable} is non-zero, the list is formatted in such a waythat it can be made part of an @code{inputrc} file and re-read.@end deftypefun@deftypefun int rl_set_paren_blink_timeout (int u)Set the time interval (in microseconds) that Readline waits when showinga balancing character when @code{blink-matching-paren} has been enabled.@end deftypefun@node Alternate Interface@subsection Alternate InterfaceAn alternate interface is available to plain @code{readline()}. Someapplications need to interleave keyboard I/O with file, device, orwindow system I/O, typically by using a main loop to @code{select()}on various file descriptors. To accomodate this need, readline canalso be invoked as a `callback' function from an event loop. Thereare functions available to make this easy.@deftypefun void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler)Set up the terminal for readline I/O and display the initialexpanded value of @var{prompt}. Save the value of @var{lhandler} touse as a function to call when a complete line of input has been entered.The function takes the text of the line as an argument.@end deftypefun@deftypefun void rl_callback_read_char (void)Whenever an application determines that keyboard input is available, itshould call @code{rl_callback_read_char()}, which will read the nextcharacter from the current input source. If that character completes theline, @code{rl_callback_read_char} will invoke the @var{lhandler}function saved by @code{rl_callback_handler_install} to process theline. @code{EOF} is indicated by calling @var{lhandler} with a@code{NULL} line.@end deftypefun@deftypefun void rl_callback_handler_remove (void)Restore the terminal to its initial state and remove the line handler.This may be called from within a callback as well as independently.@end deftypefun@node A Readline Example@subsection A Readline ExampleHere is a function which changes lowercase characters to their uppercaseequivalents, and uppercase characters to lowercase. Ifthis function was bound to @samp{M-c}, then typing @samp{M-c} wouldchange the case of the character under point. Typing @samp{M-1 0 M-c}would change the case of the following 10 characters, leaving the cursor onthe last character changed.@example/* Invert the case of the COUNT following characters. */intinvert_case_line (count, key) int count, key;@{ register int start, end, i; start = rl_point; if (rl_point >= rl_end) return (0); if (count < 0) @{ direction = -1; count = -count; @} else direction = 1; /* Find the end of the range to modify. */ end = start + (count * direction); /* Force it to be within range. */ if (end > rl_end) end = rl_end; else if (end < 0) end = 0; if (start == end) return (0); if (start > end) @{ int temp = start; start = end; end = temp; @} /* Tell readline that we are modifying the line, so it will save the undo information. */ rl_modifying (start, end); for (i = start; i != end; i++) @{ if (_rl_uppercase_p (rl_line_buffer[i])) rl_line_buffer[i] = _rl_to_lower (rl_line_buffer[i]); else if (_rl_lowercase_p (rl_line_buffer[i])) rl_line_buffer[i] = _rl_to_upper (rl_line_buffer[i]); @} /* Move point to on top of the last character changed. */ rl_point = (direction == 1) ? end - 1 : start; return (0);@}@end example@node Readline Signal Handling@section Readline Signal HandlingSignals are asynchronous events sent to a process by the Unix kernel,sometimes on behalf of another process. They are intended to indicateexceptional events, like a user pressing the interrupt key on his terminal,or a network connection being broken. There is a class of signals that canbe sent to the process currently reading input from the keyboard. SinceReadline changes the terminal attributes when it is called, it needs toperform special processing when such a signal is received in order torestore the terminal to a sane state, or provide application writers withfunctions to do so manually. Readline contains an internal signal handler that is installed for anumber of signals (@code{SIGINT}, @code{SIGQUIT}, @code{SIGTERM},@code{SIGALRM}, @code{SIGTSTP}, @code{SIGTTIN}, and @code{SIGTTOU}).When one of these signals is received, the signal handlerwill reset the terminal attributes to those that were in effect before@code{readline()} was called, reset the signal handling to what it wasbefore @code{readline()} was called, and resend the signal to the callingapplication.If and when the calling application's signal handler returns, Readlinewill reinitialize the terminal and continue to accept input.When a @code{SIGINT} is received, the Readline signal handler performssome additional work, which will cause any partially-entered line to beaborted (see the description of @code{rl_free_line_state()} below).There is an additional Readline signal handler, for @code{SIGWINCH}, whichthe kernel sends to a process whenever the terminal's size changes (forexample, if a user resizes an @code{xterm}). The Readline @code{SIGWINCH}handler updates Readline's internal screen size information, and then callsany @code{SIGWINCH} signal handler the calling application has installed. Readline calls the application's @code{SIGWINCH} signal handler withoutresetting the terminal to its original state. If the application's signalhandler does more than update its idea of the terminal size and return (forexample, a @code{longjmp} back to a main processing loop), it @emph{must}call @code{rl_cleanup_after_signal()} (described below), to restore theterminal state. Readline provides two variables that allow application writers tocontrol whether or not it will catch certain signals and act on themwhen they are received. It is important that applications change thevalues of these variables only when calling @code{readline()}, not ina signal handler, so Readline's internal signal state is not corrupted.@deftypevar int rl_catch_signalsIf this variable is non-zero, Readline will install signal handlers for@code{SIGINT}, @code{SIGQUIT}, @code{SIGTERM}, @code{SIGALRM},@code{SIGTSTP}, @code{SIGTTIN}, and @code{SIGTTOU}.The default value of @code{rl_catch_signals} is 1.@end deftypevar@deftypevar int rl_catch_sigwinchIf this variable is non-zero, Readline will install a signal handler for@code{SIGWINCH}.The default value of @code{rl_catch_sigwinch} is 1.@end deftypevarIf an application does not wish to have Readline catch any signals, orto handle signals other than those Readline catches (@code{SIGHUP},for example), Readline provides convenience functions to do the necessary terminaland internal state cleanup upon receipt of a signal.@deftypefun void rl_cleanup_after_signal (void)This function will reset the state of the terminal to what it was before@code{readline()} was called, and remove the Readline signal handlers forall signals, depending on the values of @code{rl_catch_signals} and@code{rl_catch_sigwinch}.@end deftypefun@deftypefun void rl_free_line_state (void)This will free any partial state associated with the current input line(undo information, any partial history entry, any partially-enteredkeyboard macro, and any partially-entered numeric argument). Thisshould be called before @code{rl_cleanup_after_signal()}. TheReadline signal handler for @code{SIGINT} calls this to abort thecurrent input line.@end deftypefun@deftypefun void rl_reset_after_signal (void)This will reinitialize the terminal and reinstall any Readline signalhandlers, depending on the values of @code{rl_catch_signals} and@code{rl_catch_sigwinch}.@end deftypefunIf an application does not wish Readline to catch @code{SIGWINCH}, it maycall @code{rl_resize_terminal()} or @code{rl_set_screen_size()} to forceReadline to update its idea of the terminal size when a @code{SIGWINCH}is received.@deftypefun void rl_resize_terminal (void)Update Readline's internal screen size by reading values from the kernel.@end deftypefun@deftypefun void rl_set_screen_size (int rows, int cols)Set Readline's idea of the terminal size to @var{rows} rows and@var{cols} columns.@end deftypefunIf an application does not want to install a @code{SIGWINCH} handler, butis still interested in the screen dimensions, Readline's idea of the screensize may be queried.@deftypefun void rl_get_screen_size (int *rows, int *cols)Return Readline's idea of the terminal's size in thevariables pointed to by the arguments.@end deftypefunThe following functions install and remove Readline's signal handlers.@deftypefun int rl_set_signals (void)Install Readline's signal handler for @code{SIGINT}, @code{SIGQUIT},@code{SIGTERM}, @code{SIGALRM}, @code{SIGTSTP}, @code{SIGTTIN},@code{SIGTTOU}, and @code{SIGWINCH}, depending on the values of@code{rl_catch_signals} and @code{rl_catch_sigwinch}.@end deftypefun@deftypefun int rl_clear_signals (void)Remove all of the Readline signal handlers installed by@code{rl_set_signals()}.@end deftypefun@node Custom Completers@section Custom CompletersTypically, a program that reads commands from the user has a way ofdisambiguating commands and data. If your program is one of these, thenit can provide completion for commands, data, or both.The following sections describe how your program and Readlinecooperate to provide this service.@menu* How Completing Works:: The logic used to do completion.* Completion Functions:: Functions provided by Readline.* Completion Variables:: Variables which control completion.* A Short Completion Example:: An example of writing completer subroutines.@end menu@node How Completing Works@subsection How Completing WorksIn order to complete some text, the full list of possible completionsmust be available. That is, it is not possible to accuratelyexpand a partial word without knowing all of the possible wordswhich make sense in that context. The Readline library providesthe user interface to completion, and two of the most commoncompletion functions: filename and username. For completing other typesof text, you must write your own completion function. This section
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -