2 * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "telescope.h"
29 * Provide completions for load-url (lu).
32 compl_lu(void **data, void **ret, const char **descr)
34 struct history_item **state = (struct history_item **)data;
36 /* first time: init the state */
38 *state = history.items;
40 if (*state == history.items + history.len)
43 return (*state)++->uri;
47 * Provide completions for execute-extended-command (eecmd).
50 compl_eecmd(void **data, void **ret, const char **descr)
52 struct cmd **state = (struct cmd **)data;
54 /* first time: init the state */
58 if ((*state)->cmd == NULL)
61 *descr = (*state)->descr;
62 return (*state)++->cmd;
66 * Provide completions for tab-select.
69 compl_ts(void **data, void **ret, const char **descr)
71 struct tab **tab = (struct tab **)data;
73 /* first time: init the state */
75 *tab = TAILQ_FIRST(&tabshead);
76 else if ((*tab = TAILQ_NEXT(*tab, tabs)) == NULL)
81 if (*(*tab)->buffer.title == '\0')
82 return hist_cur((*tab)->hist);
83 *descr = hist_cur((*tab)->hist);
84 return (*tab)->buffer.title;
88 * Provide completions for link-select.
91 compl_ls(void **data, void **ret, const char **descr)
93 struct line **line = (struct line **)data;
98 while (l != NULL && l->type != LINE_LINK)
99 l = TAILQ_NEXT(l, lines);
105 if ((link = l->line) == NULL) {
112 *line = TAILQ_NEXT(l, lines);
117 * Provide completions for swiper.
120 compl_swiper(void **data, void **ret, const char **descr)
122 struct line **line = (struct line **)data;
125 while (*line != NULL && (*line)->line == NULL)
126 *line = TAILQ_NEXT(*line, lines);
131 text = (*line)->line;
133 *line = TAILQ_NEXT(*line, lines);
138 * Provide completions for toc
141 compl_toc(void **data, void **ret, const char **descr)
143 struct line **line = (struct line **)data;
148 while (l != NULL && (l->line == NULL ||
149 (l->type != LINE_TITLE_1 &&
150 l->type != LINE_TITLE_2 &&
151 l->type != LINE_TITLE_3)))
152 l = TAILQ_NEXT(l, lines);
160 *line = TAILQ_NEXT(l, lines);
165 * Provide completions for use-certificate
168 compl_uc(void **data, void **ret, const char **descr)
170 const char ***state = (const char ***)data;
172 /* first time: init the state */
174 *state = (const char **)identities;
179 /* XXX filling descr too would be nice */
180 return *((*state)++);