mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Make fuzzy matching available everywhere: #133 (-fuzzy)
This commit is contained in:
parent
c7ed92e40c
commit
98b8e583cb
7 changed files with 54 additions and 54 deletions
|
@ -193,6 +193,10 @@ Below is a list of the most important options:
|
|||
|
||||
Do not print any message when starting in daemon mode.
|
||||
|
||||
`-fuzzy`
|
||||
|
||||
Enable experimental fuzzy matching.
|
||||
|
||||
|
||||
### Theming
|
||||
|
||||
|
@ -547,9 +551,6 @@ Add a message line below the filter entry box. Supports pango markup.
|
|||
For more information on supported markup see [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)
|
||||
|
||||
|
||||
`-z`
|
||||
|
||||
Enable sloppy fuzzy matching.
|
||||
|
||||
### Message dialog
|
||||
|
||||
|
|
28
doc/rofi.1
28
doc/rofi.1
|
@ -1,7 +1,7 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "ROFI\-MANPAGE" "" "June 2015" "" ""
|
||||
.TH "ROFI\-MANPAGE" "" "July 2015" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
|
||||
|
@ -293,6 +293,19 @@ Start in case sensitive mode\.
|
|||
.P
|
||||
Do not print any message when starting in daemon mode\.
|
||||
.
|
||||
.P
|
||||
\fB\-fuzzy\fR
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
Enable experimental fuzzy matching\.
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "Theming"
|
||||
\fB\-bg\fR
|
||||
.
|
||||
|
@ -997,19 +1010,6 @@ Select first line that matches the given string
|
|||
.P
|
||||
Add a message line below the filter entry box\. Supports pango markup\. For more information on supported markup see here \fIhttps://developer\.gnome\.org/pango/stable/PangoMarkupFormat\.html\fR
|
||||
.
|
||||
.P
|
||||
\fB\-z\fR
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
Enable sloppy fuzzy matching\.
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "Message dialog"
|
||||
\fB\-e\fR \fImessage\fR
|
||||
.
|
||||
|
|
|
@ -108,10 +108,6 @@ int token_match ( char **tokens, const char *input, int case_sensitive,
|
|||
__attribute__( ( unused ) ) unsigned int index,
|
||||
__attribute__( ( unused ) ) Switcher * data );
|
||||
|
||||
int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
|
||||
__attribute__( ( unused ) ) unsigned int index,
|
||||
__attribute__( ( unused ) ) Switcher * data );
|
||||
|
||||
/**
|
||||
* @param cmd The command to execute.
|
||||
*
|
||||
|
|
|
@ -226,6 +226,8 @@ typedef struct _Settings
|
|||
unsigned int parse_hosts;
|
||||
/** Combi Switchers */
|
||||
char *combi_modi;
|
||||
/** Fuzzy match */
|
||||
unsigned int fuzzy;
|
||||
} Settings;
|
||||
|
||||
/** Global Settings structure. */
|
||||
|
|
|
@ -187,7 +187,6 @@ int dmenu_switcher_dialog ( char **input )
|
|||
char **list = get_dmenu ( &length );
|
||||
int restart = FALSE;
|
||||
char *message = NULL;
|
||||
menu_match_cb filter = token_match;
|
||||
|
||||
find_arg_str ( "-mesg", &message );
|
||||
|
||||
|
@ -225,10 +224,6 @@ int dmenu_switcher_dialog ( char **input )
|
|||
}
|
||||
find_arg_str_alloc ( "-filter", input );
|
||||
|
||||
if ( find_arg ( "-z" ) >= 0 ) {
|
||||
filter = fuzzy_token_match;
|
||||
}
|
||||
|
||||
char *select = NULL;
|
||||
find_arg_str ( "-select", &select );
|
||||
if ( select != NULL ) {
|
||||
|
@ -246,7 +241,7 @@ int dmenu_switcher_dialog ( char **input )
|
|||
do {
|
||||
int next_pos = selected_line;
|
||||
int mretv = menu ( list, length, input, dmenu_prompt,
|
||||
filter, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message );
|
||||
token_match, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message );
|
||||
// Special behavior.
|
||||
if ( only_selected ) {
|
||||
/**
|
||||
|
|
|
@ -329,25 +329,7 @@ int find_arg_char ( const char * const key, char *val )
|
|||
* Shared 'token_match' function.
|
||||
* Matches tokenized.
|
||||
*/
|
||||
int token_match ( char **tokens, const char *input, int case_sensitive,
|
||||
__attribute__( ( unused ) ) unsigned int index,
|
||||
__attribute__( ( unused ) ) Switcher *data )
|
||||
{
|
||||
int match = 1;
|
||||
char *compk = token_collate_key ( input, case_sensitive );
|
||||
|
||||
// Do a tokenized match.
|
||||
if ( tokens ) {
|
||||
for ( int j = 0; match && tokens[j]; j++ ) {
|
||||
match = ( strstr ( compk, tokens[j] ) != NULL );
|
||||
}
|
||||
}
|
||||
g_free ( compk );
|
||||
return match;
|
||||
}
|
||||
int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
|
||||
__attribute__( ( unused ) ) unsigned int index,
|
||||
__attribute__( ( unused ) ) Switcher * data )
|
||||
static int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive )
|
||||
{
|
||||
int match = 1;
|
||||
char *compk = token_collate_key ( input, case_sensitive );
|
||||
|
@ -368,6 +350,29 @@ int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
|
|||
g_free ( compk );
|
||||
return match;
|
||||
}
|
||||
static int normal_token_match ( char **tokens, const char *input, int case_sensitive )
|
||||
{
|
||||
int match = 1;
|
||||
char *compk = token_collate_key ( input, case_sensitive );
|
||||
|
||||
// Do a tokenized match.
|
||||
if ( tokens ) {
|
||||
for ( int j = 0; match && tokens[j]; j++ ) {
|
||||
match = ( strstr ( compk, tokens[j] ) != NULL );
|
||||
}
|
||||
}
|
||||
g_free ( compk );
|
||||
return match;
|
||||
}
|
||||
int token_match ( char **tokens, const char *input, int case_sensitive,
|
||||
__attribute__( ( unused ) ) unsigned int index,
|
||||
__attribute__( ( unused ) ) Switcher *data )
|
||||
{
|
||||
if ( config.fuzzy ) {
|
||||
return fuzzy_token_match ( tokens, input, case_sensitive );
|
||||
}
|
||||
return normal_token_match ( tokens, input, case_sensitive );
|
||||
}
|
||||
|
||||
int execute_generator ( const char * cmd )
|
||||
{
|
||||
|
|
|
@ -122,7 +122,8 @@ static XrmOption xrmOptions[] = {
|
|||
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL },
|
||||
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL },
|
||||
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL },
|
||||
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL }
|
||||
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
|
||||
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL }
|
||||
};
|
||||
|
||||
// Dynamic options.
|
||||
|
|
Loading…
Reference in a new issue