📄 rltech.texi
字号:
before @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. If either @var{rows} or @var{columns} is less thanor equal to 0, Readline's idea of that terminal dimension is unchanged.@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 deftypefun@deftypefun void rl_reset_screen_size (void)Cause Readline to reobtain the screen size and recalculate its dimensions.@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 Completers@cindex application-specific completion functionsTypically, 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 sectiondescribes exactly what such functions must do, and provides an example.There are three major functions used to perform completion:@enumerate@itemThe user-interface function @code{rl_complete()}. This function iscalled with the same arguments as other bindable Readline functions:@var{count} and @var{invoking_key}.It isolates the word to be completed and calls@code{rl_completion_matches()} to generate a list of possible completions.It then either lists the possible completions, inserts the possiblecompletions, or actually performs thecompletion, depending on which behavior is desired.@itemThe internal function @code{rl_completion_matches()} uses anapplication-supplied @dfn{generator} function to generate the list ofpossible matches, and then returns the array of these matches.The caller should place the address of its generator function in@code{rl_completion_entry_function}.@itemThe generator function is called repeatedly from@code{rl_completion_matches()}, returning a string each time. Thearguments to the generator function are @var{text} and @var{state}.@var{text} is the partial word to be completed. @var{state} is zero thefirst time the function is called, allowing the generator to performany necessary initialization, and a positive non-zero integer foreach subsequent call. The generator function returns@code{(char *)NULL} to inform @code{rl_completion_matches()} that there areno more possibilities left. Usually the generator function computes thelist of possible completions when @var{state} is zero, and returns themone at a time on subsequent calls. Each string the generator functionreturns as a match must be allocated with @code{malloc()}; Readlinefrees the strings when it has finished with them.Such a generator function is referred to as an@dfn{application-specific completion function}.@end enumerate@deftypefun int rl_complete (int ignore, int invoking_key)Complete the word at or before point. You have supplied the functionthat does the initial simple matching selection algorithm (see@code{rl_completion_matches()}). The default is to do filename completion.@end deftypefun@deftypevar {rl_compentry_func_t *} rl_completion_entry_functionThis is a pointer to the generator function for@code{rl_completion_matches()}.If the value of @code{rl_completion_entry_function} is@code{NULL} then the default filename generatorfunction, @code{rl_filename_completion_function()}, is used.An @dfn{application-specific completion function} is a function whoseaddress is assigned to @code{rl_completion_entry_function} and whosereturn values are used to generate possible completions.@end deftypevar@node Completion Functions@subsection Completion FunctionsHere is the complete list of callable completion functions present inReadline.@deftypefun int rl_complete_internal (int what_to_do)Complete the word at or before point. @var{what_to_do} says what to dowith the completion. A value of @samp{?} means list the possiblecompletions. @samp{TAB} means do standard completion. @samp{*} meansinsert all of the possible completions. @samp{!} means to displayall of the possible completions, if there is more than one, as well asperforming partial completion. @samp{@@} is similar to @samp{!}, butpossible completions are not listed if the possible completions sharea common prefix.@end deftypefun@deftypefun int rl_complete (int ignore, int invoking_key)Complete the word at or before point. You have supplied the functionthat does the initial simple matching selection algorithm (see@code{rl_completion_matches()} and @code{rl_completion_entry_function}).The default is to do filenamecompletion. This calls @code{rl_complete_internal()} with anargument depending on @var{invoking_key}.@end deftypefun@deftypefun int rl_possible_completions (int count, int invoking_key)List the possible completions. See description of @code{rl_complete()}. This calls @code{rl_complete_internal()} with an argument of@samp{?}.@end deftypefun@deftypefun int rl_insert_completions (int count, int invoking_key)Insert the list of possible completions into the line, deleting thepartially-completed word. See description of @code{rl_complete()}.This calls @code{rl_complete_internal()} with an argument of @samp{*}.@end deftypefun@deftypefun int rl_completion_mode (rl_command_func_t *cfunc)Returns the apppriate value to pass to @code{rl_complete_internal()}depending on whether @var{cfunc} was called twice in succession andthe values of the @code{show-all-if-ambiguous} and@code{show-all-if-unmodified} variables.Application-specific completion functions may use this function to presentthe same interface as @code{rl_complete()}.@end deftypefun@deftypefun {char **} rl_completion_matches (const char *text, rl_compentry_func_t *entry_func)Returns an array of strings which is a list of completions for@var{text}. If there are no completions, returns @code{NULL}.The first entry in the returned array is the substitution for @var{text}.The remaining entries are the possible completions. The array isterminated with a @code{NULL} pointer.@var{entry_func} is a function of two args, and returns a@code{char *}. The first argument is @var{text}. The second is astate argument; it is zero on the first call, and non-zero on subsequentcalls. @var{entry_func} returns a @code{NULL} pointer to the callerwhen there are no more matches.@end deftypefun@deftypefun {char *} rl_filename_completion_function (const char *text, int state)A generator function for filename completion in the general case.@var{text} is a partial filename.The Bash source is a useful reference for writing application-specificcompletion functions (the Bash completion functions call this and otherReadline functions).@end deftypefun@deftypefun {char *} rl_username_completion_function (const char *text, int state)A completion generator for usernames. @var{text} contains a partialusername preceded by a random character (usually @samp{~}). As with allcompletion generators, @var{state} is zero on the first call and non-zerofor subsequent calls.@end deftypefun@node Completion Variables@subsection Completion Variables@deftypevar {rl_compentry_func_t *} rl_completion_entry_functionA pointer to the generator function for @code{rl_completion_matches()}.@code{NULL} means to use @code{rl_filename_completion_function()},the default filename completer.@end deftypevar@deftypevar {rl_completion_func_t *} rl_attempted_completion_functionA pointer to an alternative function to create matches.The function is called with @var{text}, @var{start}, and @var{end}.@var{start} and @var{end} are indices in @code{rl_line_buffer} definingthe boundaries of @var{text}, which is a character string.If this function exists and returns @code{NULL}, or if this variable isset to @code{NULL}, then @code{rl_complete()} will call the value of@code{rl_completion_entry_function} to generate matches, otherwise thearray of strings returned will be used.If this function sets the @code{rl_attempted_completion_over}variable to a non-zero value, Readline will not perform its defaultcompletion even if this function returns no matches.@end deftypevar@deftypevar {rl_quote_func_t *} rl_filename_quoting_functionA pointer to a function that will quote a filename in anapplication-specific fashion. This is called if filename completion is beingattempted and one of the characters in @code{rl_filename_quote_characters}appears in a completed filename. The function is called with@var{text}, @var{match_type}, and @var{quote_pointer}. The @var{text}is the filename to be quoted. The @var{match_type} is either@code{SINGLE_MATCH}, if there is only one completion match, or@code{MULT_MATCH}. Some functions use this to decide whether or not toinsert a closing quote character. The @var{quote_pointer} is a pointerto any opening quote character the user typed. Some functions chooseto reset this character.@end deftypevar@deftypevar {rl_dequote_func_t *} rl_filename_dequoting_functionA pointer to a function that will remove application-specific quotingcharacters from a filename before completion is attempted, so thosecharacters do not interfere with matching the text against names inthe filesystem. It is called with @var{text}, the text of the wordto be dequoted, and @var{quote_char}, which is the quoting character that delimits the filename (usually @samp{'} or @samp{"}). If@var{quote_char} is zero, the filename was not in an embedded string.@end deftypevar@deftypevar {rl_linebuf_func_t *} rl_char_is_quoted_pA pointer to a function to call that determines whether or not a specificcharacter in the line buffer is quoted, according to whatever quotingmechanism the program calling Readline uses. The function is called withtwo arguments: @var{text}, the text of the line, and @var{index}, theindex of the character in the line. It is used to decide whether acharacter found in @code{rl_completer_word_break_characters} should beused
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -