📄 rltech.texinfo
字号:
@deftypefun int rl_kill_text (int start, int end)Copy the text between @var{start} and @var{end} in the current lineto the kill ring, appending or prepending to the last kill if thelast command was a kill command. The text is deleted.If @var{start} is less than @var{end},the text is appended, otherwise prepended. If the last command wasnot a kill, a new kill ring slot is used.@end deftypefun@node Utility Functions@subsection Utility Functions@deftypefun int rl_read_key ()Return the next character available. This handles input inserted intothe input stream via @var{pending input} (@pxref{Readline Variables})and @code{rl_stuff_char ()}, macros, and characters read from the keyboard.@end deftypefun@deftypefun int rl_getc (FILE *)Return the next character available from the keyboard.@end deftypefun@deftypefun int rl_stuff_char (int c)Insert @var{c} into the Readline input stream. It will be "read"before Readline attempts to read characters from the terminal with@code{rl_read_key ()}.@end deftypefun@deftypefun int rl_extend_line_buffer (int len)Ensure that @code{rl_line_buffer} has enough space to hold @var{len}characters, possibly reallocating it if necessary.@end deftypefun@deftypefun int rl_initialize ()Initialize or re-initialize Readline's internal state.@end deftypefun@deftypefun int rl_reset_terminal (char *terminal_name)Reinitialize Readline's idea of the terminal settings using@var{terminal_name} as the terminal type (e.g., @code{vt100}).If @var{terminal_name} is NULL, the value of the @code{TERM}environment variable is used.@end deftypefun@deftypefun int alphabetic (int c)Return 1 if @var{c} is an alphabetic character.@end deftypefun@deftypefun int numeric (int c)Return 1 if @var{c} is a numeric character.@end deftypefun@deftypefun int ding ()Ring the terminal bell, obeying the setting of @code{bell-style}.@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{chartypes.h}.@deftypefun int uppercase_p (int c)Return 1 if @var{c} is an uppercase alphabetic character.@end deftypefun@deftypefun int lowercase_p (int c)Return 1 if @var{c} is a lowercase alphabetic character.@end deftypefun@deftypefun int digit_p (int c)Return 1 if @var{c} is a numeric character.@end deftypefun@deftypefun int to_upper (int c)If @var{c} is a lowercase alphabetic character, return the correspondinguppercase character.@end deftypefun@deftypefun int to_lower (int c)If @var{c} is an uppercase alphabetic character, return the correspondinglowercase character.@end deftypefun@deftypefun int digit_value (int c)If @var{c} is a number, return the value it represents.@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 (char *prompt, Vfunction *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 callback when a complete line of input has been entered.@end deftypefun@deftypefun void rl_callback_read_char ()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 ()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@subsection An 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 (uppercase_p (rl_line_buffer[i])) rl_line_buffer[i] = to_lower (rl_line_buffer[i]); else if (lowercase_p (rl_line_buffer[i])) rl_line_buffer[i] = 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 histerminal, or a network connection being broken. There is a class ofsignals that can be sent to the process currently reading input fromthe keyboard. Since Readline changes the terminal attributes when itis called, it needs to perform special processing when a signal isreceived to restore the terminal to a sane state, or provide applicationwriters with functions 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 ()}).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 state, and then calls any@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 ()} to force Readline to update its idea ofthe terminal size when a @code{SIGWINCH} is received.@deftypefun void rl_resize_terminal (void)Update Readline's internal screen size.@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 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 Readlinefunctions intended for interactive use: @var{count} and@var{invoking_key}. It isolates the word to be completed and calls@code{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{completion_matches ()} uses your@dfn{generator} function to generate the list of possible matches, andthen returns the array of these matches. You should place the addressof your generator function in @code{rl_completion_entry_function}.@itemThe generator function is called repeatedly from
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -