mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-10 15:44:41 -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
|
@ -62,19 +62,20 @@ Settings config = {
|
||||||
.i3_mode = 0,
|
.i3_mode = 0,
|
||||||
#endif
|
#endif
|
||||||
// Key binding
|
// Key binding
|
||||||
.window_key = "F12",
|
.window_key = "F12",
|
||||||
.run_key = "mod1+F2",
|
.run_key = "mod1+F2",
|
||||||
.ssh_key = "mod1+F3",
|
.ssh_key = "mod1+F3",
|
||||||
// Location of the window. WL_CENTER, WL_NORTH_WEST, WL_NORTH,WL_NORTH_EAST, etc.
|
// Location of the window. WL_CENTER, WL_NORTH_WEST, WL_NORTH,WL_NORTH_EAST, etc.
|
||||||
.location = WL_CENTER,
|
.location = WL_CENTER,
|
||||||
// Mode of window, list (Vertical) or dmenu like (Horizontal)
|
// Mode of window, list (Vertical) or dmenu like (Horizontal)
|
||||||
.hmode = FALSE,
|
.hmode = FALSE,
|
||||||
// Padding of the window.
|
// Padding of the window.
|
||||||
.padding = 5,
|
.padding = 5,
|
||||||
.ssh_set_title = TRUE,
|
.ssh_set_title = TRUE,
|
||||||
.y_offset = 0,
|
.y_offset = 0,
|
||||||
.x_offset = 0,
|
.x_offset = 0,
|
||||||
.fixed_num_lines = FALSE,
|
.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* ]
|
[ -terminal *terminal* ] [ -loc *position* ] [ -hmode ] [ -fixed-num-lines ] [ -padding *padding* ]
|
||||||
[ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ]
|
[ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ]
|
||||||
[ -ssh-set-title *true|false* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ]
|
[ -ssh-set-title *true|false* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ]
|
||||||
[ -disable-history ]
|
[ -disable-history ] [ -levenshtein-sort ]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -215,6 +215,10 @@ OPTIONS
|
||||||
|
|
||||||
Disable history
|
Disable history
|
||||||
|
|
||||||
|
`-levenshtein-sort`
|
||||||
|
|
||||||
|
When searching sort the result based on levenshtein distance.
|
||||||
|
|
||||||
|
|
||||||
Switch between modi
|
Switch between modi
|
||||||
-------------------
|
-------------------
|
||||||
|
|
|
@ -135,6 +135,8 @@ typedef struct _Settings
|
||||||
unsigned int fixed_num_lines;
|
unsigned int fixed_num_lines;
|
||||||
|
|
||||||
unsigned int disable_history;
|
unsigned int disable_history;
|
||||||
|
|
||||||
|
unsigned int levenshtein_sort;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
extern Settings config;
|
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* ) );
|
char **filtered = calloc ( num_lines, sizeof ( char* ) );
|
||||||
int *line_map = calloc ( num_lines, sizeof ( int ) );
|
int *line_map = calloc ( num_lines, sizeof ( int ) );
|
||||||
int *distance = NULL;
|
int *distance = NULL;
|
||||||
if ( config.disable_history ) {
|
if ( config.levenshtein_sort ) {
|
||||||
distance = calloc ( num_lines, sizeof ( int ) );
|
distance = calloc ( num_lines, sizeof ( int ) );
|
||||||
}
|
}
|
||||||
unsigned int filtered_lines = 0;
|
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 each token was matched, add it to list.
|
||||||
if ( match ) {
|
if ( match ) {
|
||||||
line_map[j] = i;
|
line_map[j] = i;
|
||||||
if ( config.disable_history ) {
|
if ( config.levenshtein_sort ) {
|
||||||
distance[i] = levenshtein ( *input, lines[i] );
|
distance[i] = levenshtein ( *input, lines[i] );
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( config.disable_history ) {
|
if ( config.levenshtein_sort ) {
|
||||||
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
||||||
}
|
}
|
||||||
for ( i = 0; i < j; i++ ) {
|
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 each token was matched, add it to list.
|
||||||
if ( match ) {
|
if ( match ) {
|
||||||
line_map[j] = i;
|
line_map[j] = i;
|
||||||
if ( config.disable_history ) {
|
if ( config.levenshtein_sort ) {
|
||||||
distance[i] = levenshtein ( text->text, lines[i] );
|
distance[i] = levenshtein ( text->text, lines[i] );
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( config.disable_history ) {
|
if ( config.levenshtein_sort ) {
|
||||||
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance );
|
||||||
}
|
}
|
||||||
for ( i = 0; i < j; i++ ) {
|
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 ) {
|
if ( find_arg ( argc, argv, "-disable-history" ) >= 0 ) {
|
||||||
config.disable_history = TRUE;
|
config.disable_history = TRUE;
|
||||||
}
|
}
|
||||||
|
if ( find_arg ( argc, argv, "-levenshtein-sort" ) >= 0 ) {
|
||||||
|
config.levenshtein_sort = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse commandline arguments about behavior
|
// Parse commandline arguments about behavior
|
||||||
find_arg_str ( argc, argv, "-terminal", &( config.terminal_emulator ) );
|
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, "ssh-set-title", { .num = &config.ssh_set_title }, NULL },
|
||||||
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
|
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL },
|
||||||
|
{ xrm_Boolean, "levenshtein-sort",{ .num = &config.levenshtein_sort }, NULL },
|
||||||
/* Key bindings */
|
/* Key bindings */
|
||||||
{ xrm_String, "key", { .str = &config.window_key }, NULL },
|
{ xrm_String, "key", { .str = &config.window_key }, NULL },
|
||||||
{ xrm_String, "rkey", { .str = &config.run_key }, NULL },
|
{ xrm_String, "rkey", { .str = &config.run_key }, NULL },
|
||||||
|
|
Loading…
Add table
Reference in a new issue