1 '\" te
   2 .\" Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
   3 .\" All Rights Reserved.
   4 .\" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
   5 .\" "Software"), to deal in the Software without restriction, including
   6 .\" without limitation the rights to use, copy, modify, merge, publish,
   7 .\" distribute, and/or sell copies of the Software, and to permit persons
   8 .\" to whom the Software is furnished to do so, provided that the above
   9 .\" copyright notice(s) and this permission notice appear in all copies of
  10 .\" the Software and that both the above copyright notice(s) and this
  11 .\" permission notice appear in supporting documentation.
  12 .\"
  13 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
  16 .\" OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  17 .\" HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
  18 .\" INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
  19 .\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  20 .\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  21 .\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22 .\"
  23 .\" Except as contained in this notice, the name of a copyright holder
  24 .\" shall not be used in advertising or otherwise to promote the sale, use
  25 .\" or other dealings in this Software without prior written authorization
  26 .\" of the copyright holder.
  27 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
  28 .TH GL_GET_LINE 3TECLA "January 18, 2020"
  29 .SH NAME
  30 gl_get_line, new_GetLine, del_GetLine, gl_customize_completion,
  31 gl_change_terminal, gl_configure_getline, gl_load_history, gl_save_history,
  32 gl_group_history, gl_show_history, gl_watch_fd, gl_inactivity_timeout,
  33 gl_terminal_size, gl_set_term_size, gl_resize_history, gl_limit_history,
  34 gl_clear_history, gl_toggle_history, gl_lookup_history, gl_state_of_history,
  35 gl_range_of_history, gl_size_of_history, gl_echo_mode, gl_replace_prompt,
  36 gl_prompt_style, gl_ignore_signal, gl_trap_signal, gl_last_signal,
  37 gl_completion_action, gl_register_action, gl_display_text, gl_return_status,
  38 gl_error_message, gl_catch_blocked, gl_list_signals, gl_bind_keyseq,
  39 gl_erase_terminal, gl_automatic_history, gl_append_history, gl_query_char,
  40 gl_read_char \- allow the user to compose an input line
  41 .SH SYNOPSIS
  42 .nf
  43 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-ltecla\fR [ \fIlibrary\fR\&.\|.\|. ]
  44 #include <stdio.h>
  45 #include <libtecla.h>
  46 
  47 \fBGetLine *\fR\fBnew_GetLine\fR(\fBsize_t\fR \fIlinelen\fR, \fBsize_t\fR \fIhistlen\fR);
  48 .fi
  49 
  50 .LP
  51 .nf
  52 \fBGetLine *\fR\fBdel_GetLine\fR(\fBGetLine *\fR\fIgl\fR);
  53 .fi
  54 
  55 .LP
  56 .nf
  57 \fBchar *\fR\fBgl_get_line\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIprompt\fR,
  58      \fBconst char *\fR\fIstart_line\fR, \fBint\fR \fIstart_pos\fR);
  59 .fi
  60 
  61 .LP
  62 .nf
  63 \fBint\fR \fBgl_query_char\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIprompt\fR, \fBchar\fR \fIdefchar\fR);
  64 .fi
  65 
  66 .LP
  67 .nf
  68 \fBint\fR \fBgl_read_char\fR(\fBGetLine *\fR\fIgl\fR);
  69 .fi
  70 
  71 .LP
  72 .nf
  73 \fBint\fR \fBgl_customize_completion\fR(\fBGetLine *\fR\fIgl\fR, \fBvoid *\fR\fIdata\fR,
  74      \fBCplMatchFn *\fR\fImatch_fn\fR);
  75 .fi
  76 
  77 .LP
  78 .nf
  79 \fBint\fR \fBgl_change_terminal\fR(\fBGetLine *\fR\fIgl\fR, \fBFILE *\fR\fIinput_fp\fR,
  80      \fBFILE *\fR\fIoutput_fp\fR, \fBconst char *\fR\fIterm\fR);
  81 .fi
  82 
  83 .LP
  84 .nf
  85 \fBint\fR \fBgl_configure_getline\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIapp_string\fR,
  86      \fBconst char *\fR\fIapp_file\fR,\ \fBconst char *\fR\fIuser_file\fR);
  87 .fi
  88 
  89 .LP
  90 .nf
  91 \fBint\fR \fBgl_bind_keyseq\fR(\fBGetLine *\fR\fIgl\fR, \fBGlKeyOrigin\fR \fIorigin\fR,
  92      \fBconst char *\fR\fIkeyseq\fR, \fBconst char *\fR\fIaction\fR);
  93 .fi
  94 
  95 .LP
  96 .nf
  97 \fBint\fR \fBgl_save_history\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIfilename\fR,
  98      \fBconst char *\fR\fIcomment\fR, \fBint\fR \fImax_lines\fR);
  99 .fi
 100 
 101 .LP
 102 .nf
 103 \fBint\fR \fBgl_load_history\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIfilename\fR,
 104      \fBconst char *\fR\fIcomment\fR);
 105 .fi
 106 
 107 .LP
 108 .nf
 109 \fBint\fR \fBgl_watch_fd\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIfd\fR, \fBGlFdEvent\fR \fIevent\fR,
 110      \fBGlFdEventFn *\fR\fIcallback\fR, \fBvoid *\fR\fIdata\fR);
 111 .fi
 112 
 113 .LP
 114 .nf
 115 \fBint\fR \fBgl_inactivity_timeout\fR(\fBGetLine *\fR\fIgl\fR, \fBGlTimeoutFn *\fR\fIcallback\fR,
 116      \fBvoid *\fR\fIdata\fR, \fBunsigned long\fR \fIsec\fR, \fBunsigned long\fR \fInsec\fR);
 117 .fi
 118 
 119 .LP
 120 .nf
 121 \fBint\fR \fBgl_group_history\fR(\fBGetLine *\fR\fIgl\fR, \fBunsigned\fR \fIstream\fR);
 122 .fi
 123 
 124 .LP
 125 .nf
 126 \fBint\fR \fBgl_show_history\fR(\fBGetLine *\fR\fIgl\fR, \fBFILE *\fR\fIfp\fR, \fBconst char *\fR\fIfmt\fR,
 127      \fBint\fR \fIall_groups\fR, \fBint\fR \fImax_lines\fR);
 128 .fi
 129 
 130 .LP
 131 .nf
 132 \fBint\fR \fBgl_resize_history\fR(\fBGetLine *\fR\fIgl\fR, \fBsize_t\fR \fIbufsize\fR);
 133 .fi
 134 
 135 .LP
 136 .nf
 137 \fBvoid\fR \fBgl_limit_history\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fImax_lines\fR);
 138 .fi
 139 
 140 .LP
 141 .nf
 142 \fBvoid\fR \fBgl_clear_history\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIall_groups\fR);
 143 .fi
 144 
 145 .LP
 146 .nf
 147 \fBvoid\fR \fBgl_toggle_history\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIenable\fR);
 148 .fi
 149 
 150 .LP
 151 .nf
 152 \fBGlTerminalSize\fR \fBgl_terminal_size\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIdef_ncolumn\fR,
 153      \fBint\fR \fIdef_nline\fR);
 154 .fi
 155 
 156 .LP
 157 .nf
 158 \fBint\fR \fBgl_set_term_size\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIncolumn\fR, \fBint\fR \fInline\fR);
 159 .fi
 160 
 161 .LP
 162 .nf
 163 \fBint\fR \fBgl_lookup_history\fR(\fBGetLine *\fR\fIgl\fR, \fBunsigned long\fR \fIid\fR,
 164      \fBGlHistoryLine *\fR\fIhline\fR);
 165 .fi
 166 
 167 .LP
 168 .nf
 169 \fBvoid\fR \fBgl_state_of_history\fR(\fBGetLine *\fR\fIgl\fR, \fBGlHistoryState *\fR\fIstate\fR);
 170 .fi
 171 
 172 .LP
 173 .nf
 174 \fBvoid\fR \fBgl_range_of_history\fR(\fBGetLine *\fR\fIgl\fR, \fBGlHistoryRange *\fR\fIrange\fR);
 175 .fi
 176 
 177 .LP
 178 .nf
 179 \fBvoid\fR \fBgl_size_of_history\fR(\fBGetLine *\fR\fIgl\fR, \fBGlHistorySize *\fR\fIsize\fR);
 180 .fi
 181 
 182 .LP
 183 .nf
 184 \fBvoid\fR \fBgl_echo_mode\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIenable\fR);
 185 .fi
 186 
 187 .LP
 188 .nf
 189 \fBvoid\fR \fBgl_replace_prompt\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIprompt\fR);
 190 .fi
 191 
 192 .LP
 193 .nf
 194 \fBvoid\fR \fBgl_prompt_style\fR(\fBGetLine *\fR\fIgl\fR, \fBGlPromptStyle\fR \fIstyle\fR);
 195 .fi
 196 
 197 .LP
 198 .nf
 199 \fBint\fR \fBgl_ignore_signal\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIsigno\fR);
 200 .fi
 201 
 202 .LP
 203 .nf
 204 \fBint\fR \fBgl_trap_signal\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIsigno\fR, \fBunsigned\fR \fIflags\fR,
 205      \fBGlAfterSignal\fR \fIafter\fR, \fBint\fR \fIerrno_value\fR);
 206 .fi
 207 
 208 .LP
 209 .nf
 210 \fBint\fR \fBgl_last_signal\fR(\fBGetLine *\fR\fIgl\fR);
 211 .fi
 212 
 213 .LP
 214 .nf
 215 \fBint\fR \fBgl_completion_action\fR(\fBGetLine *\fR\fIgl\fR, \fBvoid *\fR\fIdata\fR,
 216      \fBCplMatchFn *\fR\fImatch_fn\fR, \fBint\fR \fIlist_only\fR, \fBconst char *\fR\fIname\fR,
 217      \fBconst char *\fR\fIkeyseq\fR);
 218 .fi
 219 
 220 .LP
 221 .nf
 222 \fBint\fR \fBgl_register_action\fR(\fBGetLine *\fR\fIgl\fR, \fBvoid *\fR\fIdata\fR, \fBGlActionFn *\fR\fIfn\fR,
 223      \fBconst char *\fR\fIname\fR, \fBconst char *\fR\fIkeyseq\fR);
 224 .fi
 225 
 226 .LP
 227 .nf
 228 \fBint\fR \fBgl_display_text\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIindentation\fR,
 229      \fBconst char *\fR\fIprefix\fR, \fBconst char *\fR\fIsuffix\fR, \fBint\fR \fIfill_char\fR,
 230      \fBint\fR \fIdef_width\fR, \fBint\fR \fIstart\fR, \fBconst char *\fR\fIstring\fR);
 231 .fi
 232 
 233 .LP
 234 .nf
 235 \fBGlReturnStatus\fR \fBgl_return_status\fR(\fBGetLine *\fR\fIgl\fR);
 236 .fi
 237 
 238 .LP
 239 .nf
 240 \fBconst char *\fR\fBgl_error_message\fR(\fBGetLine *\fR\fIgl\fR, \fBchar *\fR\fIbuff\fR, \fBsize_t\fR \fIn\fR);
 241 .fi
 242 
 243 .LP
 244 .nf
 245 \fBvoid\fR \fBgl_catch_blocked\fR(\fBGetLine *\fR\fIgl\fR);
 246 .fi
 247 
 248 .LP
 249 .nf
 250 \fBint\fR \fBgl_list_signals\fR(\fBGetLine *\fR\fIgl\fR, \fBsigset_t *\fR\fIset\fR);
 251 .fi
 252 
 253 .LP
 254 .nf
 255 \fBint\fR \fBgl_append_history\fR(\fBGetLine *\fR\fIgl\fR, \fBconst char *\fR\fIline\fR);
 256 .fi
 257 
 258 .LP
 259 .nf
 260 \fBint\fR \fBgl_automatic_history\fR(\fBGetLine *\fR\fIgl\fR, \fBint\fR \fIenable\fR);
 261 .fi
 262 
 263 .LP
 264 .nf
 265 \fBint\fR \fBgl_erase_terminal\fR(\fBGetLine *\fR\fIgl\fR);
 266 .fi
 267 
 268 .SH DESCRIPTION
 269 The \fBgl_get_line()\fR function is part of the \fBlibtecla\fR(3LIB) library.
 270 If the user is typing at a terminal, each call prompts them for a line of
 271 input, then provides interactive editing facilities, similar to those of the
 272 UNIX \fBtcsh\fR shell. In addition to simple command-line editing, it supports
 273 recall of previously entered command lines, TAB completion of file names, and
 274 in-line wild-card expansion of filenames. Documentation of both the user-level
 275 command-line editing features and all user configuration options can be found
 276 on the \fBtecla\fR(5) manual page.
 277 .SS "An Example"
 278 The following shows a complete example of how to use the \fBgl_get_line()\fR
 279 function to get input from the user:
 280 .sp
 281 .in +2
 282 .nf
 283 #include <stdio.h>
 284 #include <locale.h>
 285 #include <libtecla.h>
 286 
 287 int main(int argc, char *argv[])
 288 {
 289   char *line;    /* The line that the user typed */
 290   GetLine *gl;   /* The gl_get_line() resource object */
 291 
 292   setlocale(LC_CTYPE, ""); /* Adopt the user's choice */
 293                            /* of character set. */
 294 
 295   gl = new_GetLine(1024, 2048);
 296   if(!gl)
 297     return 1;
 298   while((line=gl_get_line(gl, "$ ", NULL, -1)) != NULL &&
 299          strcmp(line, "exit\en") != 0)
 300     printf("You typed: %s\en", line);
 301 
 302   gl = del_GetLine(gl);
 303   return 0;
 304 }
 305 .fi
 306 .in -2
 307 
 308 .sp
 309 .LP
 310 In the example, first the resources needed by the \fBgl_get_line()\fR function
 311 are created by calling \fBnew_GetLine()\fR. This allocates the memory used in
 312 subsequent calls to the \fBgl_get_line()\fR function, including the history
 313 buffer for recording previously entered lines. Then one or more lines are read
 314 from the user, until either an error occurs, or the user types exit. Then
 315 finally the resources that were allocated by \fBnew_GetLine()\fR, are returned
 316 to the system by calling \fBdel_GetLine()\fR. Note the use of the \fINULL\fR
 317 return value of \fBdel_GetLine()\fR to make \fIgl\fR \fINULL\fR. This is a
 318 safety precaution. If the program subsequently attempts to pass \fIgl\fR to
 319 \fBgl_get_line()\fR, said function will complain, and return an error, instead
 320 of attempting to use the deleted resource object.
 321 .SS "The Functions Used In The Example"
 322 The \fBnew_GetLine()\fR function creates the resources used by the
 323 \fBgl_get_line()\fR function and returns an opaque pointer to the object that
 324 contains them. The maximum length of an input line is specified by the
 325 \fIlinelen\fR argument, and the number of bytes to allocate for storing history
 326 lines is set by the \fIhistlen\fR argument. History lines are stored
 327 back-to-back in a single buffer of this size. Note that this means that the
 328 number of history lines that can be stored at any given time, depends on the
 329 lengths of the individual lines. If you want to place an upper limit on the
 330 number of lines that can be stored, see the description of the
 331 \fBgl_limit_history()\fR function. If you do not want history at all, specify
 332 \fIhistlen\fR as zero, and no history buffer will be allocated.
 333 .sp
 334 .LP
 335 On error, a message is printed to \fBstderr\fR and \fINULL\fR is returned.
 336 .sp
 337 .LP
 338 The \fBdel_GetLine()\fR function deletes the resources that were returned by a
 339 previous call to \fBnew_GetLine()\fR. It always returns \fINULL\fR (for
 340 example, a deleted object). It does nothing if the \fIgl\fR argument is
 341 \fINULL\fR.
 342 .sp
 343 .LP
 344 The \fBgl_get_line()\fR function can be called any number of times to read
 345 input from the user. The gl argument must have been previously returned by a
 346 call to \fBnew_GetLine()\fR. The \fIprompt\fR argument should be a normal
 347 null-terminated string, specifying the prompt to present the user with. By
 348 default prompts are displayed literally, but if enabled with the
 349 \fBgl_prompt_style()\fR function, prompts can contain directives to do
 350 underlining, switch to and from bold fonts, or turn highlighting on and off.
 351 .sp
 352 .LP
 353 If you want to specify the initial contents of the line for the user to edit,
 354 pass the desired string with the \fIstart_line\fR argument. You can then
 355 specify which character of this line the cursor is initially positioned over by
 356 using the \fIstart_pos\fR argument. This should be -1 if you want the cursor to
 357 follow the last character of the start line. If you do not want to preload the
 358 line in this manner, send \fIstart_line\fR as \fINULL\fR, and set
 359 \fIstart_pos\fR to -1.
 360 .sp
 361 .LP
 362 The \fBgl_get_line()\fR function returns a pointer to the line entered by the
 363 user, or \fINULL\fR on error or at the end of the input. The returned pointer
 364 is part of the specified \fIgl\fR resource object, and thus should not be freed
 365 by the caller, or assumed to be unchanging from one call to the next. When
 366 reading from a user at a terminal, there will always be a newline character at
 367 the end of the returned line. When standard input is being taken from a pipe or
 368 a file, there will similarly be a newline unless the input line was too long to
 369 store in the internal buffer. In the latter case you should call
 370 \fBgl_get_line()\fR again to read the rest of the line. Note that this behavior
 371 makes \fBgl_get_line()\fR similar to \fBfgets\fR(3C). When \fBstdin\fR is not
 372 connected to a terminal, \fBgl_get_line()\fR simply calls \fBfgets()\fR.
 373 .SS "The Return Status Of \fBgl_get_line()\fR"
 374 The \fBgl_get_line()\fR function has two possible return values: a pointer to
 375 the completed input line, or \fINULL\fR. Additional information about what
 376 caused \fBgl_get_line()\fR to return is available both by inspecting
 377 \fBerrno\fR and by calling the \fBgl_return_status()\fR function.
 378 .sp
 379 .LP
 380 The following are the possible enumerated values returned by
 381 \fBgl_return_status()\fR:
 382 .sp
 383 .ne 2
 384 .na
 385 \fB\fBGLR_NEWLINE\fR\fR
 386 .ad
 387 .RS 15n
 388 The last call to \fBgl_get_line()\fR successfully returned a completed input
 389 line.
 390 .RE
 391 
 392 .sp
 393 .ne 2
 394 .na
 395 \fB\fBGLR_BLOCKED\fR\fR
 396 .ad
 397 .RS 15n
 398 The \fBgl_get_line()\fR function was in non-blocking server mode, and returned
 399 early to avoid blocking the process while waiting for terminal I/O. The
 400 \fBgl_pending_io()\fR function can be used to see what type of I/O
 401 \fBgl_get_line()\fR was waiting for. See the \fBgl_io_mode\fR(3TECLA).
 402 .RE
 403 
 404 .sp
 405 .ne 2
 406 .na
 407 \fB\fBGLR_SIGNAL\fR\fR
 408 .ad
 409 .RS 15n
 410 A signal was caught by \fBgl_get_line()\fR that had an after-signal disposition
 411 of \fBGLS_ABORT\fR. See \fBgl_trap_signal()\fR.
 412 .RE
 413 
 414 .sp
 415 .ne 2
 416 .na
 417 \fB\fBGLR_TIMEOUT\fR\fR
 418 .ad
 419 .RS 15n
 420 The inactivity timer expired while \fBgl_get_line()\fR was waiting for input,
 421 and the timeout callback function returned \fBGLTO_ABORT\fR. See
 422 \fBgl_inactivity_timeout()\fR for information about timeouts.
 423 .RE
 424 
 425 .sp
 426 .ne 2
 427 .na
 428 \fB\fBGLR_FDABORT\fR\fR
 429 .ad
 430 .RS 15n
 431 An application I/O callback returned \fBGLFD_ABORT\fR. See
 432 \fBgl_watch_fd()\fR.
 433 .RE
 434 
 435 .sp
 436 .ne 2
 437 .na
 438 \fB\fBGLR_EOF\fR\fR
 439 .ad
 440 .RS 15n
 441 End of file reached. This can happen when input is coming from a file or a
 442 pipe, instead of the terminal. It also occurs if the user invokes the
 443 list-or-eof or del-char-or-list-or-eof actions at the start of a new line.
 444 .RE
 445 
 446 .sp
 447 .ne 2
 448 .na
 449 \fB\fBGLR_ERROR\fR\fR
 450 .ad
 451 .RS 15n
 452 An unexpected error caused \fBgl_get_line()\fR to abort (consult \fBerrno\fR
 453 and/or \fBgl_error_message()\fR for details.
 454 .RE
 455 
 456 .sp
 457 .LP
 458 When \fBgl_return_status()\fR returns \fBGLR_ERROR\fR and the value of
 459 \fBerrno\fR is not sufficient to explain what happened, you can use the
 460 \fBgl_error_message()\fR function to request a description of the last error
 461 that occurred.
 462 .sp
 463 .LP
 464 The return value of \fBgl_error_message()\fR is a pointer to the message that
 465 occurred. If the \fIbuff\fR argument is \fINULL\fR, this will be a pointer to a
 466 buffer within \fIgl\fR whose value will probably change on the next call to any
 467 function associated with \fBgl_get_line()\fR. Otherwise, if a non-null
 468 \fIbuff\fR argument is provided, the error message, including a '\e0'
 469 terminator, will be written within the first \fIn\fR elements of this buffer,
 470 and the return value will be a pointer to the first element of this buffer. If
 471 the message will not fit in the provided buffer, it will be truncated to fit.
 472 .SS "Optional Prompt Formatting"
 473 Whereas by default the prompt string that you specify is displayed literally
 474 without any special interpretation of the characters within it, the
 475 \fBgl_prompt_style()\fR function can be used to enable optional formatting
 476 directives within the prompt.
 477 .sp
 478 .LP
 479 The \fIstyle\fR argument, which specifies the formatting style, can take any of
 480 the following values:
 481 .sp
 482 .ne 2
 483 .na
 484 \fB\fBGL_FORMAT_PROMPT\fR\fR
 485 .ad
 486 .RS 21n
 487 In this style, the formatting directives described below, when included in
 488 prompt strings, are interpreted as follows:
 489 .sp
 490 .ne 2
 491 .na
 492 \fB\fB%B\fR\fR
 493 .ad
 494 .RS 6n
 495 Display subsequent characters with a bold font.
 496 .RE
 497 
 498 .sp
 499 .ne 2
 500 .na
 501 \fB\fB%b\fR\fR
 502 .ad
 503 .RS 6n
 504 Stop displaying characters with the bold font.
 505 .RE
 506 
 507 .sp
 508 .ne 2
 509 .na
 510 \fB\fB%F\fR\fR
 511 .ad
 512 .RS 6n
 513 Make subsequent characters flash.
 514 .RE
 515 
 516 .sp
 517 .ne 2
 518 .na
 519 \fB\fB%f\fR\fR
 520 .ad
 521 .RS 6n
 522 Turn off flashing characters.
 523 .RE
 524 
 525 .sp
 526 .ne 2
 527 .na
 528 \fB\fB%U\fR\fR
 529 .ad
 530 .RS 6n
 531 Underline subsequent characters.
 532 .RE
 533 
 534 .sp
 535 .ne 2
 536 .na
 537 \fB\fB%u\fR\fR
 538 .ad
 539 .RS 6n
 540 Stop underlining characters.
 541 .RE
 542 
 543 .sp
 544 .ne 2
 545 .na
 546 \fB\fB%P\fR\fR
 547 .ad
 548 .RS 6n
 549 Switch to a pale (half brightness) font.
 550 .RE
 551 
 552 .sp
 553 .ne 2
 554 .na
 555 \fB\fB%p\fR\fR
 556 .ad
 557 .RS 6n
 558 Stop using the pale font.
 559 .RE
 560 
 561 .sp
 562 .ne 2
 563 .na
 564 \fB\fB%S\fR\fR
 565 .ad
 566 .RS 6n
 567 Highlight subsequent characters (also known as standout mode).
 568 .RE
 569 
 570 .sp
 571 .ne 2
 572 .na
 573 \fB\fB%s\fR\fR
 574 .ad
 575 .RS 6n
 576 Stop highlighting characters.
 577 .RE
 578 
 579 .sp
 580 .ne 2
 581 .na
 582 \fB\fB%V\fR\fR
 583 .ad
 584 .RS 6n
 585 Turn on reverse video.
 586 .RE
 587 
 588 .sp
 589 .ne 2
 590 .na
 591 \fB\fB%v\fR\fR
 592 .ad
 593 .RS 6n
 594 Turn off reverse video.
 595 .RE
 596 
 597 .sp
 598 .ne 2
 599 .na
 600 \fB\fB%%\fR\fR
 601 .ad
 602 .RS 6n
 603 Display a single % character.
 604 .RE
 605 
 606 For example, in this mode, a prompt string like "%UOK%u$" would display the
 607 prompt "OK$", but with the OK part underlined.
 608 .sp
 609 Note that although a pair of characters that starts with a % character, but
 610 does not match any of the above directives is displayed literally, if a new
 611 directive is subsequently introduced which does match, the displayed prompt
 612 will change, so it is better to always use %% to display a literal %.
 613 .sp
 614 Also note that not all terminals support all of these text attributes, and that
 615 some substitute a different attribute for missing ones.
 616 .RE
 617 
 618 .sp
 619 .ne 2
 620 .na
 621 \fB\fBGL_LITERAL_PROMPT\fR\fR
 622 .ad
 623 .RS 21n
 624 In this style, the prompt string is printed literally. This is the default
 625 style.
 626 .RE
 627 
 628 .SS "Alternate Configuration Sources"
 629 By default users have the option of configuring the behavior of
 630 \fBgl_get_line()\fR with a configuration file called \fB\&.teclarc\fR in their
 631 home directories. The fact that all applications share this same configuration
 632 file is both an advantage and a disadvantage. In most cases it is an advantage,
 633 since it encourages uniformity, and frees the user from having to configure
 634 each application separately. In some applications, however, this single means
 635 of configuration is a problem. This is particularly true of embedded software,
 636 where there's no filesystem to read a configuration file from, and also in
 637 applications where a radically different choice of keybindings is needed to
 638 emulate a legacy keyboard interface. To cater for such cases, the
 639 \fBgl_configure_getline()\fR function allows the application to control where
 640 configuration information is read from.
 641 .sp
 642 .LP
 643 The \fBgl_configure_getline()\fR function allows the configuration commands
 644 that would normally be read from a user's \fB~/.teclarc\fR file, to be read
 645 from any or none of, a string, an application specific configuration file,
 646 and/or a user-specific configuration file. If this function is called before
 647 the first call to \fBgl_get_line()\fR, the default behavior of reading
 648 \fB~/.teclarc\fR on the first call to \fBgl_get_line()\fR is disabled, so all
 649 configurations must be achieved using the configuration sources specified with
 650 this function.
 651 .sp
 652 .LP
 653 If \fIapp_string\fR != \fINULL\fR, then it is interpreted as a string
 654 containing one or more configuration commands, separated from each other in the
 655 string by embedded newline  characters. If \fIapp_file\fR != \fINULL\fR then it
 656 is interpreted as the full pathname of an application-specific configuration
 657 file. If user_file != \fINULL\fR then it is interpreted as the full path name
 658 of a user-specific configuration file, such as \fB~/.teclarc\fR. For example,
 659 in the call
 660 .sp
 661 .in +2
 662 .nf
 663 gl_configure_getline(gl, "edit-mode vi \en nobeep",
 664                      "/usr/share/myapp/teclarc", "~/.teclarc");
 665 .fi
 666 .in -2
 667 
 668 .sp
 669 .LP
 670 The \fIapp_string\fR argument causes the calling application to start in
 671 \fBvi\fR(1) edit-mode, instead of the default \fBemacs\fR mode, and turns off
 672 the use of the terminal bell by the library. It then attempts to read
 673 system-wide configuration commands from an optional file called
 674 \fB/usr/share/myapp/teclarc\fR, then finally reads user-specific configuration
 675 commands from an optional \fB\&.teclarc\fR file in the user's home directory.
 676 Note that the arguments are listed in ascending order of priority, with the
 677 contents of \fIapp_string\fR being potentially overridden by commands in
 678 \fIapp_file\fR, and commands in \fIapp_file\fR potentially being overridden by
 679 commands in \fIuser_file\fR.
 680 .sp
 681 .LP
 682 You can call this function as many times as needed, the results being
 683 cumulative, but note that copies of any file names specified with the
 684 \fIapp_file\fR and \fIuser_file\fR arguments are recorded internally for
 685 subsequent use by the read-init-files key-binding function, so if you plan to
 686 call this function multiple times, be sure that the last call specifies the
 687 filenames that you want re-read when the user requests that the configuration
 688 files be re-read.
 689 .sp
 690 .LP
 691 Individual key sequences can also be bound and unbound using the
 692 \fBgl_bind_keyseq()\fR function. The \fIorigin\fR argument specifies the
 693 priority of the binding, according to whom it is being established for, and
 694 must be one of the following two values.
 695 .sp
 696 .ne 2
 697 .na
 698 \fB\fBGL_USER_KEY\fR\fR
 699 .ad
 700 .RS 15n
 701 The user requested this key-binding.
 702 .RE
 703 
 704 .sp
 705 .ne 2
 706 .na
 707 \fB\fBGL_APP_KEY\fR\fR
 708 .ad
 709 .RS 15n
 710 This is a default binding set by the application.
 711 .RE
 712 
 713 .sp
 714 .LP
 715 When both user and application bindings for a given key sequence have been
 716 specified, the user binding takes precedence. The application's binding is
 717 subsequently reinstated if the user's binding is later unbound with either
 718 another call to this function, or a call to \fBgl_configure_getline()\fR.
 719 .sp
 720 .LP
 721 The \fIkeyseq\fR argument specifies the key sequence to be bound or unbound,
 722 and is expressed in the same way as in a \fB~/.teclarc\fR configuration file.
 723 The \fIaction\fR argument must either be a string containing the name of the
 724 action to bind the key sequence to, or it must be \fINULL\fR or \fB""\fR to
 725 unbind the key sequence.
 726 .SS "Customized Word Completion"
 727 If in your application you would like to have TAB completion complete other
 728 things in addition to or instead of filenames, you can arrange this by
 729 registering an alternate completion callback function with a call to the
 730 \fBgl_customize_completion()\fR function.
 731 .sp
 732 .LP
 733 The \fIdata\fR argument provides a way for your application to pass arbitrary,
 734 application-specific information to the callback function. This is passed to
 735 the callback every time that it is called. It might for example point to the
 736 symbol table from which possible completions are to be sought. The
 737 \fImatch_fn\fR argument specifies the callback function to be called. The
 738 \fICplMatchFn\fR function type is defined in <\fBlibtecla.h\fR>, as is a
 739 \fBCPL_MATCH_FN()\fR macro that you can use to declare and prototype callback
 740 functions. The declaration and responsibilities of callback functions are
 741 described in depth on the \fBcpl_complete_word\fR(3TECLA) manual page.
 742 .sp
 743 .LP
 744 The callback function is responsible for looking backwards in the input line
 745 from the point at which the user pressed TAB, to find the start of the word
 746 being completed. It then must lookup possible completions of this word, and
 747 record them one by one in the \fBWordCompletion\fR object that is passed to it
 748 as an argument, by calling the \fBcpl_add_completion()\fR function. If the
 749 callback function wants to provide filename completion in addition to its own
 750 specific completions, it has the option of itself calling the builtin filename
 751 completion callback. This is also documented in the
 752 \fBcpl_complete_word\fR(3TECLA) manual page.
 753 .sp
 754 .LP
 755 If you would like \fBgl_get_line()\fR to return the current input line when a
 756 successful completion has been made, you can arrange this when you call
 757 \fBcpl_add_completion()\fR by making the last character of the continuation
 758 suffix a newline character. The input line will be updated to display the
 759 completion, together with any continuation suffix up to the newline character,
 760 and \fBgl_get_line()\fR will return this input line.
 761 .sp
 762 .LP
 763 If your callback function needs to write something to the terminal, it must
 764 call \fBgl_normal_io()\fR before doing so. This will start a new line after the
 765 input line that is currently being edited, reinstate normal terminal I/O, and
 766 notify \fBgl_get_line()\fR that the input line will need to be redrawn when the
 767 callback returns.
 768 .SS "Adding Completion Actions"
 769 In the previous section the ability to customize the behavior of the only
 770 default completion action, complete-word, was described. In this section the
 771 ability to install additional action functions, so that different types of word
 772 completion can be bound to different key sequences, is described. This is
 773 achieved by using the \fBgl_completion_action()\fR function.
 774 .sp
 775 .LP
 776 The \fIdata\fR and \fImatch_fn\fR arguments are as described on the
 777 \fBcpl_complete_word\fR(3TECLA) manual page, and specify the callback function
 778 that should be invoked to identify possible completions. The \fIlist_only\fR
 779 argument determines whether the action that is being defined should attempt to
 780 complete the word as far as possible in the input line before displaying any
 781 possible ambiguous completions, or whether it should simply display the list of
 782 possible completions without touching the input line. The former option is
 783 selected by specifying a value of 0, and the latter by specifying a value of 1.
 784 The \fIname\fR argument specifies the name by which configuration files and
 785 future invocations of this function should refer to the action. This must
 786 either be the name of an existing completion action to be changed, or be a new
 787 unused name for a new action. Finally, the \fIkeyseq\fR argument specifies the
 788 default key sequence to bind the action to. If this is \fINULL\fR, no new key
 789 sequence will be bound to the action.
 790 .sp
 791 .LP
 792 Beware that in order for the user to be able to change the key sequence that is
 793 bound to actions that are installed in this manner, you should call
 794 \fBgl_completion_action()\fR to install a given action for the first time
 795 between calling \fBnew_GetLine()\fR and the first call to \fBgl_get_line()\fR.
 796 Otherwise, when the user's configuration file is read on the first call to
 797 \fBgl_get_line()\fR, the name of the your additional action will not be known,
 798 and any reference to it in the configuration file will generate an error.
 799 .sp
 800 .LP
 801 As discussed for \fBgl_customize_completion()\fR, if your callback function
 802 needs to write anything to the terminal, it must call \fBgl_normal_io()\fR
 803 before doing so.
 804 .SS "Defining Custom Actions"
 805 Although the built-in key-binding actions are sufficient for the needs of most
 806 applications, occasionally a specialized application may need to define one or
 807 more custom actions, bound to application-specific key sequences. For example,
 808 a sales application would benefit from having a key sequence that displayed the
 809 part name that corresponded to a part number preceding the cursor. Such a
 810 feature is clearly beyond the scope of the built-in action functions. So for
 811 such special cases, the \fBgl_register_action()\fR function is provided.
 812 .sp
 813 .LP
 814 The \fBgl_register_action()\fR function lets the application register an
 815 external function, \fIfn\fR, that will thereafter be called whenever either the
 816 specified key sequence, \fIkeyseq\fR, is entered by the user, or the user
 817 enters any other key sequence that the user subsequently binds to the specified
 818 action name, \fIname\fR, in their configuration file. The \fIdata\fR argument
 819 can be a pointer to anything that the application wants to have passed to the
 820 action function, \fIfn\fR, whenever that function is invoked.
 821 .sp
 822 .LP
 823 The action function, \fIfn\fR, should be declared using the
 824 \fBGL_ACTION_FN()\fR macro, which is defined in <\fBlibtecla.h\fR>.
 825 .sp
 826 .in +2
 827 .nf
 828 #define GL_ACTION_FN(fn) GlAfterAction (fn)(GetLine *gl, \e
 829                        void *data, int count, size_t curpos, \e
 830                        const char *line)
 831 .fi
 832 .in -2
 833 
 834 .sp
 835 .LP
 836 The \fIgl\fR and \fIdata\fR arguments are those that were previously passed to
 837 \fBgl_register_action()\fR when the action function was registered. The
 838 \fIcount\fR argument is a numeric argument which the user has the option of
 839 entering using the digit-argument action, before invoking the action. If the
 840 user does not enter a number, then the \fIcount\fR argument is set to 1.
 841 Nominally this argument is interpreted as a repeat count, meaning that the
 842 action should be repeated that many times. In practice however, for some
 843 actions a repeat count makes little sense. In such cases, actions can either
 844 simply ignore the \fIcount\fR argument, or use its value for a different
 845 purpose.
 846 .sp
 847 .LP
 848 A copy of the current input line is passed in the read-only \fIline\fR
 849 argument. The current cursor position within this string is given by the index
 850 contained in the \fIcurpos\fR argument. Note that direct manipulation of the
 851 input line and the cursor position is not permitted because the rules dictated
 852 by various modes (such as \fBvi\fR mode versus \fBemacs\fR mode, no-echo mode,
 853 and insert mode versus overstrike mode) make it too complex for an application
 854 writer to write a conforming editing action, as well as constrain future
 855 changes to the internals of \fBgl_get_line()\fR. A potential solution to this
 856 dilemma would be to allow the action function to edit the line using the
 857 existing editing actions. This is currently under consideration.
 858 .sp
 859 .LP
 860 If the action function wishes to write text to the terminal without this
 861 getting mixed up with the displayed text of the input line, or read from the
 862 terminal without having to handle raw terminal I/O, then before doing either of
 863 these operations, it must temporarily suspend line editing by calling the
 864 \fBgl_normal_io()\fR function. This function flushes any pending output to the
 865 terminal, moves the cursor to the start of the line that follows the last
 866 terminal line of the input line, then restores the terminal to a state that is
 867 suitable for use with the C \fBstdio\fR facilities. The latter includes such
 868 things as restoring the normal mapping of \en to \er\en, and, when in server
 869 mode, restoring the normal blocking form of terminal I/O. Having called this
 870 function, the action function can read from and write to the terminal without
 871 the fear of creating a mess. It is not necessary for the action function to
 872 restore the original editing environment before it returns. This is done
 873 automatically by \fBgl_get_line()\fR after the action function returns. The
 874 following is a simple example of an action function which writes the sentence
 875 "Hello world" on a new terminal line after the line being edited. When this
 876 function returns, the input line is redrawn on the line that follows the "Hello
 877 world" line, and line editing resumes.
 878 .sp
 879 .in +2
 880 .nf
 881 static GL_ACTION_FN(say_hello_fn)
 882 {
 883     if(gl_normal_io(gl))   /* Temporarily suspend editing */
 884         return GLA_ABORT;
 885     printf("Hello world\en");
 886     return GLA_CONTINUE;
 887 }
 888 .fi
 889 .in -2
 890 
 891 .sp
 892 .LP
 893 Action functions must return one of the following values, to tell
 894 \fBgl_get_line()\fR how to proceed.
 895 .sp
 896 .ne 2
 897 .na
 898 \fB\fBGLA_ABORT\fR\fR
 899 .ad
 900 .RS 16n
 901 Cause \fBgl_get_line()\fR to return \fINULL\fR.
 902 .RE
 903 
 904 .sp
 905 .ne 2
 906 .na
 907 \fB\fBGLA_RETURN\fR\fR
 908 .ad
 909 .RS 16n
 910 Cause \fBgl_get_line()\fR to return the completed input line
 911 .RE
 912 
 913 .sp
 914 .ne 2
 915 .na
 916 \fB\fBGLA_CONTINUE\fR\fR
 917 .ad
 918 .RS 16n
 919 Resume command-line editing.
 920 .RE
 921 
 922 .sp
 923 .LP
 924 Note that the \fIname\fR argument of \fBgl_register_action()\fR specifies the
 925 name by which a user can refer to the action in their configuration file. This
 926 allows them to re-bind the action to an alternate key-sequence. In order for
 927 this to work, it is necessary to call \fBgl_register_action()\fR between
 928 calling \fBnew_GetLine()\fR and the first call to \fBgl_get_line()\fR.
 929 .SS "History Files"
 930 To save the contents of the history buffer before quitting your application and
 931 subsequently restore them when you next start the application, the
 932 \fBgl_save_history()\fR and \fBgl_load_history()\fR functions are provided.
 933 .sp
 934 .LP
 935 The \fIfilename\fR argument specifies the name to give the history file when
 936 saving, or the name of an existing history file, when loading. This may contain
 937 home directory and environment variable expressions, such as
 938 \fB~/.myapp_history\fR or \fB$HOME/.myapp_history\fR.
 939 .sp
 940 .LP
 941 Along with each history line, additional information about it, such as its
 942 nesting level and when it was entered by the user, is recorded as a comment
 943 preceding the line in the history file. Writing this as a comment allows the
 944 history file to double as a command file, just in case you wish to replay a
 945 whole session using it. Since comment prefixes differ in different languages,
 946 the comment argument is provided for specifying the comment prefix. For
 947 example, if your application were a UNIX shell, such as the Bourne shell, you
 948 would specify "#" here. Whatever you choose for the comment character, you must
 949 specify the same prefix to \fBgl_load_history()\fR that you used when you
 950 called \fBgl_save_history()\fR to write the history file.
 951 .sp
 952 .LP
 953 The \fImax_lines\fR argument must be either -1 to specify that all lines in the
 954 history list be saved, or a positive number specifying a ceiling on how many of
 955 the most recent lines should be saved.
 956 .sp
 957 .LP
 958 Both functions return non-zero on error, after writing an error message to
 959 \fBstderr\fR. Note that \fBgl_load_history()\fR does not consider the
 960 non-existence of a file to be an error.
 961 .SS "Multiple History Lists"
 962 If your application uses a single \fBGetLine\fR object for entering many
 963 different types of input lines, you might want \fBgl_get_line()\fR to
 964 distinguish the different types of lines in the history list, and only recall
 965 lines that match the current type of line. To support this requirement,
 966 \fBgl_get_line()\fR marks lines being recorded in the history list with an
 967 integer identifier chosen by the application. Initially this identifier is set
 968 to 0 by \fBnew_GetLine()\fR, but it can be changed subsequently by calling
 969 \fBgl_group_history()\fR.
 970 .sp
 971 .LP
 972 The integer identifier ID can be any number chosen by the application, but note
 973 that \fBgl_save_history()\fR and \fBgl_load_history()\fR preserve the
 974 association between identifiers and historical input lines between program
 975 invocations, so you should choose fixed identifiers for the different types of
 976 input line used by your application.
 977 .sp
 978 .LP
 979 Whenever \fBgl_get_line()\fR appends a new input line to the history list, the
 980 current history identifier is recorded with it, and when it is asked to recall
 981 a historical input line, it only recalls lines that are marked with the current
 982 identifier.
 983 .SS "Displaying History"
 984 The history list can be displayed by calling \fBgl_show_history()\fR. This
 985 function displays the current contents of the history list to the \fBstdio\fR
 986 output stream \fIfp\fR. If the \fImax_lines\fR argument is greater than or
 987 equal to zero, then no more than this number of  the most recent lines will be
 988 displayed. If the \fIall_groups\fR argument is non-zero, lines from all history
 989 groups are displayed. Otherwise only those of the currently selected history
 990 group are displayed. The format string argument, \fIfmt\fR, determines how the
 991 line is displayed. This can contain arbitrary characters which are written
 992 verbatim, interleaved with any of the following format directives:
 993 .sp
 994 .ne 2
 995 .na
 996 \fB\fB%D\fR\fR
 997 .ad
 998 .RS 6n
 999 The date on which the line was originally entered, formatted like 2001-11-20.
1000 .RE
1001 
1002 .sp
1003 .ne 2
1004 .na
1005 \fB\fB%T\fR\fR
1006 .ad
1007 .RS 6n
1008 The time of day when the line was entered, formatted like 23:59:59.
1009 .RE
1010 
1011 .sp
1012 .ne 2
1013 .na
1014 \fB\fB%N\fR\fR
1015 .ad
1016 .RS 6n
1017 The sequential entry number of the line in the history buffer.
1018 .RE
1019 
1020 .sp
1021 .ne 2
1022 .na
1023 \fB\fB%G\fR\fR
1024 .ad
1025 .RS 6n
1026 The number of the history group which the line belongs to.
1027 .RE
1028 
1029 .sp
1030 .ne 2
1031 .na
1032 \fB\fB%%\fR\fR
1033 .ad
1034 .RS 6n
1035 A literal % character.
1036 .RE
1037 
1038 .sp
1039 .ne 2
1040 .na
1041 \fB\fB%H\fR\fR
1042 .ad
1043 .RS 6n
1044 The history line itself.
1045 .RE
1046 
1047 .sp
1048 .LP
1049 Thus a format string like "%D %T %H0" would output something like:
1050 .sp
1051 .in +2
1052 .nf
1053 2001-11-20 10:23:34  Hello world
1054 .fi
1055 .in -2
1056 
1057 .sp
1058 .LP
1059 Note the inclusion of an explicit newline character in the format string.
1060 .SS "Looking Up History"
1061 The \fBgl_lookup_history()\fR function allows the calling application to look
1062 up lines in the history list.
1063 .sp
1064 .LP
1065 The \fIid\fR argument indicates which line to look up, where the first line
1066 that was entered in the history list after \fBnew_GetLine()\fR was called is
1067 denoted by 0, and subsequently entered lines are denoted with successively
1068 higher numbers. Note that the range of lines currently preserved in the history
1069 list can be queried by calling the \fBgl_range_of_history()\fR function. If the
1070 requested line is in the history list, the details of the line are recorded in
1071 the variable pointed to by the \fIhline\fR argument, and 1 is returned.
1072 Otherwise 0 is returned, and the variable pointed to by \fIhline\fR is left
1073 unchanged.
1074 .sp
1075 .LP
1076 Beware that the string returned in \fIhline\fR->\fIline\fR is part of the
1077 history buffer, so it must not be modified by the caller, and will be recycled
1078 on the next call to any function that takes \fIgl\fR as its argument. Therefore
1079 you should make a private copy of this string if you need to keep it.
1080 .SS "Manual History Archival"
1081 By default, whenever a line is entered by the user, it is automatically
1082 appended to the history list, just before \fBgl_get_line()\fR returns the line
1083 to the caller. This is convenient for the majority of applications, but there
1084 are also applications that need finer-grained control over what gets added to
1085 the history list. In such cases, the automatic addition of entered lines to the
1086 history list can be turned off by calling the \fBgl_automatic_history()\fR
1087 function.
1088 .sp
1089 .LP
1090 If this function is called with its \fIenable\fR argument set to 0,
1091 \fBgl_get_line()\fR will not automatically archive subsequently entered lines.
1092 Automatic archiving can be reenabled at a later time by calling this function
1093 again, with its \fIenable\fR argument set to 1. While automatic history
1094 archiving is disabled, the calling application can use the
1095 \fBgl_append_history()\fR to append lines to the history list as needed.
1096 .sp
1097 .LP
1098 The \fIline\fR argument specifies the line to be added to the history list.
1099 This must be a normal '\e0 ' terminated string. If this string contains any
1100 newline characters, the line that gets archived in the history list will be
1101 terminated by the first of these. Otherwise it will be terminated by the '\e0 '
1102 terminator. If the line is longer than the maximum input line length that was
1103 specified when \fBnew_GetLine()\fR was called, it will be truncated to the
1104 actual \fBgl_get_line()\fR line length when the line is recalled.
1105 .sp
1106 .LP
1107 If successful, \fBgl_append_history()\fR returns 0. Otherwise it returns
1108 non-zero and sets \fBerrno\fR to one of the following values.
1109 .sp
1110 .ne 2
1111 .na
1112 \fB\fBEINVAL\fR\fR
1113 .ad
1114 .RS 10n
1115 One of the arguments passed to \fBgl_append_history()\fR was \fINULL\fR.
1116 .RE
1117 
1118 .sp
1119 .ne 2
1120 .na
1121 \fB\fBENOMEM\fR\fR
1122 .ad
1123 .RS 10n
1124 The specified line was longer than the allocated size of the history buffer (as
1125 specified when \fBnew_GetLine()\fR was called), so it could not be archived.
1126 .RE
1127 
1128 .sp
1129 .LP
1130 A textual description of the error can optionally be obtained by calling
1131 \fBgl_error_message()\fR. Note that after such an error, the history list
1132 remains in a valid state to receive new history lines, so there is little harm
1133 in simply ignoring the return status of \fBgl_append_history()\fR.
1134 .SS "Miscellaneous History Configuration"
1135 If you wish to change the size of the history buffer that was originally
1136 specified in the call to \fBnew_GetLine()\fR, you can do so with the
1137 \fBgl_resize_history()\fR function.
1138 .sp
1139 .LP
1140 The \fIhistlen\fR argument specifies the new size in bytes, and if you specify
1141 this as 0, the buffer will be deleted.
1142 .sp
1143 .LP
1144 As mentioned in the discussion of \fBnew_GetLine()\fR, the number of lines that
1145 can be stored in the history buffer, depends on the lengths of the individual
1146 lines. For example, a 1000 byte buffer could equally store 10 lines of average
1147 length 100 bytes, or 20 lines of average length 50 bytes. Although the buffer
1148 is never expanded when new lines are added, a list of pointers into the buffer
1149 does get expanded when needed to accommodate the number of lines currently
1150 stored in the buffer. To place an upper limit on the number of lines in the
1151 buffer, and thus a ceiling on the amount of memory used in this list, you can
1152 call the \fBgl_limit_history()\fR function.
1153 .sp
1154 .LP
1155 The \fImax_lines\fR should either be a positive number >= 0, specifying an
1156 upper limit on the number of lines in the buffer, or be -1 to cancel any
1157 previously specified limit. When a limit is in effect, only the \fImax_lines\fR
1158 most recently appended lines are kept in the buffer. Older lines are discarded.
1159 .sp
1160 .LP
1161 To discard lines from the history buffer, use the \fBgl_clear_history()\fR
1162 function.
1163 .sp
1164 .LP
1165 The \fIall_groups\fR argument tells the function whether to delete just the
1166 lines associated with the current history group (see \fBgl_group_history()\fR)
1167 or all historical lines in the buffer.
1168 .sp
1169 .LP
1170 The \fBgl_toggle_history()\fR function allows you to toggle history on and off
1171 without losing the current contents of the history list.
1172 .sp
1173 .LP
1174 Setting the \fIenable\fR argument to 0 turns off the history mechanism, and
1175 setting it to 1 turns it back on. When history is turned off, no new lines will
1176 be added to the history list, and history lookup key-bindings will act as
1177 though there is nothing in the history buffer.
1178 .SS "Querying History Information"
1179 The configured state of the history list can be queried with the
1180 \fBgl_history_state()\fR function. On return, the status information is
1181 recorded in the variable pointed to by the \fIstate\fR argument.
1182 .sp
1183 .LP
1184 The \fBgl_range_of_history()\fR function returns the number and range of lines
1185 in the history list. The return values are recorded in the variable pointed to
1186 by the range argument. If the \fInlines\fR member of this structure is greater
1187 than zero, then the oldest and newest members report the range of lines in the
1188 list, and \fInewest\fR=\fIoldest\fR+\fInlines\fR-1. Otherwise they are both
1189 zero.
1190 .sp
1191 .LP
1192 The \fBgl_size_of_history()\fR function returns the total size of the history
1193 buffer and the amount of the buffer that is currently occupied.
1194 .sp
1195 .LP
1196 On return, the size information is recorded in the variable pointed to by the
1197 \fIsize\fR argument.
1198 .SS "Changing Terminals"
1199 The \fBnew_GetLine()\fR constructor function assumes that input is to be read
1200 from \fBstdin\fR and output written to \fBstdout\fR. The following function
1201 allows you to switch to different input and output streams.
1202 .sp
1203 .LP
1204 The \fIgl\fR argument is the object that was returned by \fBnew_GetLine()\fR.
1205 The \fIinput_fp\fR argument specifies the stream to read from, and
1206 \fIoutput_fp\fR specifies the stream to be written to. Only if both of these
1207 refer to a terminal, will interactive terminal input be enabled. Otherwise
1208 \fBgl_get_line()\fR will simply call \fBfgets()\fR to read command input. If
1209 both streams refer to a terminal, then they must refer to the same terminal,
1210 and the type of this terminal must be specified with the \fIterm\fR argument.
1211 The value of the \fIterm\fR argument is looked up in the terminal information
1212 database (\fBterminfo\fR or \fBtermcap\fR), in order to determine which special
1213 control sequences are needed to control various aspects of the terminal.
1214 \fBnew_GetLine()\fR for example, passes the return value of
1215 \fBgetenv\fR("TERM") in this argument. Note that if one or both of
1216 \fIinput_fp\fR and \fIoutput_fp\fR do not refer to a terminal, then it is legal
1217 to pass \fINULL\fR instead of a terminal type.
1218 .sp
1219 .LP
1220 Note that if you want to pass file descriptors to \fBgl_change_terminal()\fR,
1221 you can do this by creating \fBstdio\fR stream wrappers using the POSIX
1222 \fBfdopen\fR(3C) function.
1223 .SS "External Event Handling"
1224 By default, \fBgl_get_line()\fR does not return until either a complete input
1225 line has been entered by the user, or an error occurs. In programs that need to
1226 watch for I/O from other sources than the terminal, there are two options.
1227 .RS +4
1228 .TP
1229 .ie t \(bu
1230 .el o
1231 Use the functions described in the \fBgl_io_mode\fR(3TECLA) manual page to
1232 switch \fBgl_get_line()\fR into non-blocking server mode. In this mode,
1233 \fBgl_get_line()\fR becomes a non-blocking, incremental line-editing function
1234 that can safely be called from an external event loop. Although this is a very
1235 versatile method, it involves taking on some responsibilities that are normally
1236 performed behind the scenes by \fBgl_get_line()\fR.
1237 .RE
1238 .RS +4
1239 .TP
1240 .ie t \(bu
1241 .el o
1242 While \fBgl_get_line()\fR is waiting for keyboard input from the user, you can
1243 ask it to also watch for activity on arbitrary file descriptors, such as
1244 network sockets or pipes, and have it call functions of your choosing when
1245 activity is seen. This works on any system that has the select system call,
1246 which is most, if not all flavors of UNIX.
1247 .RE
1248 .sp
1249 .LP
1250 Registering a file descriptor to be watched by \fBgl_get_line()\fR involves
1251 calling the \fBgl_watch_fd()\fR function. If this returns non-zero, then it
1252 means that either your arguments are invalid, or that this facility is not
1253 supported on the host system.
1254 .sp
1255 .LP
1256 The \fIfd\fR argument is the file descriptor to be watched. The event argument
1257 specifies what type of activity is of interest, chosen from the following
1258 enumerated values:
1259 .sp
1260 .ne 2
1261 .na
1262 \fB\fBGLFD_READ\fR\fR
1263 .ad
1264 .RS 15n
1265 Watch for the arrival of data to be read.
1266 .RE
1267 
1268 .sp
1269 .ne 2
1270 .na
1271 \fB\fBGLFD_WRITE\fR\fR
1272 .ad
1273 .RS 15n
1274 Watch for the ability to write to the file descriptor without blocking.
1275 .RE
1276 
1277 .sp
1278 .ne 2
1279 .na
1280 \fB\fBGLFD_URGENT\fR\fR
1281 .ad
1282 .RS 15n
1283 Watch for the arrival of urgent out-of-band data on the file descriptor.
1284 .RE
1285 
1286 .sp
1287 .LP
1288 The \fIcallback\fR argument is the function to call when the selected activity
1289 is seen. It should be defined with the following macro, which is defined in
1290 libtecla.h.
1291 .sp
1292 .in +2
1293 .nf
1294 #define GL_FD_EVENT_FN(fn) GlFdStatus (fn)(GetLine *gl, \
1295                                    void *data, int fd, GlFdEvent event)
1296 .fi
1297 .in -2
1298 
1299 .sp
1300 .LP
1301 The data argument of the \fBgl_watch_fd()\fR function is passed to the callback
1302 function for its own use, and can point to anything you like, including
1303 \fINULL\fR. The file descriptor and the event argument are also passed to the
1304 callback function, and this potentially allows the same callback function to be
1305 registered to more than one type of event and/or more than one file descriptor.
1306 The return value of the callback function should be one of the following
1307 values.
1308 .sp
1309 .ne 2
1310 .na
1311 \fB\fBGLFD_ABORT\fR\fR
1312 .ad
1313 .RS 17n
1314 Tell \fBgl_get_line()\fR to abort. When this happens, \fBgl_get_line()\fR
1315 returns \fINULL\fR, and a following call to \fBgl_return_status()\fR will
1316 return \fBGLR_FDABORT\fR. Note that if the application needs \fBerrno\fR always
1317 to have a meaningful value when \fBgl_get_line()\fR returns \fINULL\fR, the
1318 callback function should set \fBerrno\fR appropriately.
1319 .RE
1320 
1321 .sp
1322 .ne 2
1323 .na
1324 \fB\fBGLFD_REFRESH\fR\fR
1325 .ad
1326 .RS 17n
1327 Redraw the input line  then continue waiting for input. Return this if your
1328 callback wrote to the terminal.
1329 .RE
1330 
1331 .sp
1332 .ne 2
1333 .na
1334 \fB\fBGLFD_CONTINUE\fR\fR
1335 .ad
1336 .RS 17n
1337 Continue to wait for input, without redrawing the line.
1338 .RE
1339 
1340 .sp
1341 .LP
1342 Note that before calling the callback, \fBgl_get_line()\fR blocks most signals
1343 and leaves its own signal handlers installed, so if you need to catch a
1344 particular signal you will need to both temporarily install your own signal
1345 handler, and unblock the signal. Be sure to re-block the signal (if it was
1346 originally blocked) and reinstate the original signal handler, if any, before
1347 returning.
1348 .sp
1349 .LP
1350 Your callback should not try to read from the terminal, which is left in raw
1351 mode as far as input is concerned. You can write to the terminal as usual,
1352 since features like conversion of newline to carriage-return/linefeed are
1353 re-enabled while the callback is running. If your callback function does write
1354 to the terminal, be sure to output a newline first, and when your callback
1355 returns, tell \fBgl_get_line()\fR that the input line needs to be redrawn, by
1356 returning the \fBGLFD_REFRESH\fR status code.
1357 .sp
1358 .LP
1359 To remove a callback function that you previously registered for a given file
1360 descriptor and event, simply call \fBgl_watch_fd()\fR with the same \fIfd\fR
1361 and \fIevent\fR arguments, but with a \fIcallback\fR argument of 0. The
1362 \fIdata\fR argument is ignored in this case.
1363 .SS "Setting An Inactivity Timeout"
1364 The \fBgl_inactivity_timeout()\fR function can be used to set or cancel an
1365 inactivity timeout. Inactivity in this case refers both to keyboard input, and
1366 to I/O on any file descriptors registered by prior and subsequent calls to
1367 \fBgl_watch_fd()\fR.
1368 .sp
1369 .LP
1370 The timeout is specified in the form of an integral number of seconds and an
1371 integral number of nanoseconds, specified by the \fIsec\fR and \fInsec\fR
1372 arguments, respectively. Subsequently, whenever no activity is seen for this
1373 time period, the function specified by the \fIcallback\fR argument is called.
1374 The \fIdata\fR argument of \fBgl_inactivity_timeout()\fR is passed to this
1375 callback function whenever it is invoked, and can thus be used to pass
1376 arbitrary application-specific information to the callback. The following macro
1377 is provided in <\fBlibtecla.h\fR> for applications to use to declare and
1378 prototype timeout callback functions.
1379 .sp
1380 .in +2
1381 .nf
1382 #define GL_TIMEOUT_FN(fn) GlAfterTimeout (fn)(GetLine *gl, void *data)
1383 .fi
1384 .in -2
1385 
1386 .sp
1387 .LP
1388 On returning, the application's callback is expected to return one of the
1389 following enumerators to tell \fBgl_get_line()\fR how to proceed after the
1390 timeout has been handled by the callback.
1391 .sp
1392 .ne 2
1393 .na
1394 \fB\fBGLTO_ABORT\fR\fR
1395 .ad
1396 .RS 17n
1397 Tell \fBgl_get_line()\fR to abort. When this happens, \fBgl_get_line()\fR will
1398 return \fINULL\fR, and a following call to \fBgl_return_status()\fR will return
1399 \fBGLR_TIMEOUT\fR. Note that if the application needs \fBerrno\fR always to
1400 have a meaningful value when \fBgl_get_line()\fR returns \fINULL\fR, the
1401 callback function should set \fBerrno\fR appropriately.
1402 .RE
1403 
1404 .sp
1405 .ne 2
1406 .na
1407 \fB\fBGLTO_REFRESH\fR\fR
1408 .ad
1409 .RS 17n
1410 Redraw the input line, then continue waiting for input. You should return this
1411 value if your callback wrote to the terminal.
1412 .RE
1413 
1414 .sp
1415 .ne 2
1416 .na
1417 \fB\fBGLTO_CONTINUE\fR\fR
1418 .ad
1419 .RS 17n
1420 In normal blocking-I/O mode, continue to wait for input, without redrawing the
1421 user's input line. In non-blocking server I/O mode (see
1422 \fBgl_io_mode\fR(3TECLA)), \fBgl_get_line()\fR acts as though I/O blocked. This
1423 means that \fBgl_get_line()\fR will immediately return \fINULL\fR, and a
1424 following call to \fBgl_return_status()\fR will return \fBGLR_BLOCKED\fR.
1425 .RE
1426 
1427 .sp
1428 .LP
1429 Note that before calling the callback, \fBgl_get_line()\fR blocks most signals
1430 and leaves its own signal handlers installed, so if you need to catch a
1431 particular signal you will need to both temporarily install your own signal
1432 handler and unblock the signal. Be sure to re-block the signal (if it was
1433 originally blocked) and reinstate the original signal handler, if any, before
1434 returning.
1435 .sp
1436 .LP
1437 Your callback should not try to read from the terminal, which is left in raw
1438 mode as far as input is concerned. You can however write to the terminal as
1439 usual, since features like conversion of newline to carriage-return/linefeed
1440 are re-enabled while the callback is running. If your callback function does
1441 write to the terminal, be sure to output a newline first, and when your
1442 callback returns, tell \fBgl_get_line()\fR that the input line needs to be
1443 redrawn, by returning the \fBGLTO_REFRESH\fR status code.
1444 .sp
1445 .LP
1446 Finally, note that although the timeout arguments include a nanosecond
1447 component, few computer clocks presently have resolutions that are finer than a
1448 few milliseconds, so asking for less than a few milliseconds is equivalent to
1449 requesting zero seconds on many systems. If this would be a problem, you should
1450 base your timeout selection on the actual resolution of the host clock (for
1451 example, by calling \fBsysconf\fR(\fB_SC_CLK_TCK\fR)).
1452 .sp
1453 .LP
1454 To turn off timeouts, simply call \fBgl_inactivity_timeout()\fR with a
1455 \fIcallback\fR argument of 0. The \fIdata\fR argument is ignored in this case.
1456 .SS "Signal Handling Defaults"
1457 By default, the \fBgl_get_line()\fR function intercepts a number of signals.
1458 This is particularly important for signals that would by default terminate the
1459 process, since the terminal needs to be restored to a usable state before this
1460 happens. This section describes the signals that are trapped by default and how
1461 \fBgl_get_line()\fR responds to them. Changing these defaults is the topic of
1462 the following section.
1463 .sp
1464 .LP
1465 When the following subset of signals are caught, \fBgl_get_line()\fR first
1466 restores the terminal settings and signal handling to how they were before
1467 \fBgl_get_line()\fR was called, resends the signal to allow the calling
1468 application's signal handlers to handle it, then, if the process still exists,
1469 returns \fINULL\fR and sets \fBerrno\fR as specified below.
1470 .sp
1471 .ne 2
1472 .na
1473 \fB\fBSIGINT\fR\fR
1474 .ad
1475 .RS 11n
1476 This signal is generated both by the keyboard interrupt key (usually \fB^C\fR),
1477 and the keyboard break key. The \fBerrno\fR value is \fBEINTR\fR.
1478 .RE
1479 
1480 .sp
1481 .ne 2
1482 .na
1483 \fB\fBSIGHUP\fR\fR
1484 .ad
1485 .RS 11n
1486 This signal is generated when the controlling terminal exits. The \fBerrno\fR
1487 value is \fBENOTTY\fR.
1488 .RE
1489 
1490 .sp
1491 .ne 2
1492 .na
1493 \fB\fBSIGPIPE\fR\fR
1494 .ad
1495 .RS 11n
1496 This signal is generated when a program attempts to write to a pipe whose
1497 remote end is not being read by any process. This can happen for example if you
1498 have called \fBgl_change_terminal()\fR to redirect output to a pipe hidden
1499 under a pseudo terminal. The \fBerrno\fR value is \fBEPIPE\fR.
1500 .RE
1501 
1502 .sp
1503 .ne 2
1504 .na
1505 \fB\fBSIGQUIT\fR\fR
1506 .ad
1507 .RS 11n
1508 This signal is generated by the keyboard quit key (usually \fB^\e\fR). The
1509 \fBerrno\fR value is \fBEINTR\fR.
1510 .RE
1511 
1512 .sp
1513 .ne 2
1514 .na
1515 \fB\fBSIGABRT\fR\fR
1516 .ad
1517 .RS 11n
1518 This signal is generated by the standard C, abort function. By default it both
1519 terminates the process and generates a core dump. The \fBerrno\fR value is
1520 \fBEINTR\fR.
1521 .RE
1522 
1523 .sp
1524 .ne 2
1525 .na
1526 \fB\fBSIGTERM\fR\fR
1527 .ad
1528 .RS 11n
1529 This is the default signal that the UNIX kill command sends to processes. The
1530 \fBerrno\fR value is \fBEINTR\fR.
1531 .RE
1532 
1533 .sp
1534 .LP
1535 Note that in the case of all of the above signals, POSIX mandates that by
1536 default the process is terminated, with the addition of a core dump in the case
1537 of the \fBSIGQUIT\fR signal. In other words, if the calling application does
1538 not override the default handler by supplying its own signal handler, receipt
1539 of the corresponding signal will terminate the application before
1540 \fBgl_get_line()\fR returns.
1541 .sp
1542 .LP
1543 If \fBgl_get_line()\fR aborts with \fBerrno\fR set to \fBEINTR\fR, you can find
1544 out what signal caused it to abort, by calling the \fBgl_last_signal()\fR
1545 function. This returns the numeric code (for example, \fBSIGINT\fR) of the last
1546 signal that was received during the most recent call to \fBgl_get_line()\fR, or
1547 -1 if no signals were received.
1548 .sp
1549 .LP
1550 On systems that support it, when a \fBSIGWINCH\fR (window change) signal is
1551 received, \fBgl_get_line()\fR queries the terminal to find out its new size,
1552 redraws the current input line to accommodate the new size, then returns to
1553 waiting for keyboard input from the user. Unlike other signals, this signal is
1554 not resent to the application.
1555 .sp
1556 .LP
1557 Finally, the following signals cause \fBgl_get_line()\fR to first restore the
1558 terminal and signal environment to that which prevailed before
1559 \fBgl_get_line()\fR was called, then resend the signal to the application. If
1560 the process still exists after the signal has been delivered, then
1561 \fBgl_get_line()\fR then re-establishes its own signal handlers, switches the
1562 terminal back to raw mode, redisplays the input line, and goes back to awaiting
1563 terminal input from the user.
1564 .sp
1565 .ne 2
1566 .na
1567 \fB\fBSIGCONT\fR\fR
1568 .ad
1569 .RS 13n
1570 This signal is generated when a suspended process is resumed.
1571 .RE
1572 
1573 .sp
1574 .ne 2
1575 .na
1576 \fB\fBSIGPOLL\fR\fR
1577 .ad
1578 .RS 13n
1579 On SVR4 systems, this signal notifies the process of an asynchronous I/O event.
1580 Note that under 4.3+BSD, \fBSIGIO\fR and \fBSIGPOLL\fR are the same. On other
1581 systems, \fBSIGIO\fR is ignored by default, so \fBgl_get_line()\fR does not
1582 trap it by default.
1583 .RE
1584 
1585 .sp
1586 .ne 2
1587 .na
1588 \fB\fBSIGPWR\fR\fR
1589 .ad
1590 .RS 13n
1591 This signal is generated when a power failure occurs (presumably when the
1592 system is on a UPS).
1593 .RE
1594 
1595 .sp
1596 .ne 2
1597 .na
1598 \fB\fBSIGALRM\fR\fR
1599 .ad
1600 .RS 13n
1601 This signal is generated when a timer expires.
1602 .RE
1603 
1604 .sp
1605 .ne 2
1606 .na
1607 \fB\fBSIGUSR1\fR\fR
1608 .ad
1609 .RS 13n
1610 An application specific signal.
1611 .RE
1612 
1613 .sp
1614 .ne 2
1615 .na
1616 \fB\fBSIGUSR2\fR\fR
1617 .ad
1618 .RS 13n
1619 Another application specific signal.
1620 .RE
1621 
1622 .sp
1623 .ne 2
1624 .na
1625 \fB\fBSIGVTALRM\fR\fR
1626 .ad
1627 .RS 13n
1628 This signal is generated when a virtual timer expires. See \fBsetitimer\fR(2).
1629 .RE
1630 
1631 .sp
1632 .ne 2
1633 .na
1634 \fB\fBSIGXCPU\fR\fR
1635 .ad
1636 .RS 13n
1637 This signal is generated when a process exceeds its soft CPU time limit.
1638 .RE
1639 
1640 .sp
1641 .ne 2
1642 .na
1643 \fB\fBSIGXFSZ\fR\fR
1644 .ad
1645 .RS 13n
1646 This signal is generated when a process exceeds its soft file-size limit.
1647 .RE
1648 
1649 .sp
1650 .ne 2
1651 .na
1652 \fB\fBSIGTSTP\fR\fR
1653 .ad
1654 .RS 13n
1655 This signal is generated by the terminal suspend key, which is usually
1656 \fB^Z\fR, or the delayed terminal suspend key, which is usually \fB^Y\fR.
1657 .RE
1658 
1659 .sp
1660 .ne 2
1661 .na
1662 \fB\fBSIGTTIN\fR\fR
1663 .ad
1664 .RS 13n
1665 This signal is generated if the program attempts to read from the terminal
1666 while the program is running in the background.
1667 .RE
1668 
1669 .sp
1670 .ne 2
1671 .na
1672 \fB\fBSIGTTOU\fR\fR
1673 .ad
1674 .RS 13n
1675 This signal is generated if the program attempts to write to the terminal while
1676 the program is running in the background.
1677 .RE
1678 
1679 .sp
1680 .LP
1681 Obviously not all of the above signals are supported on all systems, so code to
1682 support them is conditionally compiled into the tecla library.
1683 .sp
1684 .LP
1685 Note that if \fBSIGKILL\fR or \fBSIGPOLL\fR, which by definition cannot be
1686 caught, or any of the hardware generated exception signals, such as
1687 \fBSIGSEGV\fR, \fBSIGBUS\fR, and \fBSIGFPE\fR, are received and unhandled while
1688 \fBgl_get_line()\fR has the terminal in raw mode, the program will be
1689 terminated without the terminal having been restored to a usable state. In
1690 practice, job-control shells usually reset the terminal settings when a process
1691 relinquishes the controlling terminal, so this is only a problem with older
1692 shells.
1693 .SS "Customized Signal Handling"
1694 The previous section listed the signals that \fBgl_get_line()\fR traps by
1695 default, and described how it responds to them. This section describes how to
1696 both add and remove signals from the list of trapped signals, and how to
1697 specify how \fBgl_get_line()\fR should respond to a given signal.
1698 .sp
1699 .LP
1700 If you do not need \fBgl_get_line()\fR to do anything in response to a signal
1701 that it normally traps, you can tell to \fBgl_get_line()\fR to ignore that
1702 signal by calling \fBgl_ignore_signal()\fR.
1703 .sp
1704 .LP
1705 The \fIsigno\fR argument is the number of the signal (for example,
1706 \fBSIGINT\fR) that you want to have ignored. If the specified signal is not
1707 currently one of those being trapped, this function does nothing.
1708 .sp
1709 .LP
1710 The \fBgl_trap_signal()\fR function allows you to either add a new signal to
1711 the list that \fBgl_get_line()\fR traps or modify how it responds to a signal
1712 that it already traps.
1713 .sp
1714 .LP
1715 The \fIsigno\fR argument is the number of the signal that you want to have
1716 trapped. The \fIflags\fR argument is a set of flags that determine the
1717 environment in which the application's signal handler is invoked. The
1718 \fIafter\fR argument tells \fBgl_get_line()\fR what to do after the
1719 application's signal handler returns. The \fIerrno_value\fR tells
1720 \fBgl_get_line()\fR what to set \fBerrno\fR to if told to abort.
1721 .sp
1722 .LP
1723 The \fIflags\fR argument is a bitwise OR of zero or more of the following
1724 enumerators:
1725 .sp
1726 .ne 2
1727 .na
1728 \fB\fBGLS_RESTORE_SIG\fR\fR
1729 .ad
1730 .RS 20n
1731 Restore the caller's signal environment while handling the signal.
1732 .RE
1733 
1734 .sp
1735 .ne 2
1736 .na
1737 \fB\fBGLS_RESTORE_TTY\fR\fR
1738 .ad
1739 .RS 20n
1740 Restore the caller's terminal settings while handling the signal.
1741 .RE
1742 
1743 .sp
1744 .ne 2
1745 .na
1746 \fB\fBGLS_RESTORE_LINE\fR\fR
1747 .ad
1748 .RS 20n
1749 Move the cursor to the start of the line following the input line before
1750 invoking the application's signal handler.
1751 .RE
1752 
1753 .sp
1754 .ne 2
1755 .na
1756 \fB\fBGLS_REDRAW_LINE\fR\fR
1757 .ad
1758 .RS 20n
1759 Redraw the input line when the application's signal handler returns.
1760 .RE
1761 
1762 .sp
1763 .ne 2
1764 .na
1765 \fB\fBGLS_UNBLOCK_SIG\fR\fR
1766 .ad
1767 .RS 20n
1768 Normally, if the calling program has a signal blocked (see
1769 \fBsigprocmask\fR(2)), \fBgl_get_line()\fR does not trap that signal. This flag
1770 tells \fBgl_get_line()\fR to trap the signal and unblock it for the duration of
1771 the call to \fBgl_get_line()\fR.
1772 .RE
1773 
1774 .sp
1775 .ne 2
1776 .na
1777 \fB\fBGLS_DONT_FORWARD\fR\fR
1778 .ad
1779 .RS 20n
1780 If this flag is included, the signal will not be forwarded to the signal
1781 handler of the calling program.
1782 .RE
1783 
1784 .sp
1785 .LP
1786 Two commonly useful flag combinations are also enumerated as follows:
1787 .sp
1788 .ne 2
1789 .na
1790 \fB\fBGLS_RESTORE_ENV\fR\fR
1791 .ad
1792 .RS 21n
1793 \fBGLS_RESTORE_SIG\fR | \fBGLS_RESTORE_TTY\fR |\fBGLS_REDRAW_LINE\fR
1794 .RE
1795 
1796 .sp
1797 .ne 2
1798 .na
1799 \fB\fBGLS_SUSPEND_INPUT\fR\fR
1800 .ad
1801 .RS 21n
1802 \fBGLS_RESTORE_ENV\fR | \fBGLS_RESTORE_LINE\fR
1803 .RE
1804 
1805 .sp
1806 .LP
1807 If your signal handler, or the default system signal handler for this signal,
1808 if you have not overridden it, never either writes to the terminal, nor
1809 suspends or terminates the calling program, then you can safely set the
1810 \fIflags\fR argument to 0.
1811 .RS +4
1812 .TP
1813 .ie t \(bu
1814 .el o
1815 The cursor does not get left in the middle of the input line.
1816 .RE
1817 .RS +4
1818 .TP
1819 .ie t \(bu
1820 .el o
1821 So that the user can type in input and have it echoed.
1822 .RE
1823 .RS +4
1824 .TP
1825 .ie t \(bu
1826 .el o
1827 So that you do not need to end each output line with \er\en, instead of just
1828 \en.
1829 .RE
1830 .sp
1831 .LP
1832 The \fBGL_RESTORE_ENV\fR combination is the same as \fBGL_SUSPEND_INPUT\fR,
1833 except that it does not move the cursor. If your signal handler does not read
1834 or write anything to the terminal, the user will not see any visible indication
1835 that a signal was caught. This can be useful if you have a signal handler that
1836 only occasionally writes to the terminal, where using \fBGL_SUSPEND_LINE\fR
1837 would cause the input line to be unnecessarily duplicated when nothing had been
1838 written to the terminal. Such a signal handler, when it does write to the
1839 terminal, should be sure to start a new line at the start of its first write,
1840 by writing a new line before returning. If the signal arrives while the user is
1841 entering a line that only occupies a signal terminal line, or if the cursor is
1842 on the last terminal line of a longer input line, this will have the same
1843 effect as \fBGL_SUSPEND_INPUT\fR. Otherwise it will start writing on a line
1844 that already contains part of the displayed input line. This does not do any
1845 harm, but it looks a bit ugly, which is why the \fBGL_SUSPEND_INPUT\fR
1846 combination is better if you know that you are always going to be writing to
1847 the terminal.
1848 .sp
1849 .LP
1850 The \fIafter\fR argument, which determines what \fBgl_get_line()\fR does after
1851 the application's signal handler returns (if  it returns), can take any one of
1852 the following values:
1853 .sp
1854 .ne 2
1855 .na
1856 \fB\fBGLS_RETURN\fR\fR
1857 .ad
1858 .RS 16n
1859 Return the completed input line, just as though the user had pressed the return
1860 key.
1861 .RE
1862 
1863 .sp
1864 .ne 2
1865 .na
1866 \fB\fBGLS_ABORT\fR\fR
1867 .ad
1868 .RS 16n
1869 Cause \fBgl_get_line()\fR to abort. When this happens, \fBgl_get_line()\fR
1870 returns \fINULL\fR, and a following call to \fBgl_return_status()\fR will
1871 return \fBGLR_SIGNAL\fR. Note that if the application needs \fBerrno\fR always
1872 to have a meaningful value when \fBgl_get_line()\fR returns \fINULL\fR, the
1873 callback function should set \fBerrno\fR appropriately.
1874 .RE
1875 
1876 .sp
1877 .ne 2
1878 .na
1879 \fB\fBGLS_CONTINUE\fR\fR
1880 .ad
1881 .RS 16n
1882 Resume command line editing.
1883 .RE
1884 
1885 .sp
1886 .LP
1887 The \fIerrno_value\fR argument is intended to be combined with the
1888 \fBGLS_ABORT\fR option, telling \fBgl_get_line()\fR what to set the standard
1889 \fBerrno\fR variable to before returning \fINULL\fR to the calling program. It
1890 can also, however, be used with the \fBGL_RETURN\fR option, in case you want to
1891 have a way to distinguish between an input line that was entered using the
1892 return key, and one that was entered by the receipt of a signal.
1893 .SS "Reliable Signal Handling"
1894 Signal handling is surprisingly hard to do reliably without race conditions. In
1895 \fBgl_get_line()\fR a lot of care has been taken to allow applications to
1896 perform reliable signal handling around \fBgl_get_line()\fR. This section
1897 explains how to make use of this.
1898 .sp
1899 .LP
1900 As an example of the problems that can arise if the application is not written
1901 correctly, imagine that one's application has a \fBSIGINT\fR signal handler
1902 that sets a global flag. Now suppose that the application tests this flag just
1903 before invoking \fBgl_get_line()\fR. If a \fBSIGINT\fR signal happens to be
1904 received in the small window of time between the statement that tests the value
1905 of this flag, and the statement that calls \fBgl_get_line()\fR, then
1906 \fBgl_get_line()\fR will not see the signal, and will not be interrupted. As a
1907 result, the application will not be able to respond to the signal until the
1908 user gets around to finishing entering the input line and \fBgl_get_line()\fR
1909 returns. Depending on the application, this might or might not be a disaster,
1910 but at the very least it would puzzle the user.
1911 .sp
1912 .LP
1913 The way to avoid such problems is to do the following.
1914 .RS +4
1915 .TP
1916 1.
1917 If needed, use the \fBgl_trap_signal()\fR function to configure
1918 \fBgl_get_line()\fR to abort when important signals are caught.
1919 .RE
1920 .RS +4
1921 .TP
1922 2.
1923 Configure \fBgl_get_line()\fR such that if any of the signals that it
1924 catches are blocked when \fBgl_get_line()\fR is called, they will be unblocked
1925 automatically during times when \fBgl_get_line()\fR is waiting for I/O. This
1926 can be done either on a per signal basis, by calling the \fBgl_trap_signal()\fR
1927 function, and specifying the \fBGLS_UNBLOCK\fR attribute of the signal, or
1928 globally by calling the \fBgl_catch_blocked()\fR function. This function simply
1929 adds the \fBGLS_UNBLOCK\fR attribute to all of the signals that it is currently
1930 configured to trap.
1931 .RE
1932 .RS +4
1933 .TP
1934 3.
1935 Just before calling \fBgl_get_line()\fR, block delivery of all of the
1936 signals that \fBgl_get_line()\fR is configured to trap. This can be done using
1937 the POSIX sigprocmask function in conjunction with the \fBgl_list_signals()\fR
1938 function. This function returns the set of signals that it is currently
1939 configured to catch in the set argument, which is in the form required by
1940 \fBsigprocmask\fR(2).
1941 .RE
1942 .RS +4
1943 .TP
1944 4.
1945 In the example, one would now test the global flag that the signal handler
1946 sets, knowing that there is now no danger of this flag being set again until
1947 \fBgl_get_line()\fR unblocks its signals while performing I/O.
1948 .RE
1949 .RS +4
1950 .TP
1951 5.
1952 Eventually \fBgl_get_line()\fR returns, either because a signal was caught,
1953 an error occurred, or the user finished entering their input line.
1954 .RE
1955 .RS +4
1956 .TP
1957 6.
1958 Now one would check the global signal flag again, and if it is set, respond
1959 to it, and zero the flag.
1960 .RE
1961 .RS +4
1962 .TP
1963 7.
1964 Use \fBsigprocmask()\fR to unblock the signals that were blocked in step 3.
1965 .RE
1966 .sp
1967 .LP
1968 The same technique can be used around certain POSIX signal-aware functions,
1969 such as \fBsigsetjmp\fR(3C) and \fBsigsuspend\fR(2), and in particular, the
1970 former of these two functions can be used in conjunction with
1971 \fBsiglongjmp\fR(3C) to implement race-condition free signal handling around
1972 other long-running system calls. The \fBgl_get_line()\fR function manages to
1973 reliably trap signals around calls to functions like \fBread\fR(2) and
1974 \fBselect\fR(3C) without race conditions.
1975 .sp
1976 .LP
1977 The \fBgl_get_line()\fR function first uses the POSIX \fBsigprocmask()\fR
1978 function to block the delivery of all of the signals that it is currently
1979 configured to catch. This is redundant if the application has already blocked
1980 them, but it does no harm. It undoes this step just before returning.
1981 .sp
1982 .LP
1983 Whenever \fBgl_get_line()\fR needs to call read or select to wait for input
1984 from the user, it first calls the POSIX \fBsigsetjmp()\fR function, being sure
1985 to specify a non-zero value for its \fIsavemask\fR argument.
1986 .sp
1987 .LP
1988 If \fBsigsetjmp()\fR returns zero, \fBgl_get_line()\fR then does the following.
1989 .RS +4
1990 .TP
1991 1.
1992 It uses the POSIX \fBsigaction\fR(2) function to register a temporary signal
1993 handler to all of the signals that it is configured to catch. This signal
1994 handler does two things.
1995 .RS +4
1996 .TP
1997 a.
1998 It records the number of the signal that was received in a file-scope
1999 variable.
2000 .RE
2001 .RS +4
2002 .TP
2003 b.
2004 It then calls the POSIX \fBsiglongjmp()\fR function using the buffer that
2005 was passed to \fBsigsetjmp()\fR for its first argument and a non-zero value for
2006 its second argument.
2007 .RE
2008 When this signal handler is registered, the \fIsa_mask\fR member of the
2009 \fBstruct sigaction\fR \fIact\fR argument of the call to \fBsigaction()\fR is
2010 configured to contain all of the signals that \fBgl_get_line()\fR is catching.
2011 This ensures that only one signal will be caught at once by our signal handler,
2012 which in turn ensures that multiple instances of our signal handler do not
2013 tread on each other's toes.
2014 .RE
2015 .RS +4
2016 .TP
2017 2.
2018 Now that the signal handler has been set up, \fBgl_get_line()\fR unblocks
2019 all of the signals that it is configured to catch.
2020 .RE
2021 .RS +4
2022 .TP
2023 3.
2024 It then calls the \fBread()\fR or \fBselect()\fR function to wait for
2025 keyboard input.
2026 .RE
2027 .RS +4
2028 .TP
2029 4.
2030 If this function returns (that is, no signal is received),
2031 \fBgl_get_line()\fR blocks delivery of the signals of interest again.
2032 .RE
2033 .RS +4
2034 .TP
2035 5.
2036 It then reinstates the signal handlers that were displaced by the one that
2037 was just installed.
2038 .RE
2039 .sp
2040 .LP
2041 Alternatively, if \fBsigsetjmp()\fR returns non-zero, this means that one of
2042 the signals being trapped was caught while the above steps were executing. When
2043 this happens, \fBgl_get_line()\fR does the following.
2044 .sp
2045 .LP
2046 First, note that when a call to \fBsiglongjmp()\fR causes \fBsigsetjmp()\fR to
2047 return, provided that the \fIsavemask\fR argument of \fBsigsetjmp()\fR was
2048 non-zero, the signal process mask is restored to how it was when
2049 \fBsigsetjmp()\fR was called. This is the important difference between
2050 \fBsigsetjmp()\fR and the older problematic \fBsetjmp\fR(3C), and is the
2051 essential ingredient that makes it possible to avoid signal handling race
2052 conditions. Because of this we are guaranteed that all of the signals that we
2053 blocked before calling \fBsigsetjmp()\fR are blocked again as soon as any
2054 signal is caught. The following statements, which are then executed, are thus
2055 guaranteed to be executed without any further signals being caught.
2056 .RS +4
2057 .TP
2058 1.
2059 If so instructed by the \fBgl_get_line()\fR configuration attributes of the
2060 signal that was caught, \fBgl_get_line()\fR restores the terminal attributes to
2061 the state that they had when \fBgl_get_line()\fR was called. This is
2062 particularly important for signals that suspend or terminate the process, since
2063 otherwise the terminal would be left in an unusable state.
2064 .RE
2065 .RS +4
2066 .TP
2067 2.
2068 It then reinstates the application's signal handlers.
2069 .RE
2070 .RS +4
2071 .TP
2072 3.
2073 Then it uses the C standard-library \fBraise\fR(3C) function to re-send the
2074 application the signal that was caught.
2075 .RE
2076 .RS +4
2077 .TP
2078 4.
2079 Next it unblocks delivery of the signal that we just sent. This results in
2080 the signal that was just sent by \fBraise()\fR being caught by the
2081 application's original signal handler, which can now handle it as it sees fit.
2082 .RE
2083 .RS +4
2084 .TP
2085 5.
2086 If the signal handler returns (that is, it does not terminate the process),
2087 \fBgl_get_line()\fR blocks delivery of the above signal again.
2088 .RE
2089 .RS +4
2090 .TP
2091 6.
2092 It then undoes any actions performed in the first of the above steps and
2093 redisplays the line, if the signal configuration calls for this.
2094 .RE
2095 .RS +4
2096 .TP
2097 7.
2098 \fBgl_get_line()\fR then either resumes trying to read a character, or
2099 aborts, depending on the configuration of the signal that was caught.
2100 .RE
2101 .sp
2102 .LP
2103 What the above steps do in essence is to take asynchronously delivered signals
2104 and handle them synchronously, one at a time, at a point in the code where
2105 \fBgl_get_line()\fR has complete control over its environment.
2106 .SS "The Terminal Size"
2107 On most systems the combination of the \fBTIOCGWINSZ\fR ioctl and the
2108 \fBSIGWINCH\fR signal is used to maintain an accurate idea of the terminal
2109 size. The terminal size is newly queried every time that \fBgl_get_line()\fR is
2110 called and whenever a \fBSIGWINCH\fR signal is received.
2111 .sp
2112 .LP
2113 On the few systems where this mechanism is not available, at startup
2114 \fBnew_GetLine()\fR first looks for the \fBLINES\fR and \fBCOLUMNS\fR
2115 environment variables. If these are not found, or they contain unusable values,
2116 then if a terminal information database like \fBterminfo\fR or \fBtermcap\fR is
2117 available, the default size of the terminal is looked up in this database. If
2118 this too fails to provide the terminal size, a default size of 80 columns by 24
2119 lines is used.
2120 .sp
2121 .LP
2122 Even on systems that do support ioctl(\fBTIOCGWINSZ\fR), if the terminal is on
2123 the other end of a serial line, the terminal driver generally has no way of
2124 detecting when a resize occurs or of querying what the current size is. In such
2125 cases no \fBSIGWINCH\fR is sent to the process, and the dimensions returned by
2126 ioctl(\fBTIOCGWINSZ\fR) are not correct. The only way to handle such instances
2127 is to provide a way for the user to enter a command that tells the remote
2128 system what the new size is. This command would then call the
2129 \fBgl_set_term_size()\fR function to tell \fBgl_get_line()\fR about the change
2130 in size.
2131 .sp
2132 .LP
2133 The \fIncolumn\fR and \fInline\fR arguments are used to specify the new
2134 dimensions of the terminal, and must not be less than 1. On systems that do
2135 support ioctl(\fBTIOCGWINSZ\fR), this function first calls
2136 ioctl(\fBTIOCSWINSZ\fR) to tell the terminal driver about the change in size.
2137 In non-blocking server-I/O mode, if a line is currently being input, the input
2138 line is then redrawn to accommodate the changed size. Finally the new values are
2139 recorded in \fIgl\fR for future use by \fBgl_get_line()\fR.
2140 .sp
2141 .LP
2142 The \fBgl_terminal_size()\fR function allows you to query the current size of
2143 the terminal, and install an alternate fallback size for cases where the size
2144 is not available. Beware that the terminal size will not be available if
2145 reading from a pipe or a file, so the default values can be important even on
2146 systems that do support ways of finding out the terminal size.
2147 .sp
2148 .LP
2149 This function first updates \fBgl_get_line()\fR's fallback terminal dimensions,
2150 then records its findings in the return value.
2151 .sp
2152 .LP
2153 The \fIdef_ncolumn\fR and \fIdef_nline\fR arguments specify the default number
2154 of terminal columns and lines to use if the terminal size cannot be determined
2155 by ioctl(\fBTIOCGWINSZ\fR) or environment variables.
2156 .SS "Hiding What You Type"
2157 When entering sensitive information, such as passwords, it is best not to have
2158 the text that you are entering echoed on the terminal. Furthermore, such text
2159 should not be recorded in the history list, since somebody finding your
2160 terminal unattended could then recall it, or somebody snooping through your
2161 directories could see it in your history file. With this in mind, the
2162 \fBgl_echo_mode()\fR function allows you to toggle on and off the display and
2163 archival of any text that is subsequently entered in calls to
2164 \fBgl_get_line()\fR.
2165 .sp
2166 .LP
2167 The \fIenable\fR argument specifies whether entered text should be visible or
2168 not. If it is 0, then subsequently entered lines will not be visible on the
2169 terminal, and will not be recorded in the history list. If it is 1, then
2170 subsequent input lines will be displayed as they are entered, and provided that
2171 history has not been turned off with a call to \fBgl_toggle_history()\fR, then
2172 they will also be archived in the history list. Finally, if the enable argument
2173 is -1, then the echoing mode is left unchanged, which allows you to
2174 non-destructively query the current setting through the return value. In all
2175 cases, the return value of the function is 0 if echoing was disabled before the
2176 function was called, and 1 if it was enabled.
2177 .sp
2178 .LP
2179 When echoing is turned off, note that although tab completion will invisibly
2180 complete your prefix as far as possible, ambiguous completions will not be
2181 displayed.
2182 .SS "Single Character Queries"
2183 Using \fBgl_get_line()\fR to query the user for a single character reply, is
2184 inconvenient for the user, since they must hit the enter or return key before
2185 the character that they typed is returned to the program. Thus the
2186 \fBgl_query_char()\fR function has been provided for single character queries
2187 like this.
2188 .sp
2189 .LP
2190 This function displays the specified prompt at the start of a new line, and
2191 waits for the user to type a character. When the user types a character,
2192 \fBgl_query_char()\fR displays it to the right of the prompt, starts a newline,
2193 then returns the character to the calling program. The return value of the
2194 function is the character that was typed. If the read had to be aborted for
2195 some reason, EOF is returned instead. In the latter case, the application can
2196 call the previously documented \fBgl_return_status()\fR, to find out what went
2197 wrong. This could, for example, have been the reception of a signal, or the
2198 optional inactivity timer going off.
2199 .sp
2200 .LP
2201 If the user simply hits enter, the value of the \fIdefchar\fR argument is
2202 substituted. This means that when the user hits either newline or return, the
2203 character specified in \fIdefchar\fR, is displayed after the prompt, as though
2204 the user had typed it, as well as being returned to the calling application. If
2205 such a replacement is not important, simply pass '\en' as the value of
2206 \fIdefchar\fR.
2207 .sp
2208 .LP
2209 If the entered character is an unprintable character, it is displayed
2210 symbolically. For example, control-A is displayed as \fB^A\fR, and characters
2211 beyond 127 are displayed in octal, preceded by a backslash.
2212 .sp
2213 .LP
2214 As with \fBgl_get_line()\fR, echoing of the entered character can be disabled
2215 using the \fBgl_echo_mode()\fR function.
2216 .sp
2217 .LP
2218 If the calling process is suspended while waiting for the user to type their
2219 response, the cursor is moved to the line following the prompt line, then when
2220 the process resumes, the prompt is redisplayed, and \fBgl_query_char()\fR
2221 resumes waiting for the user to type a character.
2222 .sp
2223 .LP
2224 Note that in non-blocking server mode, if an incomplete input line is in the
2225 process of being read when \fBgl_query_char()\fR is called, the partial input
2226 line is discarded, and erased from the terminal, before the new prompt is
2227 displayed. The next call to \fBgl_get_line()\fR will thus start editing a new
2228 line.
2229 .SS "Reading Raw Characters"
2230 Whereas the \fBgl_query_char()\fR function visibly prompts the user for a
2231 character, and displays what they typed, the \fBgl_read_char()\fR function
2232 reads a signal character from the user, without writing anything to the
2233 terminal, or perturbing any incompletely entered input line. This means that it
2234 can be called not only from between calls to \fBgl_get_line()\fR, but also from
2235 callback functions that the application has registered to be called by
2236 \fBgl_get_line()\fR.
2237 .sp
2238 .LP
2239 On success, the return value of \fBgl_read_char()\fR is the character that was
2240 read. On failure, EOF is returned, and the \fBgl_return_status()\fR function
2241 can be called to find out what went wrong. Possibilities include the optional
2242 inactivity timer going off, the receipt of a signal that is configured to abort
2243 \fBgl_get_line()\fR, or terminal I/O blocking, when in non-blocking server-I/O
2244 mode.
2245 .sp
2246 .LP
2247 Beware that certain keyboard keys, such as function keys, and cursor keys,
2248 usually generate at least three characters each, so a single call to
2249 \fBgl_read_char()\fR will not be enough to identify such keystrokes.
2250 .SS "Clearing The Terminal"
2251 The calling program can clear the terminal by calling
2252 \fBgl_erase_terminal()\fR. In non-blocking server-I/O mode, this function also
2253 arranges for the current input line to be redrawn from scratch when
2254 \fBgl_get_line()\fR is next called.
2255 .SS "Displaying Text Dynamically"
2256 Between calls to \fBgl_get_line()\fR, the \fBgl_display_text()\fR function
2257 provides a convenient way to display paragraphs of text, left-justified and
2258 split over one or more terminal lines according to the constraints of the
2259 current width of the terminal. Examples of the use of this function may be
2260 found in the demo programs, where it is used to display introductions. In those
2261 examples the advanced use  of optional prefixes, suffixes and filled lines to
2262 draw a box around the text is also illustrated.
2263 .sp
2264 .LP
2265 If \fIgl\fR is not currently connected to a terminal, for example if the output
2266 of a program that uses \fBgl_get_line()\fR is being piped to another program or
2267 redirected to a file, then the value of the \fIdef_width\fR parameter is used
2268 as the terminal width.
2269 .sp
2270 .LP
2271 The \fIindentation\fR argument specifies the number of characters to use to
2272 indent each line of output. The \fIfill_char\fR argument specifies the character
2273 that will be used to perform this indentation.
2274 .sp
2275 .LP
2276 The \fIprefix\fR argument can be either \fINULL\fR or a string to place at the
2277 beginning of each new line (after any indentation). Similarly, the \fIsuffix\fR
2278 argument can be either \fINULL\fR or a string to place at the end of each line.
2279 The suffix is placed flush against the right edge of the terminal, and any
2280 space between its first character and the last word on that line is filled with
2281 the character specified by the \fIfill_char\fR argument. Normally the
2282 fill-character is a space.
2283 .sp
2284 .LP
2285 The \fIstart\fR argument tells \fBgl_display_text()\fR how many characters have
2286 already been written to the current terminal line, and thus tells it the
2287 starting column index of the cursor. Since the return value of
2288 \fBgl_display_text()\fR is the ending column index of the cursor, by passing
2289 the return value of one call to the start argument of the next call, a
2290 paragraph that is broken between more than one string can be composed by
2291 calling \fBgl_display_text()\fR for each successive portion of the paragraph.
2292 Note that literal newline characters are necessary at the end of each paragraph
2293 to force a new line to be started.
2294 .sp
2295 .LP
2296 On error, \fBgl_display_text()\fR returns -1.
2297 .SS "Callback Function Facilities"
2298 Unless otherwise stated, callback functions such as tab completion callbacks
2299 and event callbacks should not call any functions in this module. The following
2300 functions, however, are designed specifically to be used by callback functions.
2301 .sp
2302 .LP
2303 Calling the \fBgl_replace_prompt()\fR function from a callback tells
2304 \fBgl_get_line()\fR to display a different prompt when the callback returns.
2305 Except in non-blocking server mode, it has no effect if used between calls to
2306 \fBgl_get_line()\fR. In non-blocking server mode, when used between two calls
2307 to \fBgl_get_line()\fR that are operating on the same input line, the current
2308 input line will be re-drawn with the new prompt on the following call to
2309 \fBgl_get_line()\fR.
2310 .SS "International Character Sets"
2311 Since \fBlibtecla\fR(3LIB) version 1.4.0, \fBgl_get_line()\fR has been 8-bit
2312 clean. This means that all 8-bit characters that are printable in the user's
2313 current locale are now displayed verbatim and included in the returned input
2314 line. Assuming that the calling program correctly contains a call like the
2315 following,
2316 .sp
2317 .in +2
2318 .nf
2319 setlocale(LC_CTYPE, "")
2320 .fi
2321 .in -2
2322 
2323 .sp
2324 .LP
2325 then the current locale is determined by the first of the environment variables
2326 \fBLC_CTYPE\fR, \fBLC_ALL\fR, and \fBLANG\fR that is found to contain a valid
2327 locale name. If none of these variables are defined, or the program neglects to
2328 call \fBsetlocale\fR(3C), then the default C locale is used, which is US 7-bit
2329 ASCII. On most UNIX-like platforms, you can get a list of valid locales by
2330 typing the command:
2331 .sp
2332 .in +2
2333 .nf
2334 locale -a
2335 .fi
2336 .in -2
2337 .sp
2338 
2339 .sp
2340 .LP
2341 at the shell prompt. Further documentation on how the user can make use of this
2342 to enter international characters can be found in the \fBtecla\fR(5) man page.
2343 .SS "Thread Safety"
2344 Unfortunately neither \fBterminfo\fR nor \fBtermcap\fR were designed to be
2345 reentrant, so you cannot safely use the functions of the getline module in
2346 multiple threads (you can use the separate file-expansion and word-completion
2347 modules in multiple threads, see the corresponding man pages for details).
2348 However due to the use of POSIX reentrant functions for looking up home
2349 directories, it is safe to use this module from a single thread of a
2350 multi-threaded program, provided that your other threads do not use any
2351 \fBtermcap\fR or \fBterminfo\fR functions.
2352 .SH ATTRIBUTES
2353 See \fBattributes\fR(5) for descriptions of the following attributes:
2354 .sp
2355 
2356 .sp
2357 .TS
2358 box;
2359 c | c
2360 l | l .
2361 ATTRIBUTE TYPE  ATTRIBUTE VALUE
2362 _
2363 Interface Stability     Committed
2364 _
2365 MT-Level        MT-Safe
2366 .TE
2367 
2368 .SH SEE ALSO
2369 \fBcpl_complete_word\fR(3TECLA), \fBef_expand_file\fR(3TECLA),
2370 \fBgl_io_mode\fR(3TECLA), \fBlibtecla\fR(3LIB), \fBpca_lookup_file\fR(3TECLA),
2371 \fBattributes\fR(5), \fBtecla\fR(5)