Hi list,
I'd know which is the expected behavior when rl_get_previous_history is
called and we reach the oldest element in the history list.

I'm testing the call on readline 8.0 built using Yocto 3.0 (zeus)
recipe with aarch64 target.

If I ask the previous history item and I'm already on the oldest one, a
blank line is showed. From that point on, if I ask for the next item, I
jump to the second in list skipping the oldest. This seems to be due to
the fact that hystory offset starts from 0 (oldest item).

Is this behavior correct or am I doing something wrong with my code?

With the following patch (which applies on 8.0 code) I was able to
avoid that behavior.

Thanks in advance for any comment,
Daniele.

>From f611ccba3c6f29a19fe5ffca260a2eae139c945e Mon Sep 17 00:00:00 2001
From: Daniele Dario <d.dari...@gmail.com>
Date: Wed, 2 Nov 2022 09:34:08 +0100
Subject: [PATCH] fix bizarre history behavior

If we ask the previous history item and we are already on the oldest
one,
a blank line is showed. From that point, if we ask for the next item,
we
jump to the second in list skipping the oldest. This is due to the fact
that hystory offset starts from 0 (oldest item).

To avoid it, stop getting previous item when we're on the oldest one.

Signed-off-by: Daniele Dario <d.dari...@gmail.com>
---
 misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/misc.c b/misc.c
index 64b1457..86b643e 100644
--- a/misc.c
+++ b/misc.c
@@ -580,7 +580,7 @@ rl_get_previous_history (int count, int key)
   if (count < 0)
     return (rl_get_next_history (-count, key));
 
-  if (count == 0 || history_list () == 0)
+  if (count == 0 || where_history () == 0)
     return 0;
 
   /* either not saved by rl_newline or at end of line, so set
appropriately. */
-- 
2.38.1

Reply via email to