Sujet : Re: Running an editor from ANSI C
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 07. Jun 2024, 05:46:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240606213300.35@kylheku.com>
References : 1 2 3 4 5 6 7 8
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-06, Malcolm McLean <
malcolm.arthur.mclean@gmail.com> wrote:
I want to run nano (or vi, or ed), in a shell running a pure ansi C
program. So the way to do it is to create a file, write the text you
want edit to it, them call system("nano readme.txt"). Nano then grabs
the cobsole, which is what you want. You then read the file to get the
edited data.
In the TXR project, I took Antirez's Linenoise library and did a lot
of work on it. One of the features I added is Ctrl-X Ctrl-E to edit
the input in an external editor.
There are some non-standard-C bitws in it, but the main gist of it is
as you say. The temporary file is written using some I/O functions in a
callback API used by linenoise and the editor is run via system().
https://www.kylheku.com/cgit/txr/tree/linenoise/linenoise.cFunction to look for is edit_in_editor.
In that code I made the decision to try to plant the temporary file
in the user's home directory, or else just the current directory
if the home directory can't be identified for whatever reason.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca