Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ghaerr
Copy link
Owner

@ghaerr ghaerr commented Oct 21, 2025

Moves linenoise line editing routines that were originally ported to ELKS bash shell to C library. This allows arrow-key line editing and command line history to be easily added to other applications in ELKS. Astandard (bash-compatible) TAB completion routine is also moved from the shell to libc.

Discussed briefly in #2406 (comment).

To add automatic line editing and tab completion to ELKS applications, instead of using fgets use:

#include <linenoise.h>
...
    // fputs(prompt); fflush(stdout);
    // if (fgets(buf, sizeof(buf), stdin)) do_something(buf);

    linenoiseSetCompletionCallback(linenoiseStdCompletion);
    char *str = linenoise(prompt);
    if (str) do_something(str);
    linenoiseHistoryAdd(line); /* Add to cmdline history */
    linenoiseFree(line);       /* The returned line has to be freed */

@ghaerr ghaerr merged commit fcd8c5d into master Oct 22, 2025
2 checks passed
@ghaerr ghaerr deleted the linenoise branch October 22, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants