1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
6 * Helpers that can be used to associate an editline instance with
9 * XXX support saved history
10 * XXX support multiline edition
14 #ifndef ECOLI_EDITLINE_
15 #define ECOLI_EDITLINE_
24 struct ec_editline_help {
30 * Default history size.
32 #define EC_EDITLINE_HISTORY_SIZE 128
35 * Ask the terminal to not send signals (STOP, SUSPEND, XXX). The
36 * ctrl-c, ctrl-z will be interpreted as standard characters. An
37 * action can be associated to these characters with:
39 * static int cb(EditLine *editline, int c) {
41 * see editline documentation for details
44 * if (el_set(el, EL_ADDFN, "ed-foobar", "Help string about foobar", cb))
46 * if (el_set(el, EL_BIND, "^C", "ed-break", NULL))
49 * The default behavior (without this flag) is to let the signal pass: ctrl-c
50 * will stop program and ctrl-z will suspend it.
52 #define EC_EDITLINE_DISABLE_SIGNALS 0x01
55 * Disable history. The default behavior creates an history with
56 * EC_EDITLINE_HISTORY_SIZE entries. To change this value, use
57 * ec_editline_set_history().
59 #define EC_EDITLINE_DISABLE_HISTORY 0x02
62 * Disable completion. The default behavior is to complete when
63 * '?' or '<tab>' is hit. You can register your own callback with:
65 * if (el_set(el, EL_ADDFN, "ed-complete", "Complete buffer", callback))
67 * if (el_set(el, EL_BIND, "^I", "ed-complete", NULL))
70 * The default used callback is ec_editline_complete().
72 #define EC_EDITLINE_DISABLE_COMPLETION 0x04
74 typedef int (*ec_editline_cmpl_t)(struct ec_editline *editline, int c);
77 * Create an editline instance with default behavior.
79 * XXX Wrapper to editline's el_init()
84 ec_editline(const char *name, FILE *f_in, FILE *f_out, FILE *f_err,
88 * Free an editline instance allocated with ec_editline().
90 void ec_editline_free(struct ec_editline *editline);
93 * Return the editline instance attached to the ec_editline object.
95 EditLine *ec_editline_get_el(struct ec_editline *editline);
98 const struct ec_node *ec_editline_get_node(struct ec_editline *editline);
99 void ec_editline_set_node(struct ec_editline *editline,
100 const struct ec_node *node);
102 //XXX get history, get_...
105 * Change the history size.
107 * The default behavior is to have an history whose size
108 * is EC_EDITLINE_HISTORY_SIZE. This can be changed with this
112 * The pointer to the ec_editline structure.
114 * The desired size of the history.
116 * 0 on success, or -1 on error (errno is set).
118 int ec_editline_set_history(struct ec_editline *editline,
122 ec_editline_print_cols(struct ec_editline *editline,
123 char const * const *matches, size_t n);
125 void ec_editline_free_completions(char **matches, size_t len);
127 ec_editline_get_completions(const struct ec_comp *cmpl, char ***matches_out);
129 ec_editline_append_chars(const struct ec_comp *cmpl);
132 ec_editline_get_helps(const struct ec_editline *editline, const char *line,
133 const char *full_line, struct ec_editline_help **helps_out);
135 ec_editline_print_helps(struct ec_editline *editline,
136 const struct ec_editline_help *helps, size_t n);
138 ec_editline_free_helps(struct ec_editline_help *helps, size_t len);
141 ec_editline_set_prompt(struct ec_editline *editline, const char *prompt);
149 * The returned line must be freed by the caller using ec_free().
151 char *ec_editline_gets(struct ec_editline *editline);
154 * Get a line (managing completion) and parse it with passed node
155 * XXX find a better name?
158 ec_editline_parse(struct ec_editline *editline, const struct ec_node *node);
161 ec_editline_complete(EditLine *el, int c);