mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Make levenshtein sorting its own option.
* TODO: update manpage. (no md2man on this machine)
This commit is contained in:
parent
daa0d16221
commit
c86f28493a
5 changed files with 26 additions and 15 deletions
|
@ -75,6 +75,7 @@ Settings config = {
|
|||
.y_offset = 0,
|
||||
.x_offset = 0,
|
||||
.fixed_num_lines = FALSE,
|
||||
.disable_history = FALSE
|
||||
.disable_history = FALSE,
|
||||
.levenshtein_sort = FALSE
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ SYNOPSIS
|
|||
[ -terminal *terminal* ] [ -loc *position* ] [ -hmode ] [ -fixed-num-lines ] [ -padding *padding* ]
|
||||
[ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ]
|
||||
[ -ssh-set-title *true|false* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ]
|
||||
[ -disable-history ]
|
||||
[ -disable-history ] [ -levenshtein-sort ]
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
@ -215,6 +215,10 @@ OPTIONS
|
|||
|
||||
Disable history
|
||||
|
||||
`-levenshtein-sort`
|
||||
|
||||
When searching sort the result based on levenshtein distance.
|
||||
|
||||
|
||||
Switch between modi
|
||||
-------------------
|
||||
|
|
|
@ -135,6 +135,8 @@ typedef struct _Settings
|
|||
unsigned int fixed_num_lines;
|
||||
|
||||
unsigned int disable_history;
|
||||
|
||||
unsigned int levenshtein_sort;
|
||||
} Settings;
|
||||
|
||||
extern Settings config;
|
||||
|
|
|
@ -1095,7 +1095,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
|
|||
char **filtered = calloc ( num_lines, sizeof ( char* ) );
|
||||
int *line_map = calloc ( num_lines, sizeof ( int ) );
|
||||
int *distance = NULL;
|
||||
if ( config.disable_history ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
distance = calloc ( num_lines, sizeof ( int ) );
|
||||
}
|
||||
unsigned int filtered_lines = 0;
|
||||
|
@ -1110,13 +1110,13 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
|
|||
// If each token was matched, add it to list.
|
||||
if ( match ) {
|
||||
line_map[j] = i;
|
||||
if ( config.disable_history ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
distance[i] = levenshtein ( *input, lines[i] );
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if ( config.disable_history ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
||||
}
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
|
@ -1441,13 +1441,13 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
|
|||
// If each token was matched, add it to list.
|
||||
if ( match ) {
|
||||
line_map[j] = i;
|
||||
if ( config.disable_history ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
distance[i] = levenshtein ( text->text, lines[i] );
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if ( config.disable_history ) {
|
||||
if ( config.levenshtein_sort ) {
|
||||
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
||||
}
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
|
@ -1901,6 +1901,9 @@ static void parse_cmd_options ( int argc, char ** argv )
|
|||
if ( find_arg ( argc, argv, "-disable-history" ) >= 0 ) {
|
||||
config.disable_history = TRUE;
|
||||
}
|
||||
if ( find_arg ( argc, argv, "-levenshtein-sort" ) >= 0 ) {
|
||||
config.levenshtein_sort = TRUE;
|
||||
}
|
||||
|
||||
// Parse commandline arguments about behavior
|
||||
find_arg_str ( argc, argv, "-terminal", &( config.terminal_emulator ) );
|
||||
|
|
|
@ -99,6 +99,7 @@ static XrmOption xrmOptions[] = {
|
|||
|
||||
{ xrm_Boolean, "ssh-set-title", { .num = &config.ssh_set_title }, NULL },
|
||||
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
|
||||
{ xrm_Boolean, "levenshtein-sort",{ .num = &config.levenshtein_sort }, NULL },
|
||||
/* Key bindings */
|
||||
{ xrm_String, "key", { .str = &config.window_key }, NULL },
|
||||
{ xrm_String, "rkey", { .str = &config.run_key }, NULL },
|
||||
|
|
Loading…
Reference in a new issue