diff --git a/lib/libedit/TEST/tc1.c b/lib/libedit/TEST/tc1.c index ee0b1a940a7f..88226b07dd96 100644 --- a/lib/libedit/TEST/tc1.c +++ b/lib/libedit/TEST/tc1.c @@ -1,4 +1,4 @@ -/* $NetBSD: tc1.c,v 1.1 2006/08/31 20:20:38 rpaulo Exp $ */ +/* $NetBSD: tc1.c,v 1.2 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ #if 0 static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tc1.c,v 1.1 2006/08/31 20:20:38 rpaulo Exp $"); +__RCSID("$NetBSD: tc1.c,v 1.2 2009/03/31 17:38:27 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -71,7 +71,7 @@ static void sig(int); static char * prompt(EditLine *el) { - static char a[] = "Edit$ "; + static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 "; static char b[] = "Edit> "; return (continuation ? b : a); @@ -146,7 +146,7 @@ main(int argc, char *argv[]) el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */ el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */ - el_set(el, EL_PROMPT, prompt); /* Set the prompt function */ + el_set(el, EL_PROMPT, prompt, '\1');/* Set the prompt function */ /* Tell editline to use this history interface */ el_set(el, EL_HIST, history, hist); diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3 index 13da45a18361..a32460577474 100644 --- a/lib/libedit/editline.3 +++ b/lib/libedit/editline.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: editline.3,v 1.64 2009/03/10 22:55:14 wiz Exp $ +.\" $NetBSD: editline.3,v 1.65 2009/03/31 17:38:27 christos Exp $ .\" .\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -26,7 +26,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd March 10, 2009 +.Dd March 31, 2009 .Dt EDITLINE 3 .Os .Sh NAME @@ -218,10 +218,22 @@ The following values for .Fa op are supported, along with the required argument list: .Bl -tag -width 4n -.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" +.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)", Fa "char c" Define prompt printing function as .Fa f , which is to return a string that contains the prompt. +The +.Fa c +argument indicates the start/stop literal prompt character. +.Pp +If a start/stop literal character is found in the prompt, itself +is not printed, but characters after it are printed directly to the +terminal without affecting the state of the current line. +A subsequent second start/stop literal character ends this behavior. +This is typically used to embed literal escape sequences that change the +color/style of the terminal in the prompt. +.Dv 0 +unsets it. .It Dv EL_REFRESH Re-display the current line on the next terminal line. .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" @@ -437,10 +449,22 @@ The following values for are supported, along with actual type of .Fa result : .Bl -tag -width 4n -.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" -Return a pointer to the function that displays the prompt. -.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" -Return a pointer to the function that displays the rightside prompt. +.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c" +Return a pointer to the function that displays the prompt in +.Fa f . +If +.Fa c +is not +.Dv NULL , +return the start/stop literal prompt character in it. +.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c" +Return a pointer to the function that displays the prompt in +.Fa f . +If +.Fa c +is not +.Dv NULL , +return the start/stop literal prompt character in it. .It Dv EL_EDITOR , Fa "const char *" Return the name of the editor, which will be one of .Dq emacs diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 3bec9cf8149a..becc4c8f97c0 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.50 2009/02/21 00:05:23 christos Exp $ */ +/* $NetBSD: el.c,v 1.51 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; #else -__RCSID("$NetBSD: el.c,v 1.50 2009/02/21 00:05:23 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.51 2009/03/31 17:38:27 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -155,9 +155,13 @@ el_set(EditLine *el, int op, ...) switch (op) { case EL_PROMPT: - case EL_RPROMPT: - rv = prompt_set(el, va_arg(ap, el_pfunc_t), op); + case EL_RPROMPT: { + el_pfunc_t p = va_arg(ap, el_pfunc_t); + char c = va_arg(ap, int); + + rv = prompt_set(el, p, c, op); break; + } case EL_TERMINAL: rv = term_set(el, va_arg(ap, char *)); @@ -340,9 +344,13 @@ el_get(EditLine *el, int op, ...) switch (op) { case EL_PROMPT: - case EL_RPROMPT: - rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op); + case EL_RPROMPT: { + el_pfunc_t *p = va_arg(ap, el_pfunc_t *); + char *c = va_arg(ap, char *); + + rv = prompt_get(el, p, c, op); break; + } case EL_EDITOR: rv = map_get_editor(el, va_arg(ap, const char **)); diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index bcf3c7380443..8e6edc508f12 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.38 2009/02/21 00:05:23 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.39 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -115,7 +115,7 @@ unsigned char _el_fn_complete(EditLine *, int); /* * el_set/el_get parameters */ -#define EL_PROMPT 0 /* , el_pfunc_t); */ +#define EL_PROMPT 0 /* , el_pfunc_t, char); */ #define EL_TERMINAL 1 /* , const char *); */ #define EL_EDITOR 2 /* , const char *); */ #define EL_SIGNAL 3 /* , int); */ @@ -128,7 +128,7 @@ unsigned char _el_fn_complete(EditLine *, int); /* , el_func_t); */ #define EL_HIST 10 /* , hist_fun_t, const char *); */ #define EL_EDITMODE 11 /* , int); */ -#define EL_RPROMPT 12 /* , el_pfunc_t); */ +#define EL_RPROMPT 12 /* , el_pfunc_t, char); */ #define EL_GETCFN 13 /* , el_rfunc_t); */ #define EL_CLIENTDATA 14 /* , void *); */ #define EL_UNBUFFERED 15 /* , int); */ diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c index 5b44896084eb..3f93593c2cf6 100644 --- a/lib/libedit/prompt.c +++ b/lib/libedit/prompt.c @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.c,v 1.13 2009/02/21 00:05:23 christos Exp $ */ +/* $NetBSD: prompt.c,v 1.14 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: prompt.c,v 1.13 2009/02/21 00:05:23 christos Exp $"); +__RCSID("$NetBSD: prompt.c,v 1.14 2009/03/31 17:38:27 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -87,14 +87,23 @@ prompt_print(EditLine *el, int op) { el_prompt_t *elp; char *p; + int ignore = 0; if (op == EL_PROMPT) elp = &el->el_prompt; else elp = &el->el_rprompt; p = (elp->p_func) (el); - while (*p) - re_putc(el, *p++, 1); + while (*p) { + if (elp->p_ignore == *p) { + ignore = !ignore; + continue; + } + if (ignore) + term__putc(el, *p++); + else + re_putc(el, *p++, 1); + } elp->p_pos.v = el->el_refresh.r_cursor.v; elp->p_pos.h = el->el_refresh.r_cursor.h; @@ -111,10 +120,12 @@ prompt_init(EditLine *el) el->el_prompt.p_func = prompt_default; el->el_prompt.p_pos.v = 0; el->el_prompt.p_pos.h = 0; + el->el_prompt.p_ignore = '\0'; el->el_rprompt.p_func = prompt_default_r; el->el_rprompt.p_pos.v = 0; el->el_rprompt.p_pos.h = 0; - return (0); + el->el_rprompt.p_ignore = '\0'; + return 0; } @@ -132,7 +143,7 @@ prompt_end(EditLine *el __attribute__((__unused__))) * Install a prompt printing function */ protected int -prompt_set(EditLine *el, el_pfunc_t prf, int op) +prompt_set(EditLine *el, el_pfunc_t prf, char c, int op) { el_prompt_t *p; @@ -140,6 +151,7 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op) p = &el->el_prompt; else p = &el->el_rprompt; + if (prf == NULL) { if (op == EL_PROMPT) p->p_func = prompt_default; @@ -147,9 +159,13 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op) p->p_func = prompt_default_r; } else p->p_func = prf; + + p->p_ignore = c; + p->p_pos.v = 0; p->p_pos.h = 0; - return (0); + + return 0; } @@ -157,14 +173,22 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op) * Retrieve the prompt printing function */ protected int -prompt_get(EditLine *el, el_pfunc_t *prf, int op) +prompt_get(EditLine *el, el_pfunc_t *prf, char *c, int op) { + el_prompt_t *p; if (prf == NULL) - return (-1); + return -1; + if (op == EL_PROMPT) - *prf = el->el_prompt.p_func; + p = &el->el_prompt; else - *prf = el->el_rprompt.p_func; - return (0); + p = &el->el_rprompt; + + *prf = el->el_rprompt.p_func; + + if (c) + *c = p->p_ignore; + + return 0; } diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h index ad331e4fbe9b..a70401c29982 100644 --- a/lib/libedit/prompt.h +++ b/lib/libedit/prompt.h @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.h,v 1.8 2009/02/21 00:05:23 christos Exp $ */ +/* $NetBSD: prompt.h,v 1.9 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -45,13 +45,14 @@ typedef char * (*el_pfunc_t)(EditLine*); typedef struct el_prompt_t { - el_pfunc_t p_func; /* Function to return the prompt */ - coord_t p_pos; /* position in the line after prompt */ + el_pfunc_t p_func; /* Function to return the prompt */ + coord_t p_pos; /* position in the line after prompt */ + char p_ignore; /* character to start/end literal */ } el_prompt_t; protected void prompt_print(EditLine *, int); -protected int prompt_set(EditLine *, el_pfunc_t, int); -protected int prompt_get(EditLine *, el_pfunc_t *, int); +protected int prompt_set(EditLine *, el_pfunc_t, char, int); +protected int prompt_get(EditLine *, el_pfunc_t *, char *, int); protected int prompt_init(EditLine *); protected void prompt_end(EditLine *); diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c index 64536de70f66..38265d05edec 100644 --- a/lib/libedit/refresh.c +++ b/lib/libedit/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.29 2009/02/15 21:55:23 christos Exp $ */ +/* $NetBSD: refresh.c,v 1.30 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: refresh.c,v 1.29 2009/02/15 21:55:23 christos Exp $"); +__RCSID("$NetBSD: refresh.c,v 1.30 2009/03/31 17:38:27 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -300,7 +300,7 @@ re_refresh(EditLine *el) term_move_to_char(el, 0); term_clear_EOL(el, (int) strlen(el->el_display[i])); #ifdef DEBUG_REFRESH - term_overwrite(el, "C\b", 2); + term_overwrite(el, "C\b", (size_t)2); #endif /* DEBUG_REFRESH */ el->el_display[i][0] = '\0'; } @@ -477,6 +477,7 @@ re_update_line(EditLine *el, char *old, char *new, int i) char *ofd, *ols, *oe, *nfd, *nls, *ne; char *osb, *ose, *nsb, *nse; int fx, sx; + size_t len; /* * find first diff @@ -761,14 +762,14 @@ re_update_line(EditLine *el, char *old, char *new, int i) * write (nsb-nfd) - fx chars of new starting at * (nfd + fx) */ - term_overwrite(el, (nfd + fx), - (int)((nsb - nfd) - fx)); - re__strncopy(ofd + fx, nfd + fx, - (size_t) ((nsb - nfd) - fx)); + len = (size_t) ((nsb - nfd) - fx); + term_overwrite(el, (nfd + fx), len); + re__strncopy(ofd + fx, nfd + fx, len); } else { ELRE_DEBUG(1, (__F, "without anything to save\r\n")); - term_overwrite(el, nfd, (int)(nsb - nfd)); - re__strncopy(ofd, nfd, (size_t) (nsb - nfd)); + len = (size_t)(nsb - nfd); + term_overwrite(el, nfd, len); + re__strncopy(ofd, nfd, len); /* * Done */ @@ -800,8 +801,9 @@ re_update_line(EditLine *el, char *old, char *new, int i) /* * write (nsb-nfd) chars of new starting at nfd */ - term_overwrite(el, nfd, (int)(nsb - nfd)); - re__strncopy(ofd, nfd, (size_t) (nsb - nfd)); + len = (size_t) (nsb - nfd); + term_overwrite(el, nfd, len); + re__strncopy(ofd, nfd, len); } else { ELRE_DEBUG(1, (__F, @@ -809,7 +811,7 @@ re_update_line(EditLine *el, char *old, char *new, int i) /* * write (nsb-nfd) chars of new starting at nfd */ - term_overwrite(el, nfd, (int)(nsb - nfd)); + term_overwrite(el, nfd, (size_t)(nsb - nfd)); re_clear_eol(el, fx, sx, (int)((oe - old) - (ne - new))); /* @@ -847,11 +849,11 @@ re_update_line(EditLine *el, char *old, char *new, int i) /* * write (nls-nse) chars of new starting at nse */ - term_overwrite(el, nse, (int)(nls - nse)); + term_overwrite(el, nse, (size_t)(nls - nse)); } else { ELRE_DEBUG(1, (__F, "but with nothing left to save\r\n")); - term_overwrite(el, nse, (int)(nls - nse)); + term_overwrite(el, nse, (size_t)(nls - nse)); re_clear_eol(el, fx, sx, (int)((oe - old) - (ne - new))); } @@ -889,14 +891,14 @@ re_update_line(EditLine *el, char *old, char *new, int i) * write (nsb-nfd) - fx chars of new starting at * (nfd + fx) */ - term_overwrite(el, (nfd + fx), - (int)((nsb - nfd) - fx)); - re__strncopy(ofd + fx, nfd + fx, - (size_t) ((nsb - nfd) - fx)); + len = (size_t) ((nsb - nfd) - fx); + term_overwrite(el, (nfd + fx), len); + re__strncopy(ofd + fx, nfd + fx, len); } else { ELRE_DEBUG(1, (__F, "without anything to save\r\n")); - term_overwrite(el, nfd, (int)(nsb - nfd)); - re__strncopy(ofd, nfd, (size_t) (nsb - nfd)); + len = (size_t) (nsb - nfd); + term_overwrite(el, nfd, len); + re__strncopy(ofd, nfd, len); } } /* @@ -919,10 +921,10 @@ re_update_line(EditLine *el, char *old, char *new, int i) * (nse + sx) */ term_overwrite(el, (nse + sx), - (int)((nls - nse) - sx)); + (size_t)((nls - nse) - sx)); } else { ELRE_DEBUG(1, (__F, "without anything to save\r\n")); - term_overwrite(el, nse, (int)(nls - nse)); + term_overwrite(el, nse, (size_t)(nls - nse)); /* * No need to do a clear-to-end here because we were diff --git a/lib/libedit/term.c b/lib/libedit/term.c index 9a19a070ffc7..06a4941fb1c0 100644 --- a/lib/libedit/term.c +++ b/lib/libedit/term.c @@ -1,4 +1,4 @@ -/* $NetBSD: term.c,v 1.50 2009/02/15 21:55:23 christos Exp $ */ +/* $NetBSD: term.c,v 1.51 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: term.c,v 1.50 2009/02/15 21:55:23 christos Exp $"); +__RCSID("$NetBSD: term.c,v 1.51 2009/03/31 17:38:27 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -559,7 +559,7 @@ term_move_to_line(EditLine *el, int where) term_move_to_char(el, el->el_term.t_size.h - 1); term_overwrite(el, &el->el_display[el->el_cursor.v][el->el_cursor.h], - 1); + (size_t)1); /* updates Cursor */ del--; } else { @@ -646,7 +646,7 @@ mc_again: */ term_overwrite(el, &el->el_display[el->el_cursor.v][el->el_cursor.h], - where - el->el_cursor.h); + (size_t)(where - el->el_cursor.h)); } } else { /* del < 0 := moving backward */ @@ -680,10 +680,10 @@ mc_again: * Overstrike num characters */ protected void -term_overwrite(EditLine *el, const char *cp, int n) +term_overwrite(EditLine *el, const char *cp, size_t n) { - if (n <= 0) - return; /* catch bugs */ + if (n == 0) + return; if (n > el->el_term.t_size.h) { #ifdef DEBUG_SCREEN @@ -692,6 +692,7 @@ term_overwrite(EditLine *el, const char *cp, int n) #endif /* DEBUG_SCREEN */ return; } + do { term__putc(el, *cp++); el->el_cursor.h++; @@ -784,7 +785,7 @@ term_insertwrite(EditLine *el, char *cp, int num) if ((num > 1) || !GoodStr(T_ic)) { /* if ic would be more expensive */ term_tputs(el, tgoto(Str(T_IC), num, num), num); - term_overwrite(el, cp, num); + term_overwrite(el, cp, (size_t)num); /* this updates el_cursor.h */ return; } @@ -1289,9 +1290,9 @@ protected void term_writec(EditLine *el, int c) { char buf[8]; - int cnt = key__decode_char(buf, sizeof(buf), 0, c); + size_t cnt = key__decode_char(buf, sizeof(buf), 0, c); buf[cnt] = '\0'; - term_overwrite(el, buf, cnt); + term_overwrite(el, buf, (size_t)cnt); term__flush(el); } diff --git a/lib/libedit/term.h b/lib/libedit/term.h index 0e7ddd555f4d..3ab1f6fa9fbd 100644 --- a/lib/libedit/term.h +++ b/lib/libedit/term.h @@ -1,4 +1,4 @@ -/* $NetBSD: term.h,v 1.19 2008/09/10 15:45:37 christos Exp $ */ +/* $NetBSD: term.h,v 1.20 2009/03/31 17:38:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -84,7 +84,7 @@ typedef struct { protected void term_move_to_line(EditLine *, int); protected void term_move_to_char(EditLine *, int); protected void term_clear_EOL(EditLine *, int); -protected void term_overwrite(EditLine *, const char *, int); +protected void term_overwrite(EditLine *, const char *, size_t); protected void term_insertwrite(EditLine *, char *, int); protected void term_deletechars(EditLine *, int); protected void term_clear_screen(EditLine *);