NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/56693: Add support for rl_delete_text and rl_set_key



>Number:         56693
>Category:       lib
>Synopsis:       Add support for rl_delete_text and rl_set_key
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 05 23:55:00 +0000 2022
>Originator:     Walter Lozano
>Release:        
>Organization:
Collabora
>Environment:
>Description:
The current implementation of libedit does not support rl_delete_text and rl_set_key.
>How-To-Repeat:

>Fix:
Here is a proposed implementation for rl_delete_text and rl_set_key.

cvs diff: Diffing .
Index: chared.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/chared.c,v
retrieving revision 1.60
diff -u -r1.60 chared.c
--- chared.c	11 Jan 2022 18:30:15 -0000	1.60
+++ chared.c	5 Feb 2022 23:50:49 -0000
@@ -624,6 +624,40 @@
 		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
  */
Index: histedit.h
===================================================================
RCS file: /cvsroot/src/lib/libedit/histedit.h,v
retrieving revision 1.59
diff -u -r1.59 histedit.h
--- histedit.h	11 Jan 2022 18:30:15 -0000	1.59
+++ histedit.h	5 Feb 2022 23:50:49 -0000
@@ -180,7 +180,7 @@
 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 ====
Index: readline.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/readline.c,v
retrieving revision 1.171
diff -u -r1.171 readline.c
--- readline.c	31 Jan 2022 14:44:49 -0000	1.171
+++ readline.c	5 Feb 2022 23:50:50 -0000
@@ -2339,6 +2339,16 @@
 	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 @@
 	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)
cvs diff: Diffing TEST
cvs diff: Diffing readline
Index: readline/readline.h
===================================================================
RCS file: /cvsroot/src/lib/libedit/readline/readline.h,v
retrieving revision 1.51
diff -u -r1.51 readline.h
--- readline/readline.h	31 Jan 2022 14:44:49 -0000	1.51
+++ readline/readline.h	5 Feb 2022 23:50:50 -0000
@@ -236,6 +236,7 @@
 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 @@
 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);



Home | Main Index | Thread Index | Old Index