acassis commented on code in PR #3657:
URL: https://github.com/apache/nuttx-apps/pull/3657#discussion_r3644991441
##########
system/readline/readline_common.c:
##########
@@ -359,15 +389,292 @@ static void tab_completion(FAR struct rl_common_s *vtbl,
char *buf,
* if any
*/
+ /* Don't remove extra characters after the completed word,
+ * if any
+ */
+
if (len < name_len)
{
*nch = name_len;
}
+
+ /* Whether or not the common prefix grew, the prompt and
+ * buffer were just reprinted from scratch above, so the
+ * terminal's cursor is now at the end of the line either
+ * way.
+ */
+
+ return true;
+ }
+ }
+
+ return false;
+}
+#endif
+
+#ifdef CONFIG_READLINE_EDIT_EMACS_REVERSE_SEARCH
+/****************************************************************************
+ * Name: isearch_find
+ *
+ * Description:
+ * Used by Ctrl+R (reverse incremental search). Search backward
+ * through the command history, starting just before 'startoffset',
+ * for the most recent entry containing 'search' as a substring (using
+ * the same head/offset addressing as the up/down arrow history
+ * recall code above). If a match is found, it is copied into 'buf'
+ * (updating '*nch'), and its offset is returned via '*foundoffset' so
+ * that a subsequent call can continue the search further back in
+ * history. If no match is found, 'buf'/'*nch' are left unmodified.
+ *
+ * Returned Value:
+ * True if a match was found, false otherwise.
+ *
+ ****************************************************************************/
+
+static bool isearch_find(FAR const char *search, int searchlen,
+ int startoffset, FAR int *foundoffset,
+ FAR char *buf, int buflen, FAR int *nch)
+{
+ int minoffset;
+ int offset;
+ int idx;
+ int len;
+ int i;
+ int j;
+ bool matched;
+
+ if (searchlen == 0 || g_cmdhist.len == 0)
+ {
+ return false;
+ }
+
+ minoffset = -(g_cmdhist.len - 1);
+
+ for (offset = startoffset - 1; offset >= minoffset; offset--)
+ {
+ idx = g_cmdhist.head + offset;
+
+ if (idx < 0)
+ {
+ idx += RL_CMDHIST_LEN;
+ }
+ else if (idx >= RL_CMDHIST_LEN)
+ {
+ idx -= RL_CMDHIST_LEN;
+ }
+
+ len = strlen(g_cmdhist.buf[idx]);
+
+ /* Does this history entry contain 'search' anywhere? 'search'
+ * is a raw character buffer that is never null-terminated (the
+ * caller only tracks its length in 'searchlen'), so this cannot
+ * use strstr() -- do a plain bounded substring search instead.
+ */
+
+ matched = false;
+
+ for (i = 0; i + searchlen <= len; i++)
+ {
+ for (j = 0; j < searchlen; j++)
+ {
+ if (g_cmdhist.buf[idx][i + j] != search[j])
+ {
+ break;
+ }
+ }
+
+ if (j == searchlen)
+ {
+ matched = true;
+ break;
+ }
+ }
+
+ if (!matched)
+ {
+ continue;
+ }
+
+ if (len > buflen - 1)
+ {
+ len = buflen - 1;
+ }
+
+ for (i = 0; i < len; i++)
+ {
+ buf[i] = g_cmdhist.buf[idx][i];
Review Comment:
let's keep this way to keep to follow the original code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]