/** * @file interact.h * @brief The interactive layer: prompts, line editing, history and * completion. * * None of this is reached by a script. The only hook on the path that * scripts share is one test in input_fill() ("is this input a terminal in * an interactive shell?"). */ #ifndef ZASH_INTERACT_H #define ZASH_INTERACT_H #include "parser.h" /* ---- interact.c ------------------------------------------------------ */ size_t term_cols(void); size_t term_rows(void); void interact_init(void); void interact_exit(void); bool interact_read(input_src *in); bool interact_refuse_eof(void); /* ---- history.c ------------------------------------------------------- */ void hist_init(void); void hist_add(const char *line, size_t len, bool append); int hist_count(void); const char *hist_entry(int index); void hist_save(void); /* ---- the line editor (edit_builtin.c) -------------------------------- */ /* * edit_usable() says whether lines can be edited on this terminal; * edit_readline() reads one line and returns it without its newline, in * storage it owns, or nullptr at end of input. */ bool edit_usable(void); char *edit_readline(const char *prompt, size_t *len); /* * `bind`, in the notation of the BSD shells: edit_bind() records one * "keys=action" word, reporting the problem itself and returning -1; * edit_bind_list() prints the action names, one per line. */ int edit_bind(const char *spec); void edit_bind_list(void); /* ---- complete.c ------------------------------------------------------ */ /** @brief The result of asking what could complete a word. */ typedef struct completion { char **list; /**< Candidate replacements for the word, sorted. */ int count; /**< Number of candidates. */ size_t start; /**< Offset in the line where the word begins. */ bool quoted; /**< The word began inside quotes: insert text as is. */ char quote; /**< That quote character, to close a final candidate. */ bool mvs; /**< Data set candidates: a final candidate is one that does not end in `.` or `(`. */ } completion; const char *expand_quietly(const char *raw, bool escapes); /** * @brief Length of the terminal control sequence at s, which is ESC. * @param s Text starting with the escape character. * @return Bytes in the sequence; control sequences in a prompt are for * the terminal, not for the screen, so they take no columns. */ size_t esc_seq_len(const char *s); void complete_line(const char *line, size_t cursor, completion *c); void complete_free(completion *c); /** * @brief A completion candidate, escaped for insertion into the line. * * The editors insert the text they are given as it is, so the quoting * the word needs has to be added here. * * @param s The candidate. * @param n Bytes of it to use. * @param quoted The word began inside quotes: insert it as it is. * @return The text to insert, for free(). */ char *complete_escaped(const char *s, size_t n, bool quoted); /** * @brief The candidates as a block of text for the terminal. * * Columns, with the last path component of each candidate, at most one * screenful, then "... and N more" if some were left out. Both editors * print the same thing, so one `.exp` covers both. * * @param c The candidates. * @param cols Terminal width. * @param rows Terminal height. * @return Text starting and ending with a newline, for free(). */ char *complete_listing(const completion *c, size_t cols, size_t rows); #endif