1 /* Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file interactive.h Public API for interactive sessions. */
5 /* Interactive is hard to spell, lets' write i9e. */
7 /** Structure passed as input to the completers. */
8 struct i9e_completion_info {
9 char *buffer; /**< The full line. */
10 char *word; /**< The word the cursor is in. */
11 int point; /**< Cursor position. */
12 char **argv; /**< Vector of words in \a buffer. */
13 int argc; /**< Number of elements(words) in argv. */
14 int word_num; /**< The cursor is on this word. */
17 /** Completion information returned by the completers. */
18 struct i9e_completion_result {
19 /** NULL-terminated array of possible completions. */
21 /** Whether standard filename completion should be performed. */
22 bool filename_completion_desired;
23 /** Suppress adding a space character after the completed word. */
24 bool dont_append_space;
28 * Define a completer which does nothing.
30 * \param name Determines the name of the function to be defined.
32 #define I9E_DUMMY_COMPLETER(name) static void name ## _completer( \
33 __a_unused struct i9e_completion_info *ciname, \
34 struct i9e_completion_result *result) {result->matches = NULL;}
37 * A completer is simply a function pointer and name of the command for which
38 * it performs completion.
40 struct i9e_completer {
41 /** The command for which this completer provides completion. */
43 /** The completer returns all possible completions via the second parameter. */
44 void (*completer)(struct i9e_completion_info *, struct i9e_completion_result *);
48 * The i9e configuration settings of the client.
50 * A structure of this type must be allocated and filled in by the client
51 * before it is passed to the i9e subsystem via \ref i9e_open().
53 struct i9e_client_info {
54 /** Threshold for i9e_log(). */
56 /** Complete input lines are passed to this callback function. */
57 int (*line_handler)(char *line);
58 /** In single key mode, this callback is executed instead. */
59 int (*key_handler)(int key);
60 /** The array of valid key sequences for libreadline. */
62 /** File descriptors to use for input/output/log. */
64 /** Text of the current prompt. */
66 /** Where to store the readline history. */
69 * The array of completers, one per command. This is used for
70 * completing the first word (the command) and for calling the right
71 * completer if the cursor is not on the first word.
73 struct i9e_completer *completers;
75 * If non-NULL, this node is attached immediately to the stdout btr
76 * node of the i9e subsystem.
78 struct btr_node *producer;
81 int i9e_open(struct i9e_client_info *ici, struct sched *s);
82 void i9e_attach_to_stdout(struct btr_node *producer);
83 void i9e_print_status_bar(char *buf, unsigned len);
85 void i9e_signal_dispatch(int sig_num);
86 __printf_2_3 void i9e_log(int ll, const char* fmt,...);
87 int i9e_poll(struct pollfd *fds, nfds_t nfds, int timeout);
88 int i9e_extract_completions(const char *word, char **string_list,
90 char **i9e_complete_commands(const char *word, struct i9e_completer *completers);
91 void i9e_complete_option(char **opts, struct i9e_completion_info *ci,
92 struct i9e_completion_result *cr);
93 int i9e_print_completions(struct i9e_completer *completers);
94 int i9e_get_error(void);
95 void i9e_ll_completer(struct i9e_completion_info *ci,
96 struct i9e_completion_result *cr);