1
0
Fork 0
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:
Dave Davenport 2015-07-01 09:12:22 +02:00
parent c7ed92e40c
commit 98b8e583cb
7 changed files with 54 additions and 54 deletions

View file

@ -193,6 +193,10 @@ Below is a list of the most important options:
Do not print any message when starting in daemon mode. Do not print any message when starting in daemon mode.
`-fuzzy`
Enable experimental fuzzy matching.
### Theming ### 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) For more information on supported markup see [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)
`-z`
Enable sloppy fuzzy matching.
### Message dialog ### Message dialog

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "ROFI\-MANPAGE" "" "June 2015" "" "" .TH "ROFI\-MANPAGE" "" "July 2015" "" ""
. .
.SH "NAME" .SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
@ -293,6 +293,19 @@ Start in case sensitive mode\.
.P .P
Do not print any message when starting in daemon mode\. 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" .SS "Theming"
\fB\-bg\fR \fB\-bg\fR
. .
@ -997,19 +1010,6 @@ Select first line that matches the given string
.P .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 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" .SS "Message dialog"
\fB\-e\fR \fImessage\fR \fB\-e\fR \fImessage\fR
. .

View file

@ -108,10 +108,6 @@ int token_match ( char **tokens, const char *input, int case_sensitive,
__attribute__( ( unused ) ) unsigned int index, __attribute__( ( unused ) ) unsigned int index,
__attribute__( ( unused ) ) Switcher * data ); __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. * @param cmd The command to execute.
* *

View file

@ -226,6 +226,8 @@ typedef struct _Settings
unsigned int parse_hosts; unsigned int parse_hosts;
/** Combi Switchers */ /** Combi Switchers */
char *combi_modi; char *combi_modi;
/** Fuzzy match */
unsigned int fuzzy;
} Settings; } Settings;
/** Global Settings structure. */ /** Global Settings structure. */

View file

@ -180,14 +180,13 @@ static void dmenu_output_formatted_line ( const char *format, const char *string
int dmenu_switcher_dialog ( char **input ) int dmenu_switcher_dialog ( char **input )
{ {
char *dmenu_prompt = "dmenu "; char *dmenu_prompt = "dmenu ";
int selected_line = -1; int selected_line = -1;
int retv = FALSE; int retv = FALSE;
int length = 0; int length = 0;
char **list = get_dmenu ( &length ); char **list = get_dmenu ( &length );
int restart = FALSE; int restart = FALSE;
char *message = NULL; char *message = NULL;
menu_match_cb filter = token_match;
find_arg_str ( "-mesg", &message ); find_arg_str ( "-mesg", &message );
@ -225,10 +224,6 @@ int dmenu_switcher_dialog ( char **input )
} }
find_arg_str_alloc ( "-filter", input ); find_arg_str_alloc ( "-filter", input );
if ( find_arg ( "-z" ) >= 0 ) {
filter = fuzzy_token_match;
}
char *select = NULL; char *select = NULL;
find_arg_str ( "-select", &select ); find_arg_str ( "-select", &select );
if ( select != NULL ) { if ( select != NULL ) {
@ -246,7 +241,7 @@ int dmenu_switcher_dialog ( char **input )
do { do {
int next_pos = selected_line; int next_pos = selected_line;
int mretv = menu ( list, length, input, dmenu_prompt, 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. // Special behavior.
if ( only_selected ) { if ( only_selected ) {
/** /**

View file

@ -329,25 +329,7 @@ int find_arg_char ( const char * const key, char *val )
* Shared 'token_match' function. * Shared 'token_match' function.
* Matches tokenized. * Matches tokenized.
*/ */
int token_match ( char **tokens, const char *input, int case_sensitive, static int fuzzy_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 )
{ {
int match = 1; int match = 1;
char *compk = token_collate_key ( input, case_sensitive ); 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 ); g_free ( compk );
return match; 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 ) int execute_generator ( const char * cmd )
{ {

View file

@ -122,7 +122,8 @@ static XrmOption xrmOptions[] = {
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL }, { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL }, { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, 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. // Dynamic options.