NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/56618: Improve libedit compatibility with readline
>Number: 56618
>Category: lib
>Synopsis: Improve libedit compatibility with readline
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Jan 11 17:35:00 +0000 2022
>Originator: Walter Lozano
>Release:
>Organization:
Collabora
>Environment:
>Description:
In order to improve libedit compatibility some additional symbols should be implemented
rl_copy_text
rl_save_prompt
rl_replace_line
rl_restore_prompt
rl_message
rl_erase_empty_line
rl_on_new_line
>How-To-Repeat:
>Fix:
I have prepared the following patch in order to improve the support. Please let me know if I should submit the proposed changes in other way, I did my best to follow the guidelines in the website.
Index: chared.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/chared.c,v
retrieving revision 1.59
diff -u -r1.59 chared.c
--- chared.c 23 Jul 2019 10:18:52 -0000 1.59
+++ chared.c 11 Jan 2022 17:24:18 -0000
@@ -624,6 +624,30 @@
el->el_line.cursor = el->el_line.buffer;
}
+int
+el_wreplacestr(EditLine *el, const wchar_t *s)
+{
+ size_t len;
+ wchar_t * p;
+
+ if (s == NULL || (len = wcslen(s)) == 0)
+ return -1;
+ if (el->el_line.buffer + len >= el->el_line.limit) {
+ if (!ch_enlargebufs(el, len))
+ return -1;
+ }
+
+ p = el->el_line.buffer;
+ for (size_t i=0; i<len; i++)
+ *p++ = *s++;
+
+ el->el_line.buffer[len] = 0;
+ el->el_line.lastchar = el->el_line.buffer + len;
+ if (el->el_line.cursor > el->el_line.lastchar)
+ el->el_line.cursor = el->el_line.lastchar;
+
+ return 0;
+}
/* el_cursor():
* Move the cursor to the left or the right of the current position
*/
Index: eln.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/eln.c,v
retrieving revision 1.36
diff -u -r1.36 eln.c
--- eln.c 15 Aug 2021 10:08:41 -0000 1.36
+++ eln.c 11 Jan 2022 17:24:18 -0000
@@ -386,3 +386,9 @@
{
return el_winsertstr(el, ct_decode_string(str, &el->el_lgcyconv));
}
+
+int
+el_replacestr(EditLine *el, const char *str)
+{
+ return el_wreplacestr(el, ct_decode_string(str, &el->el_lgcyconv));
+}
Index: histedit.h
===================================================================
RCS file: /cvsroot/src/lib/libedit/histedit.h,v
retrieving revision 1.58
diff -u -r1.58 histedit.h
--- histedit.h 15 Aug 2021 10:08:41 -0000 1.58
+++ histedit.h 11 Jan 2022 17:24:18 -0000
@@ -179,6 +179,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);
/*
@@ -278,6 +279,7 @@
const LineInfoW *el_wline(EditLine *);
int el_winsertstr(EditLine *, const wchar_t *);
#define el_wdeletestr el_deletestr
+int el_wreplacestr(EditLine *, const wchar_t *);
/*
* ==== History ====
Index: readline.c
===================================================================
RCS file: /cvsroot/src/lib/libedit/readline.c,v
retrieving revision 1.168
diff -u -r1.168 readline.c
--- readline.c 10 Sep 2021 18:51:36 -0000 1.168
+++ readline.c 11 Jan 2022 17:24:18 -0000
@@ -43,6 +43,7 @@
#include <limits.h>
#include <pwd.h>
#include <setjmp.h>
+#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -136,11 +137,13 @@
int _rl_echoing_p;
int history_max_entries;
char *rl_display_prompt;
+int rl_erase_empty_line;
/*
* The current prompt string.
*/
char *rl_prompt = NULL;
+char *rl_prompt_saved = NULL;
/*
* This is set to character indicating type of completion being done by
* rl_complete_internal(); this is available for application completion
@@ -278,6 +281,21 @@
return 0;
}
+void
+rl_save_prompt(void)
+{
+ rl_prompt_saved = strdup(rl_prompt);
+}
+
+void
+rl_restore_prompt(void)
+{
+ if (!rl_prompt_saved)
+ return;
+ rl_prompt = rl_prompt_saved;
+ rl_prompt_saved = NULL;
+}
+
/*
* initialize rl compat stuff
*/
@@ -2281,6 +2299,42 @@
rl_line_buffer[rl_end] = '\0';
}
+char *
+rl_copy_text(int from, int to)
+{
+ const LineInfo *li = el_line(e);
+ int len;
+ char * out;
+
+ if (from > to)
+ return NULL;
+
+ if (li->buffer + from > li->lastchar)
+ from = (int)(li->lastchar - li->buffer);
+
+ if (li->buffer + to > li->lastchar)
+ to = (int)(li->lastchar - li->buffer);
+
+ len = to - from;
+ out = (char *) el_malloc((size_t)len + 1);
+ strncpy(out, li->buffer + from , (size_t)len);
+ out[len] = 0;
+
+ return out;
+}
+
+void
+rl_replace_line (const char * text, __attribute__((unused)) int clear_undo)
+{
+ if (!text || *text == 0)
+ return;
+
+ if (h == NULL || e == NULL)
+ rl_initialize();
+
+ el_replacestr(e, text);
+}
+
void
rl_get_screen_size(int *rows, int *cols)
{
@@ -2290,6 +2344,22 @@
el_get(e, EL_GETTC, "co", cols);
}
+#define MAX_MESSAGE 160
+void
+rl_message (const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+
+ char msg[160];
+
+ vsnprintf (msg, sizeof(msg), format, args);
+
+ rl_set_prompt(msg);
+ rl_redisplay();
+ //rl_replace_line(msg, 0);
+}
+
void
rl_set_screen_size(int rows, int cols)
{
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.47
diff -u -r1.47 readline.h
--- readline/readline.h 21 Aug 2021 12:34:59 -0000 1.47
+++ readline/readline.h 11 Jan 2022 17:24:18 -0000
@@ -153,6 +153,7 @@
extern int _rl_echoing_p;
extern int history_max_entries;
extern char *rl_display_prompt;
+extern int rl_erase_empty_line;
/* supported functions */
char *readline(const char *);
@@ -226,6 +227,11 @@
void rl_echo_signal_char(int);
int rl_crlf(void);
int rl_ding(void);
+char *rl_copy_text(int, int);
+void rl_replace_line (const char *, int);
+void rl_message (const char *format, ...);
+void rl_save_prompt(void);
+void rl_restore_prompt(void);
/*
* The following are not implemented
Home |
Main Index |
Thread Index |
Old Index