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