Loading...
Searching...
No Matches
editline.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <stdbool.h>
#include <stdio.h>
struct ec_node;
struct ec_pnode;
struct ec_comp;
struct editline;
struct ec_editline;
#define EC_EDITLINE_HISTORY_SIZE 128
enum ec_editline_init_flags {
EC_EDITLINE_DISABLE_SIGNALS = 1 << 0,
EC_EDITLINE_DISABLE_HISTORY = 1 << 1,
EC_EDITLINE_DISABLE_COMPLETION = 1 << 2,
EC_EDITLINE_DEFAULT_SIGHANDLER = 1 << 3,
};
typedef int (*ec_editline_check_exit_cb_t)(void *opaque);
struct ec_editline *ec_editline(
const char *prog,
FILE *f_in,
FILE *f_out,
FILE *f_err,
enum ec_editline_init_flags flags
);
void ec_editline_free(struct ec_editline *editline);
struct editline *ec_editline_get_el(struct ec_editline *editline);
int ec_editline_term_size(
const struct ec_editline *editline,
unsigned int *width,
unsigned int *height
);
int ec_editline_set_node(struct ec_editline *editline, const struct ec_node *node);
const struct ec_node *ec_editline_get_node(const struct ec_editline *editline);
int ec_editline_set_history(struct ec_editline *editline, size_t hist_size, const char *hist_file);
int ec_editline_set_prompt(struct ec_editline *editline, const char *prompt);
int ec_editline_set_prompt_esc(struct ec_editline *editline, const char *prompt, char delim);
char *ec_editline_curline(const struct ec_editline *editline, bool trim_after_cursor);
char *ec_editline_gets(struct ec_editline *editline);
struct ec_pnode *ec_editline_parse(struct ec_editline *editline);
int ec_editline_interact(
struct ec_editline *editline,
ec_editline_check_exit_cb_t check_exit_cb,
void *opaque
);
int ec_editline_complete(struct editline *el, int c);
/*
* Deprecated aliases for symbols moved to interact.h.
*/
#include "interact.h"
#include "utils.h"
#define EC_EDITLINE_HELP_ATTR EC_DEPRECATED_MACRO("use EC_INTERACT_HELP_ATTR") EC_INTERACT_HELP_ATTR
#define EC_EDITLINE_CB_ATTR EC_DEPRECATED_MACRO("use EC_INTERACT_CB_ATTR") EC_INTERACT_CB_ATTR
#define EC_EDITLINE_DESC_ATTR EC_DEPRECATED_MACRO("use EC_INTERACT_DESC_ATTR") EC_INTERACT_DESC_ATTR
struct EC_DEPRECATED("use struct ec_interact_help") ec_editline_help {
char *desc;
char *help;
};
typedef ec_interact_command_cb_t
ec_editline_command_cb_t EC_DEPRECATED("use ec_interact_command_cb_t");
/*
* Suppress deprecation warnings for function declarations that reference
* deprecated types in their signatures.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
EC_DEPRECATED("use ec_interact_get_completions") ssize_t
ec_editline_get_completions(const struct ec_comp *cmpl, char ***matches_out);
EC_DEPRECATED("use ec_interact_free_completions")
void ec_editline_free_completions(char **matches, size_t n);
EC_DEPRECATED("use ec_interact_print_cols")
int ec_editline_print_cols(struct ec_editline *editline, char const *const *matches, size_t n);
EC_DEPRECATED("use ec_interact_append_chars")
char *ec_editline_append_chars(const struct ec_comp *cmpl);
EC_DEPRECATED("use ec_interact_get_helps") ssize_t ec_editline_get_helps(
const struct ec_editline *editline,
const char *line,
struct ec_editline_help **helps_out
);
EC_DEPRECATED("use ec_interact_print_helps")
int ec_editline_print_helps(
const struct ec_editline *editline,
const struct ec_editline_help *helps,
size_t n
);
EC_DEPRECATED("use ec_interact_free_helps")
void ec_editline_free_helps(struct ec_editline_help *helps, size_t n);
EC_DEPRECATED("use ec_interact_get_error_helps") ssize_t ec_editline_get_error_helps(
const struct ec_editline *editline,
struct ec_editline_help **helps_out,
size_t *char_idx
);
EC_DEPRECATED("use ec_interact_print_error_helps")
int ec_editline_print_error_helps(
const struct ec_editline *editline,
const struct ec_editline_help *helps,
size_t n,
size_t char_idx
);
EC_DEPRECATED("use ec_interact_set_help")
int ec_editline_set_help(struct ec_node *node, const char *help);
EC_DEPRECATED("use ec_interact_set_callback")
int ec_editline_set_callback(struct ec_node *node, ec_interact_command_cb_t cb);
EC_DEPRECATED("use ec_interact_set_desc")
int ec_editline_set_desc(struct ec_node *node, const char *desc);
#pragma GCC diagnostic pop
ec_comp
struct ec_comp * ec_comp(void)
Create an empty completion object (list of completion items).
ec_editline_set_prompt
int ec_editline_set_prompt(struct ec_editline *editline, const char *prompt)
Set editline prompt.
ec_editline
struct ec_editline * ec_editline(const char *prog, FILE *f_in, FILE *f_out, FILE *f_err, enum ec_editline_init_flags flags)
Create an editline instance with default behavior.
ec_editline_set_prompt_esc
int ec_editline_set_prompt_esc(struct ec_editline *editline, const char *prompt, char delim)
Set editline escaped prompt.
ec_editline_get_node
const struct ec_node * ec_editline_get_node(const struct ec_editline *editline)
Return the ecoli node attached to the editline structure.
ec_editline_free
void ec_editline_free(struct ec_editline *editline)
Free an editline structure allocated with ec_editline().
ec_editline_parse
struct ec_pnode * ec_editline_parse(struct ec_editline *editline)
Get a line interactively (with completion), and parse it.
ec_editline_check_exit_cb_t
int(* ec_editline_check_exit_cb_t)(void *opaque)
Type of callback invoked by ec_editline_interact() to check if loop should exit (when the function re...
Definition editline.h:94
ec_editline_get_el
struct editline * ec_editline_get_el(struct ec_editline *editline)
Return the wrapped editline instance attached to the ec_editline structure.
ec_editline_term_size
int ec_editline_term_size(const struct ec_editline *editline, unsigned int *width, unsigned int *height)
Get terminal width and height.
ec_editline_complete
int ec_editline_complete(struct editline *el, int c)
Default completion callback used by editline.
ec_editline_interact
int ec_editline_interact(struct ec_editline *editline, ec_editline_check_exit_cb_t check_exit_cb, void *opaque)
Interact with the user until exit.
ec_editline_init_flags
ec_editline_init_flags
Flags passed at ec_editline initialization.
Definition editline.h:36
ec_editline_set_node
int ec_editline_set_node(struct ec_editline *editline, const struct ec_node *node)
Attach an ecoli node to the editline structure.
ec_editline_gets
char * ec_editline_gets(struct ec_editline *editline)
Get a line interactively (with completion).
ec_editline_set_history
int ec_editline_set_history(struct ec_editline *editline, size_t hist_size, const char *hist_file)
Change the history size.
ec_editline_curline
char * ec_editline_curline(const struct ec_editline *editline, bool trim_after_cursor)
Get the current edited line.
EC_EDITLINE_DISABLE_COMPLETION
@ EC_EDITLINE_DISABLE_COMPLETION
Disable completion.
Definition editline.h:79
EC_EDITLINE_DISABLE_SIGNALS
@ EC_EDITLINE_DISABLE_SIGNALS
Ask the terminal to not send signals (STOP, SUSPEND, ...).
Definition editline.h:57
EC_EDITLINE_DEFAULT_SIGHANDLER
@ EC_EDITLINE_DEFAULT_SIGHANDLER
Use editline own signal handler for the following signals when reading command input: SIGCONT,...
Definition editline.h:86
EC_EDITLINE_DISABLE_HISTORY
@ EC_EDITLINE_DISABLE_HISTORY
Disable history.
Definition editline.h:64
ec_interact_command_cb_t
int(* ec_interact_command_cb_t)(const struct ec_pnode *)
Type of callback attached with EC_INTERACT_CB_ATTR attribute.
Definition interact.h:49
ec_node
struct ec_node * ec_node(const char *typename, const char *id)
Create a new node from its type name.
ec_pnode
struct ec_pnode * ec_pnode(const struct ec_node *node)
Create an empty parsing tree.
EC_DEPRECATED
#define EC_DEPRECATED(msg)
Mark a function or type as deprecated.
Definition utils.h:36