Loading...
Searching...
No Matches
interact.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2025, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <stdbool.h>
#include <stdio.h>
#include "complete.h"
struct ec_node;
struct ec_pnode;
struct ec_comp;
struct ec_interact_help {
char *desc;
char *help;
};
#define EC_INTERACT_HELP_ATTR "_help"
#define EC_INTERACT_CB_ATTR "_cb"
#define EC_INTERACT_DESC_ATTR "_desc"
typedef int (*ec_interact_command_cb_t)(const struct ec_pnode *);
ssize_t ec_interact_get_completions(
const struct ec_comp *cmpl,
char ***matches_out,
enum ec_comp_type type_mask
);
void ec_interact_free_completions(char **matches, size_t n);
int ec_interact_print_cols(FILE *out, unsigned int width, char const *const *matches, size_t n);
char *ec_interact_append_chars(const struct ec_comp *cmpl);
ssize_t ec_interact_get_helps(
const struct ec_node *node,
const char *line,
struct ec_interact_help **helps_out
);
int ec_interact_print_helps(
FILE *out,
unsigned int width,
const struct ec_interact_help *helps,
size_t n
);
void ec_interact_free_helps(struct ec_interact_help *helps, size_t n);
ssize_t ec_interact_get_error_helps(
const struct ec_node *node,
const char *line,
struct ec_interact_help **helps_out,
size_t *char_idx
);
int ec_interact_print_error_helps(
FILE *out,
unsigned int width,
const char *line,
const struct ec_interact_help *helps,
size_t n,
size_t char_idx
);
int ec_interact_set_help(struct ec_node *node, const char *help);
int ec_interact_set_callback(struct ec_node *node, ec_interact_command_cb_t cb);
int ec_interact_set_desc(struct ec_node *node, const char *desc);
ec_interact_command_cb_t ec_interact_get_callback(struct ec_pnode *parse);
ec_comp
struct ec_comp * ec_comp(void)
Create an empty completion object (list of completion items).
ec_comp_type
ec_comp_type
Completion item type.
Definition complete.h:47
ec_interact_get_error_helps
ssize_t ec_interact_get_error_helps(const struct ec_node *node, const char *line, struct ec_interact_help **helps_out, size_t *char_idx)
Get suggestions after a parsing error for the current line.
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_interact_print_error_helps
int ec_interact_print_error_helps(FILE *out, unsigned int width, const char *line, const struct ec_interact_help *helps, size_t n, size_t char_idx)
Print suggestions generated with ec_interact_get_error_helps().
ec_interact_set_help
int ec_interact_set_help(struct ec_node *node, const char *help)
Set help on a grammar node.
ec_interact_print_helps
int ec_interact_print_helps(FILE *out, unsigned int width, const struct ec_interact_help *helps, size_t n)
Print helps generated with ec_interact_get_helps().
ec_interact_set_desc
int ec_interact_set_desc(struct ec_node *node, const char *desc)
Set short description of a grammar node.
ec_interact_get_completions
ssize_t ec_interact_get_completions(const struct ec_comp *cmpl, char ***matches_out, enum ec_comp_type type_mask)
Get completion matches as an array of strings.
ec_interact_get_helps
ssize_t ec_interact_get_helps(const struct ec_node *node, const char *line, struct ec_interact_help **helps_out)
Get contextual helps from the current line.
ec_interact_set_callback
int ec_interact_set_callback(struct ec_node *node, ec_interact_command_cb_t cb)
Set callback function on a grammar node.
ec_interact_get_callback
ec_interact_command_cb_t ec_interact_get_callback(struct ec_pnode *parse)
Get callback attached to a parse tree.
ec_interact_print_cols
int ec_interact_print_cols(FILE *out, unsigned int width, char const *const *matches, size_t n)
Print completion matches as columns.
ec_interact_append_chars
char * ec_interact_append_chars(const struct ec_comp *cmpl)
Get characters to append to the line for a completion.
ec_interact_free_helps
void ec_interact_free_helps(struct ec_interact_help *helps, size_t n)
Free contextual helps.
ec_interact_free_completions
void ec_interact_free_completions(char **matches, size_t n)
Free the array of completion matches.
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_interact_help
A structure describing a contextual help.
Definition interact.h:26