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