From 1b4297e6095fea7258f99150fb79b49a01b5519b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 5 Feb 2023 19:47:49 -0500 Subject: Fix what went wrong, part 2 --- complete.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'complete.c') diff --git a/complete.c b/complete.c index 6d7756f..4536401 100644 --- a/complete.c +++ b/complete.c @@ -35,6 +35,7 @@ struct Node { uint id; char *str; + enum Color color; struct Node *prev; struct Node *next; }; @@ -43,12 +44,13 @@ static uint gen; static struct Node *head; static struct Node *tail; -static struct Node *alloc(uint id, const char *str) { +static struct Node *alloc(uint id, const char *str, enum Color color) { struct Node *node = calloc(1, sizeof(*node)); if (!node) err(EX_OSERR, "calloc"); node->id = id; node->str = strdup(str); if (!node->str) err(EX_OSERR, "strdup"); + node->color = color; return node; } @@ -87,13 +89,23 @@ static struct Node *find(uint id, const char *str) { return NULL; } -void completePush(uint id, const char *str) { - if (!find(id, str)) append(alloc(id, str)); +void completePush(uint id, const char *str, enum Color color) { + struct Node *node = find(id, str); + if (node) { + if (color != Default) node->color = color; + } else { + append(alloc(id, str, color)); + } } -void completePull(uint id, const char *str) { +void completePull(uint id, const char *str, enum Color color) { struct Node *node = find(id, str); - prepend(node ? detach(node) : alloc(id, str)); + if (node) { + if (color != Default) node->color = color; + prepend(detach(node)); + } else { + prepend(alloc(id, str, color)); + } } void completeReplace(const char *old, const char *new) { @@ -121,6 +133,11 @@ void completeRemove(uint id, const char *str) { gen++; } +enum Color completeColor(uint id, const char *str) { + struct Node *node = find(id, str); + return (node ? node->color : Default); +} + const char *completePrefix(struct Cursor *curs, uint id, const char *prefix) { size_t len = strlen(prefix); if (curs->gen != gen) curs->node = NULL; -- cgit 1.4.1