154226Sbostic /*- 2*61275Sbostic * Copyright (c) 1992, 1993 3*61275Sbostic * The Regents of the University of California. All rights reserved. 454226Sbostic * 554226Sbostic * This code is derived from software contributed to Berkeley by 654226Sbostic * Christos Zoulas of Cornell University. 754226Sbostic * 854226Sbostic * %sccs.include.redist.c% 954226Sbostic */ 1054226Sbostic 1154624Schristos #if !defined(lint) && !defined(SCCSID) 12*61275Sbostic static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 06/04/93"; 1354624Schristos #endif /* not lint && not SCCSID */ 1454226Sbostic 1554226Sbostic /* 1654624Schristos * prompt.c: Prompt printing functions 1754226Sbostic */ 1854226Sbostic #include "sys.h" 1954226Sbostic #include <stdio.h> 2054226Sbostic #include "el.h" 2154226Sbostic 2254226Sbostic private char *prompt_default __P((EditLine *)); 2354226Sbostic 2454226Sbostic /* prompt_default(): 2554226Sbostic * Just a default prompt, in case the user did not provide one 2654226Sbostic */ 2754226Sbostic private char * 2854226Sbostic /*ARGSUSED*/ prompt_default(el)2954226Sbosticprompt_default(el) 3054226Sbostic EditLine *el; 3154226Sbostic { 3254226Sbostic static char a[3] = { '?', ' ', '\0' }; 3354226Sbostic return a; 3454226Sbostic } 3554226Sbostic 3654226Sbostic 3754226Sbostic /* prompt_print(): 3854226Sbostic * Print the prompt and update the prompt position. 3954226Sbostic * We use an array of integers in case we want to pass 4054226Sbostic * literal escape sequences in the prompt and we want a 4154226Sbostic * bit to flag them 4254226Sbostic */ 4354226Sbostic protected void prompt_print(el)4454226Sbosticprompt_print(el) 4554226Sbostic EditLine *el; 4654226Sbostic { 4754226Sbostic char *p = (*el->el_prompt.p_func)(el); 4854226Sbostic while (*p) 4954226Sbostic re_putc(el, *p++); 5054226Sbostic 5154226Sbostic el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v; 5254226Sbostic el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h; 5354226Sbostic 5454226Sbostic } /* end prompt_print */ 5554226Sbostic 5654226Sbostic 5754226Sbostic /* prompt_init(): 5854226Sbostic * Initialize the prompt stuff 5954226Sbostic */ 6054226Sbostic protected int prompt_init(el)6154226Sbosticprompt_init(el) 6254226Sbostic EditLine *el; 6354226Sbostic { 6454226Sbostic el->el_prompt.p_func = prompt_default; 6554226Sbostic el->el_prompt.p_pos.v = 0; 6654226Sbostic el->el_prompt.p_pos.h = 0; 6754226Sbostic return 0; 6854226Sbostic } /* end prompt_init */ 6954226Sbostic 7054226Sbostic 7154226Sbostic /* prompt_end(): 7254226Sbostic * Clean up the prompt stuff 7354226Sbostic */ 7454226Sbostic protected void 7554226Sbostic /*ARGSUSED*/ prompt_end(el)7654226Sbosticprompt_end(el) 7754226Sbostic EditLine *el; 7854226Sbostic { 7954226Sbostic } /* end prompt_end */ 8054226Sbostic 8154226Sbostic 8254226Sbostic /* prompt_set(): 8354226Sbostic * Install a prompt printing function 8454226Sbostic */ 8554226Sbostic protected int prompt_set(el,prf)8654226Sbosticprompt_set(el, prf) 8754226Sbostic EditLine *el; 8854226Sbostic el_pfunc_t prf; 8954226Sbostic { 9054226Sbostic if (prf == NULL) 9154226Sbostic el->el_prompt.p_func = prompt_default; 9254226Sbostic else 9354226Sbostic el->el_prompt.p_func = prf; 9454226Sbostic el->el_prompt.p_pos.v = 0; 9554226Sbostic el->el_prompt.p_pos.h = 0; 9654226Sbostic return 0; 9754226Sbostic } /* end prompt_set */ 98