xref: /netbsd-src/lib/libedit/prompt.c (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1 /*	$NetBSD: prompt.c,v 1.2 1997/01/11 06:48:04 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Christos Zoulas of Cornell University.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  */
38 
39 #if !defined(lint) && !defined(SCCSID)
40 #if 0
41 static char sccsid[] = "@(#)prompt.c	8.1 (Berkeley) 6/4/93";
42 #else
43 static char rcsid[] = "$NetBSD: prompt.c,v 1.2 1997/01/11 06:48:04 lukem Exp $";
44 #endif
45 #endif /* not lint && not SCCSID */
46 
47 /*
48  * prompt.c: Prompt printing functions
49  */
50 #include "sys.h"
51 #include <stdio.h>
52 #include "el.h"
53 
54 private char *prompt_default	__P((EditLine *));
55 
56 /* prompt_default():
57  *	Just a default prompt, in case the user did not provide one
58  */
59 private char *
60 /*ARGSUSED*/
61 prompt_default(el)
62     EditLine *el;
63 {
64     static char a[3] = { '?', ' ', '\0' };
65     return a;
66 }
67 
68 
69 /* prompt_print():
70  *	Print the prompt and update the prompt position.
71  *	We use an array of integers in case we want to pass
72  * 	literal escape sequences in the prompt and we want a
73  *	bit to flag them
74  */
75 protected void
76 prompt_print(el)
77     EditLine *el;
78 {
79     char *p = (*el->el_prompt.p_func)(el);
80     while (*p)
81 	re_putc(el, *p++);
82 
83     el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v;
84     el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h;
85 
86 } /* end prompt_print */
87 
88 
89 /* prompt_init():
90  *	Initialize the prompt stuff
91  */
92 protected int
93 prompt_init(el)
94     EditLine *el;
95 {
96     el->el_prompt.p_func = prompt_default;
97     el->el_prompt.p_pos.v = 0;
98     el->el_prompt.p_pos.h = 0;
99     return 0;
100 } /* end prompt_init */
101 
102 
103 /* prompt_end():
104  *	Clean up the prompt stuff
105  */
106 protected void
107 /*ARGSUSED*/
108 prompt_end(el)
109     EditLine *el;
110 {
111 } /* end prompt_end */
112 
113 
114 /* prompt_set():
115  *	Install a prompt printing function
116  */
117 protected int
118 prompt_set(el, prf)
119     EditLine *el;
120     el_pfunc_t prf;
121 {
122     if (prf == NULL)
123 	el->el_prompt.p_func = prompt_default;
124     else
125 	el->el_prompt.p_func = prf;
126     el->el_prompt.p_pos.v = 0;
127     el->el_prompt.p_pos.h = 0;
128     return 0;
129 } /* end prompt_set */
130