PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key

This commit is contained in:
christos 2022-02-08 15:05:10 +00:00
parent ae43ee510b
commit 001f54a461
4 changed files with 61 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: chared.c,v 1.60 2022/01/11 18:30:15 christos Exp $ */
/* $NetBSD: chared.c,v 1.61 2022/02/08 15:05:10 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.60 2022/01/11 18:30:15 christos Exp $");
__RCSID("$NetBSD: chared.c,v 1.61 2022/02/08 15:05:10 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -624,6 +624,40 @@ el_deletestr(EditLine *el, int n)
el->el_line.cursor = el->el_line.buffer;
}
/* el_deletestr1():
* Delete characters between starn and end
*/
int
el_deletestr1(EditLine *el, int start, int end)
{
size_t line_lenght, len;
wchar_t * p1, * p2;
if (end <= start)
return 0;
line_lenght = (size_t) (el->el_line.lastchar - el->el_line.buffer);
if (start >= (int) line_lenght || end >= (int) line_lenght)
return 0;
len = (size_t) (end - start);
if (len > line_lenght - (size_t) end)
len = line_lenght - (size_t) end;
p1 = el->el_line.buffer + start;
p2 = el->el_line.buffer + end;
for (size_t i = 0; i < len; i++){
*p1++ = *p2++;
el->el_line.lastchar--;
}
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
return end - start;
}
/* el_wreplacestr():
* Replace the contents of the line with the provided string
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: histedit.h,v 1.59 2022/01/11 18:30:15 christos Exp $ */
/* $NetBSD: histedit.h,v 1.60 2022/02/08 15:05:10 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -180,7 +180,7 @@ const LineInfo *el_line(EditLine *);
int el_insertstr(EditLine *, const char *);
void el_deletestr(EditLine *, int);
int el_replacestr(EditLine *el, const char *str);
int el_deletestr1(EditLine *el, int start, int end);
/*
* ==== History ====

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.171 2022/01/31 14:44:49 christos Exp $ */
/* $NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 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.171 2022/01/31 14:44:49 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -2339,6 +2339,16 @@ rl_replace_line(const char * text, int clear_undo __attribute__((__unused__)))
el_replacestr(e, text);
}
int
rl_delete_text(int start, int end)
{
if (h == NULL || e == NULL)
rl_initialize();
return el_deletestr1(e, start, end);
}
void
rl_get_screen_size(int *rows, int *cols)
{
@ -2510,6 +2520,14 @@ rl_bind_key_in_map(int key __attribute__((__unused__)),
return 0;
}
int
rl_set_key(const char *keyseq __attribute__((__unused__)),
rl_command_func_t *function __attribute__((__unused__)),
Keymap k __attribute__((__unused__)))
{
return 0;
}
/* unsupported, but needed by python */
void
rl_cleanup_after_signal(void)

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.h,v 1.51 2022/01/31 14:44:49 christos Exp $ */
/* $NetBSD: readline.h,v 1.52 2022/02/08 15:05:10 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -236,6 +236,7 @@ int rl_crlf(void);
int rl_ding(void);
char *rl_copy_text(int, int);
void rl_replace_line(const char *, int);
int rl_delete_text(int, int);
void rl_message(const char *format, ...)
__attribute__((__format__(__printf__, 1, 2)));
void rl_save_prompt(void);
@ -250,6 +251,7 @@ void rl_set_keymap(Keymap);
Keymap rl_make_bare_keymap(void);
int rl_generic_bind(int, const char *, const char *, Keymap);
int rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
int rl_set_key(const char *, rl_command_func_t *, Keymap);
void rl_cleanup_after_signal(void);
void rl_free_line_state(void);
int rl_set_keyboard_input_timeout(int);