setup a callback to be invoked on resize buffers so that readline can

reset rl_line_buffer which unfortunately some applications use it directly.
This commit is contained in:
christos 2010-08-28 15:44:59 +00:00
parent 179b12252e
commit 7741aae941
6 changed files with 57 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $ */
/* $NetBSD: chared.c,v 1.29 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $");
__RCSID("$NetBSD: chared.c,v 1.29 2010/08/28 15:44:59 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -489,6 +489,8 @@ ch_init(EditLine *el)
sizeof(*el->el_chared.c_kill.buf));
el->el_chared.c_kill.mark = el->el_line.buffer;
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
el->el_chared.c_resizefun = NULL;
el->el_chared.c_resizearg = NULL;
el->el_map.current = el->el_map.key;
@ -629,6 +631,8 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/* Safe to set enlarged buffer size */
el->el_line.limit = &el->el_line.buffer[newsz - EL_LEAVE];
if (el->el_chared.c_resizefun)
(*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
return 1;
}
@ -782,3 +786,11 @@ c_hpos(EditLine *el)
return (int)(el->el_line.cursor - ptr - 1);
}
}
protected int
ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
{
el->el_chared.c_resizefun = f;
el->el_chared.c_resizearg = a;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: chared.h,v 1.20 2010/04/15 00:57:33 christos Exp $ */
/* $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -103,6 +103,8 @@ typedef struct c_kill_t {
Char *mark;
} c_kill_t;
typedef void (*el_zfunc_t)(EditLine *, void *);
/*
* Note that we use both data structures because the user can bind
* commands from both editors!
@ -113,6 +115,8 @@ typedef struct el_chared_t {
c_redo_t c_redo;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
el_zfunc_t c_resizefun;
void * c_resizearg;
} el_chared_t;
@ -160,6 +164,7 @@ protected int c_hpos(EditLine *);
protected int ch_init(EditLine *);
protected void ch_reset(EditLine *, int);
protected int ch_resizefun(EditLine *, el_zfunc_t, void *);
protected int ch_enlargebufs(EditLine *, size_t);
protected void ch_end(EditLine *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.c,v 1.59 2010/04/15 00:56:40 christos Exp $ */
/* $NetBSD: el.c,v 1.60 2010/08/28 15:44:59 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.59 2010/04/15 00:56:40 christos Exp $");
__RCSID("$NetBSD: el.c,v 1.60 2010/08/28 15:44:59 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -177,6 +177,13 @@ FUN(el,set)(EditLine *el, int op, ...)
break;
}
case EL_RESIZE: {
el_zfunc_t p = va_arg(ap, el_zfunc_t);
void *arg = va_arg(ap, void *);
rv = ch_resizefun(el, p, arg);
break;
}
case EL_PROMPT_ESC:
case EL_RPROMPT_ESC: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $ */
/* $NetBSD: eln.c,v 1.8 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $");
__RCSID("$NetBSD: eln.c,v 1.8 2010/08/28 15:44:59 christos Exp $");
#endif /* not lint && not SCCSID */
#include "histedit.h"
@ -118,6 +118,13 @@ el_set(EditLine *el, int op, ...)
break;
}
case EL_RESIZE: {
el_zfunc_t p = va_arg(ap, el_zfunc_t);
void *arg = va_arg(ap, void *);
ret = ch_resizefun(el, p, arg);
break;
}
case EL_TERMINAL: /* const char * */
ret = el_wset(el, op, va_arg(ap, char *));
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $ */
/* $NetBSD: histedit.h,v 1.47 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -155,6 +155,7 @@ unsigned char _el_fn_complete(EditLine *, int);
#define EL_REFRESH 20 /* , void); set */
#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */
#define EL_BUILTIN_GETCFN (NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $ */
/* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -220,6 +220,17 @@ _getc_function(EditLine *el, char *c)
return 1;
}
static void
_resize_fun(EditLine *el, void *a)
{
const LineInfo *li;
char **ap = a;
li = el_line(el);
/* a cheesy way to get rid of const cast. */
*ap = memchr(li->buffer, *li->buffer, 1);
}
static const char _dothistory[] = "/.history";
static const char *
@ -272,7 +283,6 @@ int
rl_initialize(void)
{
TYPE(HistEvent) ev;
const LineInfo *li;
int editmode = 1;
struct termios t;
@ -306,6 +316,9 @@ rl_initialize(void)
max_input_history = INT_MAX;
el_set(e, EL_HIST, history, h);
/* Setup resize function */
el_set(e, EL_RESIZE, _resize_fun, &rl_line_buffer);
/* setup getc function if valid */
if (rl_getc_function)
el_set(e, EL_GETCFN, _getc_function);
@ -351,9 +364,7 @@ rl_initialize(void)
* Unfortunately, some applications really do use rl_point
* and rl_line_buffer directly.
*/
li = el_line(e);
/* a cheesy way to get rid of const cast. */
rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
_resize_fun(e, &rl_line_buffer);
_rl_update_pos();
if (rl_startup_hook)