1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #if !defined(lint) && !defined(SCCSID) 12 static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 06/04/93"; 13 #endif /* not lint && not SCCSID */ 14 15 /* 16 * prompt.c: Prompt printing functions 17 */ 18 #include "sys.h" 19 #include <stdio.h> 20 #include "el.h" 21 22 private char *prompt_default __P((EditLine *)); 23 24 /* prompt_default(): 25 * Just a default prompt, in case the user did not provide one 26 */ 27 private char * 28 /*ARGSUSED*/ 29 prompt_default(el) 30 EditLine *el; 31 { 32 static char a[3] = { '?', ' ', '\0' }; 33 return a; 34 } 35 36 37 /* prompt_print(): 38 * Print the prompt and update the prompt position. 39 * We use an array of integers in case we want to pass 40 * literal escape sequences in the prompt and we want a 41 * bit to flag them 42 */ 43 protected void 44 prompt_print(el) 45 EditLine *el; 46 { 47 char *p = (*el->el_prompt.p_func)(el); 48 while (*p) 49 re_putc(el, *p++); 50 51 el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v; 52 el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h; 53 54 } /* end prompt_print */ 55 56 57 /* prompt_init(): 58 * Initialize the prompt stuff 59 */ 60 protected int 61 prompt_init(el) 62 EditLine *el; 63 { 64 el->el_prompt.p_func = prompt_default; 65 el->el_prompt.p_pos.v = 0; 66 el->el_prompt.p_pos.h = 0; 67 return 0; 68 } /* end prompt_init */ 69 70 71 /* prompt_end(): 72 * Clean up the prompt stuff 73 */ 74 protected void 75 /*ARGSUSED*/ 76 prompt_end(el) 77 EditLine *el; 78 { 79 } /* end prompt_end */ 80 81 82 /* prompt_set(): 83 * Install a prompt printing function 84 */ 85 protected int 86 prompt_set(el, prf) 87 EditLine *el; 88 el_pfunc_t prf; 89 { 90 if (prf == NULL) 91 el->el_prompt.p_func = prompt_default; 92 else 93 el->el_prompt.p_func = prf; 94 el->el_prompt.p_pos.v = 0; 95 el->el_prompt.p_pos.h = 0; 96 return 0; 97 } /* end prompt_set */ 98