build: Use .ONESHELL.
[paraslash.git] / interactive.h
1 /* Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2
3 /** \file interactive.h Public API for interactive sessions. */
4
5 /* Interactive is hard to spell, lets' write i9e. */
6
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. */
15 };
16
17 /** Completion information returned by the completers. */
18 struct i9e_completion_result {
19 /** NULL-terminated array of possible completions. */
20 char **matches;
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;
25 };
26
27 /**
28 * Define a completer which does nothing.
29 *
30 * \param name Determines the name of the function to be defined.
31 */
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;}
35
36 /**
37 * A completer is simply a function pointer and name of the command for which
38 * it performs completion.
39 */
40 struct i9e_completer {
41 /** The command for which this completer provides completion. */
42 const char *name;
43 /** The completer returns all possible completions via the second parameter. */
44 void (*completer)(struct i9e_completion_info *, struct i9e_completion_result *);
45 };
46
47 /**
48 * The i9e configuration settings of the client.
49 *
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().
52 */
53 struct i9e_client_info {
54 /** Threshold for i9e_log(). */
55 int loglevel;
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. */
61 char **bound_keyseqs;
62 /** File descriptors to use for input/output/log. */
63 int fds[3];
64 /** Text of the current prompt. */
65 char *prompt;
66 /** Where to store the readline history. */
67 char *history_file;
68 /**
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.
72 */
73 struct i9e_completer *completers;
74 /**
75 * If non-NULL, this node is attached immediately to the stdout btr
76 * node of the i9e subsystem.
77 */
78 struct btr_node *producer;
79 };
80
81 int i9e_open(struct i9e_client_info *ici, struct sched *s);
82 void i9e_attach_to_stdout(struct btr_node *producer);
83 void ie9_print_status_bar(char *buf, unsigned len);
84 void i9e_close(void);
85 void i9e_signal_dispatch(int sig_num);
86 __printf_2_3 void i9e_log(int ll, const char* fmt,...);
87 int i9e_select(int n, fd_set *readfds, fd_set *writefds,
88 struct timeval *timeout_tv);
89 int i9e_extract_completions(const char *word, char **string_list,
90 char ***result);
91 char **i9e_complete_commands(const char *word, struct i9e_completer *completers);
92 void i9e_complete_option(char **opts, struct i9e_completion_info *ci,
93 struct i9e_completion_result *cr);
94 int i9e_print_completions(struct i9e_completer *completers);
95 int i9e_get_error(void);