[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Selecting item from history by position and displaying for editing..
From: |
Chet Ramey |
Subject: |
Re: Selecting item from history by position and displaying for editing... |
Date: |
Wed, 26 Jul 2023 11:36:39 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 |
On 7/25/23 12:19 PM, Sam Habiel wrote:
Hello there,
Quick Intro: We have an interactive CLI for a language called M used in banking
and healthcare... I am working on adding readline integration as a nice to have
feature. We are an open source project located over here:
https://gitlab.com/YottaDB/DB/YDB.
One thing we have in our previous CLI interpreter is the ability to select a
line for editing by position and have it re-display and put the cursor at the
end. It works like this:
1. foo
2. boo
rec 2
boo<cursor>
I tried to use rl_replace_line(h->line, 1) (h is the history item), then
rl_redisplay(), but nothing show up.
You might find it easier to let readline do more of the work. There is a
readline function rl_fetch_history (new in readline-8.2 and documented in
the readline user manual as the fetch-history bindable command) that does
pretty much what you want.
In previous readline versions, it was a vi-mode-only command, used to
implement the `G' command.
The history number is interpreted the same way as the bash `history'
command displays it; rl_fetch_history computes the desired position in
the history and calls rl_get_previous_history to go there.
Since it's a bindable command that uses a user-supplied numeric argument,
you'll have to arrange to set rl_explicit_arg to 1 before calling it as
rl_fetch_history (desired_history_number, 0);
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/