Skip to content
pi-c Documentation
Login

Documentation

/* Fuzzy matching, ported from Pi (reference/pi/packages/tui/src/fuzzy.ts)
 * so filtering ranks as Pi's does: the model picker, the other pickers, the settings
 * panel and the slash-command menu (fuzzy.c). */
#ifndef PIC_TUI_FUZZY_H
#define PIC_TUI_FUZZY_H

#include "tui/term.h"

#include <stddef.h>

/* Pi's fuzzyMatch: whether QUERY matches TEXT and its score (lower is a
 * better match, as in Pi). */
int tui_fuzzy_match(const char *query, const char *text, double *score);

/* Pi's fuzzyFilter over N texts: writes the indexes of the matching texts
 * to order[] (capacity n) best first, ties in input order, and returns how
 * many matched. An empty or all-space query matches everything in input
 * order. */
size_t tui_fuzzy_filter(const char *query, const char *const *texts, size_t n, size_t *order);

/* Whether QUERY (tokens split on spaces and '/') matches TEXT, as tui_fuzzy_filter would say of
 * it: the one matcher every picker and filter uses. */
int tui_fuzzy_has(const char *query, const char *text);

/* The editing keys every filter field shares: Backspace takes the last character, Ctrl+W the last
 * word, Ctrl+U everything. 1 when K is one of them (BUF is then edited), else 0. */
int tui_filter_edit(char *buf, size_t cap, const tui_key *k);

#endif