Libecoli  0.11.3
Extensible COmmand LIne library
interact.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2025, Olivier MATZ <zer0@droids-corp.org>
3  */
4 
12 #pragma once
13 
14 #include <stdbool.h>
15 #include <stdio.h>
16 
17 #include "complete.h"
18 
19 struct ec_node;
20 struct ec_pnode;
21 struct ec_comp;
22 
27  char *desc;
28  char *help;
29 };
30 
34 #define EC_INTERACT_HELP_ATTR "_help"
35 
39 #define EC_INTERACT_CB_ATTR "_cb"
40 
44 #define EC_INTERACT_DESC_ATTR "_desc"
45 
49 typedef int (*ec_interact_command_cb_t)(const struct ec_pnode *);
50 
64  const struct ec_comp *cmpl,
65  char ***matches_out,
66  enum ec_comp_type type_mask
67 );
68 
77 void ec_interact_free_completions(char **matches, size_t n);
78 
93 int ec_interact_print_cols(FILE *out, unsigned int width, char const *const *matches, size_t n);
94 
106 char *ec_interact_append_chars(const struct ec_comp *cmpl);
107 
121  const struct ec_node *node,
122  const char *line,
123  struct ec_interact_help **helps_out
124 );
125 
141  FILE *out,
142  unsigned int width,
143  const struct ec_interact_help *helps,
144  size_t n
145 );
146 
158 void ec_interact_free_helps(struct ec_interact_help *helps, size_t n);
159 
176  const struct ec_node *node,
177  const char *line,
178  struct ec_interact_help **helps_out,
179  size_t *char_idx
180 );
181 
201  FILE *out,
202  unsigned int width,
203  const char *line,
204  const struct ec_interact_help *helps,
205  size_t n,
206  size_t char_idx
207 );
208 
223 int ec_interact_set_help(struct ec_node *node, const char *help);
224 
239 
255 int ec_interact_set_desc(struct ec_node *node, const char *desc);
256 
270 
struct ec_comp * ec_comp(void)
ec_comp_type
Definition: complete.h:47
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_command_cb_t)(const struct ec_pnode *)
Definition: interact.h:49
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_print_helps(FILE *out, unsigned int width, const struct ec_interact_help *helps, size_t n)
int ec_interact_set_desc(struct ec_node *node, const char *desc)
ssize_t ec_interact_get_completions(const struct ec_comp *cmpl, char ***matches_out, enum ec_comp_type type_mask)
ssize_t ec_interact_get_helps(const struct ec_node *node, const char *line, struct ec_interact_help **helps_out)
int ec_interact_set_callback(struct ec_node *node, ec_interact_command_cb_t cb)
ec_interact_command_cb_t ec_interact_get_callback(struct ec_pnode *parse)
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)
void ec_interact_free_helps(struct ec_interact_help *helps, size_t n)
void ec_interact_free_completions(char **matches, size_t n)
struct ec_node * ec_node(const char *typename, const char *id)
struct ec_pnode * ec_pnode(const struct ec_node *node)