002
2021-07-14
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
004
2021-07-14
op
* Permission to use, copy, modify, and distribute this software for any
005
2021-07-14
op
* purpose with or without fee is hereby granted, provided that the above
006
2021-07-14
op
* copyright notice and this permission notice appear in all copies.
008
2021-07-14
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009
2021-07-14
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010
2021-07-14
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011
2021-07-14
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012
2021-07-14
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013
2021-07-14
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014
2021-07-14
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
017
2021-07-21
op
#include "compat.h"
019
2021-07-14
op
#include <stdlib.h>
021
2021-07-14
op
#include "compl.h"
022
2021-07-14
op
#include "telescope.h"
023
2022-02-26
op
#include "session.h"
026
2022-02-26
op
* Provide completions for load-url (lu).
028
2022-02-26
op
const char *
029
2022-02-26
op
compl_lu(void **data, void **ret, const char **descr)
031
2022-02-26
op
struct history_item **state = (struct history_item **)data;
033
2022-02-26
op
/* first time: init the state */
034
2022-02-26
op
if (*state == NULL)
035
2022-02-26
op
*state = history.items;
037
2022-02-26
op
if (*state == history.items + history.len)
038
2022-02-26
op
return NULL;
040
2022-02-26
op
return (*state)++->uri;
044
2021-07-14
op
* Provide completions for execute-extended-command (eecmd).
046
2021-07-14
op
const char *
047
2021-07-18
op
compl_eecmd(void **data, void **ret, const char **descr)
049
2021-07-14
op
struct cmd **state = (struct cmd **)data;
051
2021-07-14
op
/* first time: init the state */
052
2021-07-14
op
if (*state == NULL)
053
2021-07-14
op
*state = cmds;
055
2021-07-14
op
if ((*state)->cmd == NULL)
056
2021-07-14
op
return NULL;
058
2021-07-18
op
*descr = (*state)->descr;
059
2021-07-14
op
return (*state)++->cmd;
063
2021-07-14
op
* Provide completions for tab-select.
065
2021-07-14
op
const char *
066
2021-07-18
op
compl_ts(void **data, void **ret, const char **descr)
068
2021-07-14
op
struct tab **tab = (struct tab **)data;
070
2021-07-14
op
/* first time: init the state */
071
2021-07-14
op
if (*tab == NULL)
072
2021-07-14
op
*tab = TAILQ_FIRST(&tabshead);
073
2021-07-14
op
else if ((*tab = TAILQ_NEXT(*tab, tabs)) == NULL)
074
2021-07-14
op
return NULL;
076
2021-07-14
op
*ret = *tab;
078
2021-07-14
op
if (*(*tab)->buffer.page.title == '\0')
079
2021-07-14
op
return (*tab)->hist_cur->h;
080
2021-07-18
op
*descr = (*tab)->hist_cur->h;
081
2021-07-14
op
return (*tab)->buffer.page.title;
085
2021-07-14
op
* Provide completions for link-select.
087
2021-07-14
op
const char *
088
2021-07-18
op
compl_ls(void **data, void **ret, const char **descr)
090
2021-07-14
op
struct line **line = (struct line **)data;
091
2021-07-14
op
struct line *l;
092
2021-07-14
op
const char *link;
094
2021-07-14
op
l = *line;
095
2021-07-14
op
while (l != NULL && l->type != LINE_LINK)
096
2021-07-14
op
l = TAILQ_NEXT(l, lines);
098
2021-07-14
op
/* end of buffer */
099
2021-07-14
op
if (l == NULL)
100
2021-07-14
op
return NULL;
102
2021-07-18
op
if ((link = l->line) == NULL) {
103
2021-07-16
op
link = l->alt;
104
2021-07-18
op
*descr = NULL;
106
2021-07-18
op
*descr = l->alt;
108
2021-07-14
op
*ret = l;
109
2021-07-14
op
*line = TAILQ_NEXT(l, lines);
110
2021-07-14
op
return link;
114
2021-07-15
op
* Provide completions for swiper.
116
2021-07-14
op
const char *
117
2021-07-18
op
compl_swiper(void **data, void **ret, const char **descr)
119
2021-07-14
op
struct line **line = (struct line **)data;
120
2021-07-14
op
const char *text;
122
2021-07-14
op
while (*line != NULL && (*line)->line == NULL)
123
2021-07-14
op
*line = TAILQ_NEXT(*line, lines);
125
2021-07-14
op
if (*line == NULL)
126
2021-07-14
op
return NULL;
128
2021-07-14
op
text = (*line)->line;
129
2021-07-14
op
*ret = *line;
130
2021-07-14
op
*line = TAILQ_NEXT(*line, lines);
131
2021-07-14
op
return text;
135
2021-07-15
op
* Provide completions for toc
137
2021-07-15
op
const char *
138
2021-07-18
op
compl_toc(void **data, void **ret, const char **descr)
140
2021-07-15
op
struct line **line = (struct line **)data;
141
2021-07-15
op
struct line *l;
142
2021-07-15
op
const char *text;
144
2021-07-15
op
l = *line;
145
2021-07-16
op
while (l != NULL && (l->line == NULL ||
146
2021-07-16
op
(l->type != LINE_TITLE_1 &&
147
2021-07-15
op
l->type != LINE_TITLE_2 &&
148
2021-07-16
op
l->type != LINE_TITLE_3)))
149
2021-07-15
op
l = TAILQ_NEXT(l, lines);
151
2021-07-15
op
/* end of buffer */
152
2021-07-15
op
if (l == NULL)
153
2021-07-15
op
return NULL;
155
2021-07-15
op
text = l->line;
156
2021-07-15
op
*ret = l;
157
2021-07-15
op
*line = TAILQ_NEXT(l, lines);
158
2021-07-15
op
return text;