EC_EDITLINE(3)

πŸ“¦
version 0.11.7 Β· 5 versions
, in fedora 44

πŸ’– EC_EDITLINE πŸ’–

okay bestie, so this one is straight out of the Libecoli Programmer's Manual, and it's literally the function that spins up a whole editline instance for you with all the default behavior already baked in. no cap. let's get into it 🫢


🌸 NAME 🌸

ec_editline β€” creates an editline instance with default behavior. that's it, that's the vibe ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <ecoli/editline.h>

struct ec_editline * ec_editline(
    /*
     * The name of the invoking program, used when reading the editrc(5) file
     * to determine which settings to use.
     */
    const char                  *prog,
    FILE                        *f_in,   /* The input stream to use. */
    FILE                        *f_out,  /* The output stream to use. */
    FILE                        *f_err,  /* The error stream to use. */
    /*
     * Flags to customize initialization. See ec_editline_init_flags.
     */
    enum ec_editline_init_flags  flags
);

✨ DESCRIPTION ✨

so what actually happens here? it allocates and initializes an ec_editline structure, calls editline's el_init(), and then does the editline configuration according to whatever flags you handed it. very demure, very mindful. πŸ’…

and then β€” and this is the important part, don't skip it β€” after that, the user must call ec_editline_set_node() to attach the grammar to the editline. like, it's not optional. the grammar does not attach itself. do it. 🧚


πŸ¦‹ STRUCTURES πŸ¦‹

here's the enum in all its raw glory, character for character, exactly as the page has it:

enum ec_editline_init_flags {
    /*
     * The ctrl-c, ctrl-z will be interpreted as standard
     * characters. An action can be associated with these characters with:
static int
     * cb(EditLine *editline, int c) {
{
 see editline documentation for details
}

if
     * (el_set(el, EL_ADDFN, "ed-foobar", "Help string about foobar", cb))

     * handle_error;
if (el_set(el, EL_BIND, "^C", "ed-break", NULL))
 handle_error;

The
     * default behavior (without this flag) is to let the signal pass:
ctrl-c will stop
     * program and ctrl-z will suspend it.
     */
      EC_EDITLINE_DISABLE_SIGNALS;
    /*
     * The default behavior creates a history with
     * EC_EDITLINE_HISTORY_SIZE entries. To change this value, use
ec_editline_set_history().
     */
      EC_EDITLINE_DISABLE_HISTORY;
    /*
     * The default behavior is to complete when ? or <tab> is hit.
     * You can register your own callback with:
if (el_set(el, EL_ADDFN,
     * "ed-complete", "Complete buffer", callback))
  handle_error;
if (el_set(el, EL_BIND,
     * "^I", "ed-complete", NULL))
  handle_error;

The default used callback is
     * ec_editline_complete().
     */
      EC_EDITLINE_DISABLE_COMPLETION;
    /*
     * Otherwise, the current signal handlers will be used.
     */
      EC_EDITLINE_DEFAULT_SIGHANDLER; };

okay now let's break down what each of those flags is actually doing, because the vibe check demands clarity πŸ”

  • EC_EDITLINE_DISABLE_SIGNALS β€” with this, ctrl-c and ctrl-z get interpreted as standard characters instead of signals. you can associate an action with these characters using a callback, like:
static int
cb(EditLine *editline, int c) {

(see editline documentation for details πŸ’«)

and then hooking it up like:

if (el_set(el, EL_ADDFN, "ed-foobar", "Help string about foobar", cb))
    handle_error;
if (el_set(el, EL_BIND, "^C", "ed-break", NULL))
    handle_error;

the default behavior β€” i.e. without this flag β€” is to let the signal pass through: ctrl-c will stop the program, and ctrl-z will suspend it. so if you don't set this flag, your program is getting interrupted, periodt. 😭

  • EC_EDITLINE_DISABLE_HISTORY β€” the default behavior creates a history with EC_EDITLINE_HISTORY_SIZE entries. want to change that number? use ec_editline_set_history(). easy. ✨
  • EC_EDITLINE_DISABLE_COMPLETION β€” by default it completes when ? or <tab> is hit. you can register your own callback with:
if (el_set(el, EL_ADDFN, "ed-complete", "Complete buffer", callback))
    handle_error;
if (el_set(el, EL_BIND, "^I", "ed-complete", NULL))
    handle_error;

and the default callback it uses is ec_editline_complete(). she's the main character of completion, lowkey πŸ‘‘

  • EC_EDITLINE_DEFAULT_SIGHANDLER β€” otherwise, the current signal handlers will be used. 🌈

πŸ’œ RETURN VALUE πŸ’œ

the allocated ec_editline structure, or NULL on error. if you get NULL, that's your sign bestie, something went wrong πŸ˜”


🌟 SEE ALSO 🌟

go read those next, they're all part of the same friend group fr fr 🫢


Copyright (C) 2010-2026 Olivier Matz, Robin Jarry.


and that's the whole page bestie!! πŸŽ€ this was libecoli, dated 2026-06-11 β€” go forth and ec_editline responsibly, and don't forget to call ec_editline_set_node() or the grammar will simply not be attached and that's on you πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from