2 * Copyright (C) 2011-2012 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file interactive.h Public API for interactive sessions. */
9 /* Interactive is hard to spell, lets' write i9e. */
11 /** Structure passed as input to the completers. */
12 struct i9e_completion_info {
13 char *buffer; /**< The full line. */
14 char *word; /**< The word the cursor is in. */
15 int point; /**< Cursor position. */
16 char **argv; /**< Vector of words in \a buffer. */
17 int argc; /**< Number of elements(words) in argv. */
18 int word_num; /**< The cursor is on this word. */
21 /** Completion information returned by the completers. */
22 struct i9e_completion_result {
23 /** NULL-terminated array of possible completions. */
25 /** Whether standard filename completion should be performed. */
26 bool filename_completion_desired;
27 /** Suppress adding a space character after the completed word. */
28 bool dont_append_space;
32 * Define a completer which does nothing.
34 * \param name Determines the name of the function to be defined.
36 #define I9E_DUMMY_COMPLETER(name) void name ## _completer( \
37 __a_unused struct i9e_completion_info *ciname, \
38 struct i9e_completion_result *result) {result->matches = NULL;}
41 * A completer is simply a function pointer and name of the command for which
42 * it performs completion.
44 struct i9e_completer {
45 /** The command for which this completer provides completion. */
47 /** The completer returns all possible completions via the second parameter. */
48 void (*completer)(struct i9e_completion_info *, struct i9e_completion_result *);
52 * The i9e configuration settings of the client.
54 * A structure of this type must be allocated and filled in by the client
55 * before it is passed to the i9e subsystem via \ref i9e_open().
57 struct i9e_client_info {
58 /** Threshold for i9e_log(). */
60 /** Complete input lines are passed to this callback function. */
61 int (*line_handler)(char *line);
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;
76 int i9e_open(struct i9e_client_info *ici, struct sched *s);
77 void i9e_attach_to_stdout(struct btr_node *producer);
79 void i9e_signal_dispatch(int sig_num);
80 __printf_2_3 void i9e_log(int ll, const char* fmt,...);
81 int i9e_select(int n, fd_set *readfds, fd_set *writefds,
82 struct timeval *timeout_tv);
83 int i9e_extract_completions(const char *word, char **string_list,
85 char **i9e_complete_commands(const char *word, struct i9e_completer *completers);
86 void i9e_complete_option(char **opts, struct i9e_completion_info *ci,
87 struct i9e_completion_result *cr);
88 int i9e_print_completions(struct i9e_completer *completers);