1 /* $OpenBSD: prompt.c,v 1.13 2016/04/11 21:17:29 schwarze Exp $ */
2 /* $NetBSD: prompt.c,v 1.25 2016/04/11 18:56:31 christos Exp $ */
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Christos Zoulas of Cornell University.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * prompt.c: Prompt printing functions
44 static wchar_t *prompt_default(EditLine
*);
45 static wchar_t *prompt_default_r(EditLine
*);
48 * Just a default prompt, in case the user did not provide one
52 prompt_default(EditLine
*el
__attribute__((__unused__
)))
54 static wchar_t a
[3] = L
"? ";
60 /* prompt_default_r():
61 * Just a default rprompt, in case the user did not provide one
65 prompt_default_r(EditLine
*el
__attribute__((__unused__
)))
67 static wchar_t a
[1] = L
"";
74 * Print the prompt and update the prompt position.
77 prompt_print(EditLine
*el
, int op
)
86 elp
= &el
->el_rprompt
;
89 p
= (*elp
->p_func
)(el
);
91 p
= ct_decode_string((char *)(void *)(*elp
->p_func
)(el
),
95 if (elp
->p_ignore
== *p
) {
100 terminal__putc(el
, *p
);
105 elp
->p_pos
.v
= el
->el_refresh
.r_cursor
.v
;
106 elp
->p_pos
.h
= el
->el_refresh
.r_cursor
.h
;
111 * Initialize the prompt stuff
114 prompt_init(EditLine
*el
)
117 el
->el_prompt
.p_func
= prompt_default
;
118 el
->el_prompt
.p_pos
.v
= 0;
119 el
->el_prompt
.p_pos
.h
= 0;
120 el
->el_prompt
.p_ignore
= '\0';
121 el
->el_rprompt
.p_func
= prompt_default_r
;
122 el
->el_rprompt
.p_pos
.v
= 0;
123 el
->el_rprompt
.p_pos
.h
= 0;
124 el
->el_rprompt
.p_ignore
= '\0';
130 * Clean up the prompt stuff
134 prompt_end(EditLine
*el
__attribute__((__unused__
)))
140 * Install a prompt printing function
143 prompt_set(EditLine
*el
, el_pfunc_t prf
, wchar_t c
, int op
, int wide
)
147 if (op
== EL_PROMPT
|| op
== EL_PROMPT_ESC
)
153 if (op
== EL_PROMPT
|| op
== EL_PROMPT_ESC
)
154 p
->p_func
= prompt_default
;
156 p
->p_func
= prompt_default_r
;
172 * Retrieve the prompt printing function
175 prompt_get(EditLine
*el
, el_pfunc_t
*prf
, wchar_t *c
, int op
)