| ... | ... |
@@ -63,7 +63,7 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 63 | 63 |
while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:i", longopts, NULL)) != -1) {
|
| 64 | 64 |
switch (c) {
|
| 65 | 65 |
case 'v': |
| 66 |
- printf("%s " VERSION " © 2014-2018 John Hawthorn\n", argv[0]);
|
|
| 66 |
+ printf("%s " VERSION " © 2014-2025 John Hawthorn\n", argv[0]);
|
|
| 67 | 67 |
exit(EXIT_SUCCESS); |
| 68 | 68 |
case 's': |
| 69 | 69 |
options->show_scores = 1; |
| ... | ... |
@@ -19,6 +19,7 @@ static const char *usage_str = |
| 19 | 19 |
" -s, --show-scores Show the scores of each match\n" |
| 20 | 20 |
" -0, --read-null Read input delimited by ASCII NUL characters\n" |
| 21 | 21 |
" -j, --workers NUM Use NUM workers for searching. (default is # of CPUs)\n" |
| 22 |
+ " -i, --show-info Show selection info line\n" |
|
| 22 | 23 |
" -h, --help Display this help and exit\n" |
| 23 | 24 |
" -v, --version Output version information and exit\n"; |
| 24 | 25 |
|
| ... | ... |
@@ -36,6 +37,7 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
|
| 36 | 37 |
{"version", no_argument, NULL, 'v'},
|
| 37 | 38 |
{"benchmark", optional_argument, NULL, 'b'},
|
| 38 | 39 |
{"workers", required_argument, NULL, 'j'},
|
| 40 |
+ {"show-info", no_argument, NULL, 'i'},
|
|
| 39 | 41 |
{"help", no_argument, NULL, 'h'},
|
| 40 | 42 |
{NULL, 0, NULL, 0}};
|
| 41 | 43 |
|
| ... | ... |
@@ -51,13 +53,14 @@ void options_init(options_t *options) {
|
| 51 | 53 |
options->prompt = DEFAULT_PROMPT; |
| 52 | 54 |
options->workers = DEFAULT_WORKERS; |
| 53 | 55 |
options->input_delimiter = '\n'; |
| 56 |
+ options->show_info = DEFAULT_SHOW_INFO; |
|
| 54 | 57 |
} |
| 55 | 58 |
|
| 56 | 59 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| 57 | 60 |
options_init(options); |
| 58 | 61 |
|
| 59 | 62 |
int c; |
| 60 |
- while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:", longopts, NULL)) != -1) {
|
|
| 63 |
+ while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:i", longopts, NULL)) != -1) {
|
|
| 61 | 64 |
switch (c) {
|
| 62 | 65 |
case 'v': |
| 63 | 66 |
printf("%s " VERSION " © 2014-2018 John Hawthorn\n", argv[0]);
|
| ... | ... |
@@ -108,6 +111,9 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 108 | 111 |
} |
| 109 | 112 |
options->num_lines = l; |
| 110 | 113 |
} break; |
| 114 |
+ case 'i': |
|
| 115 |
+ options->show_info = 1; |
|
| 116 |
+ break; |
|
| 111 | 117 |
case 'h': |
| 112 | 118 |
default: |
| 113 | 119 |
usage(argv[0]); |
| ... | ... |
@@ -41,16 +41,16 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
|
| 41 | 41 |
|
| 42 | 42 |
void options_init(options_t *options) {
|
| 43 | 43 |
/* set defaults */ |
| 44 |
- options->benchmark = 0; |
|
| 45 |
- options->filter = NULL; |
|
| 46 |
- options->init_search = NULL; |
|
| 47 |
- options->show_scores = 0; |
|
| 48 |
- options->scrolloff = 1; |
|
| 49 |
- options->tty_filename = DEFAULT_TTY; |
|
| 50 |
- options->num_lines = DEFAULT_NUM_LINES; |
|
| 51 |
- options->prompt = DEFAULT_PROMPT; |
|
| 52 |
- options->workers = DEFAULT_WORKERS; |
|
| 53 |
- options->read_null = 0; |
|
| 44 |
+ options->benchmark = 0; |
|
| 45 |
+ options->filter = NULL; |
|
| 46 |
+ options->init_search = NULL; |
|
| 47 |
+ options->show_scores = 0; |
|
| 48 |
+ options->scrolloff = 1; |
|
| 49 |
+ options->tty_filename = DEFAULT_TTY; |
|
| 50 |
+ options->num_lines = DEFAULT_NUM_LINES; |
|
| 51 |
+ options->prompt = DEFAULT_PROMPT; |
|
| 52 |
+ options->workers = DEFAULT_WORKERS; |
|
| 53 |
+ options->input_delimiter = '\n'; |
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| ... | ... |
@@ -66,7 +66,7 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 66 | 66 |
options->show_scores = 1; |
| 67 | 67 |
break; |
| 68 | 68 |
case '0': |
| 69 |
- options->read_null = 1; |
|
| 69 |
+ options->input_delimiter = '\0'; |
|
| 70 | 70 |
break; |
| 71 | 71 |
case 'q': |
| 72 | 72 |
options->init_search = optarg; |
Update tty to print newline as space
Add tty_putc
| ... | ... |
@@ -17,6 +17,7 @@ static const char *usage_str = |
| 17 | 17 |
" -e, --show-matches=QUERY Output the sorted matches of QUERY\n" |
| 18 | 18 |
" -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" |
| 19 | 19 |
" -s, --show-scores Show the scores of each match\n" |
| 20 |
+ " -0, --read-null Read input delimited by ASCII NUL characters\n" |
|
| 20 | 21 |
" -j, --workers NUM Use NUM workers for searching. (default is # of CPUs)\n" |
| 21 | 22 |
" -h, --help Display this help and exit\n" |
| 22 | 23 |
" -v, --version Output version information and exit\n"; |
| ... | ... |
@@ -31,6 +32,7 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
|
| 31 | 32 |
{"tty", required_argument, NULL, 't'},
|
| 32 | 33 |
{"prompt", required_argument, NULL, 'p'},
|
| 33 | 34 |
{"show-scores", no_argument, NULL, 's'},
|
| 35 |
+ {"read-null", no_argument, NULL, '0'},
|
|
| 34 | 36 |
{"version", no_argument, NULL, 'v'},
|
| 35 | 37 |
{"benchmark", optional_argument, NULL, 'b'},
|
| 36 | 38 |
{"workers", required_argument, NULL, 'j'},
|
| ... | ... |
@@ -48,13 +50,14 @@ void options_init(options_t *options) {
|
| 48 | 50 |
options->num_lines = DEFAULT_NUM_LINES; |
| 49 | 51 |
options->prompt = DEFAULT_PROMPT; |
| 50 | 52 |
options->workers = DEFAULT_WORKERS; |
| 53 |
+ options->read_null = 0; |
|
| 51 | 54 |
} |
| 52 | 55 |
|
| 53 | 56 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| 54 | 57 |
options_init(options); |
| 55 | 58 |
|
| 56 | 59 |
int c; |
| 57 |
- while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) {
|
|
| 60 |
+ while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:", longopts, NULL)) != -1) {
|
|
| 58 | 61 |
switch (c) {
|
| 59 | 62 |
case 'v': |
| 60 | 63 |
printf("%s " VERSION " © 2014-2018 John Hawthorn\n", argv[0]);
|
| ... | ... |
@@ -62,6 +65,9 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 62 | 65 |
case 's': |
| 63 | 66 |
options->show_scores = 1; |
| 64 | 67 |
break; |
| 68 |
+ case '0': |
|
| 69 |
+ options->read_null = 1; |
|
| 70 |
+ break; |
|
| 65 | 71 |
case 'q': |
| 66 | 72 |
options->init_search = optarg; |
| 67 | 73 |
break; |
| ... | ... |
@@ -6,6 +6,8 @@ |
| 6 | 6 |
|
| 7 | 7 |
#include "options.h" |
| 8 | 8 |
|
| 9 |
+#include "../config.h" |
|
| 10 |
+ |
|
| 9 | 11 |
static const char *usage_str = |
| 10 | 12 |
"" |
| 11 | 13 |
"Usage: fzy [OPTION]...\n" |
| ... | ... |
@@ -37,15 +39,15 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
|
| 37 | 39 |
|
| 38 | 40 |
void options_init(options_t *options) {
|
| 39 | 41 |
/* set defaults */ |
| 40 |
- options->benchmark = 0; |
|
| 41 |
- options->filter = NULL; |
|
| 42 |
- options->init_search = NULL; |
|
| 43 |
- options->tty_filename = "/dev/tty"; |
|
| 44 |
- options->show_scores = 0; |
|
| 45 |
- options->num_lines = 10; |
|
| 46 |
- options->scrolloff = 1; |
|
| 47 |
- options->prompt = "> "; |
|
| 48 |
- options->workers = 0; |
|
| 42 |
+ options->benchmark = 0; |
|
| 43 |
+ options->filter = NULL; |
|
| 44 |
+ options->init_search = NULL; |
|
| 45 |
+ options->show_scores = 0; |
|
| 46 |
+ options->scrolloff = 1; |
|
| 47 |
+ options->tty_filename = DEFAULT_TTY; |
|
| 48 |
+ options->num_lines = DEFAULT_NUM_LINES; |
|
| 49 |
+ options->prompt = DEFAULT_PROMPT; |
|
| 50 |
+ options->workers = DEFAULT_WORKERS; |
|
| 49 | 51 |
} |
| 50 | 52 |
|
| 51 | 53 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| ... | ... |
@@ -55,7 +55,7 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 55 | 55 |
while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) {
|
| 56 | 56 |
switch (c) {
|
| 57 | 57 |
case 'v': |
| 58 |
- printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]);
|
|
| 58 |
+ printf("%s " VERSION " © 2014-2018 John Hawthorn\n", argv[0]);
|
|
| 59 | 59 |
exit(EXIT_SUCCESS); |
| 60 | 60 |
case 's': |
| 61 | 61 |
options->show_scores = 1; |
Also shorten help to fit 80 characters wide terminal.
| ... | ... |
@@ -15,7 +15,7 @@ static const char *usage_str = |
| 15 | 15 |
" -e, --show-matches=QUERY Output the sorted matches of QUERY\n" |
| 16 | 16 |
" -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" |
| 17 | 17 |
" -s, --show-scores Show the scores of each match\n" |
| 18 |
- " -j, --workers NUM Use NUM workers for searching. (default is number of CPU threads)\n" |
|
| 18 |
+ " -j, --workers NUM Use NUM workers for searching. (default is # of CPUs)\n" |
|
| 19 | 19 |
" -h, --help Display this help and exit\n" |
| 20 | 20 |
" -v, --version Output version information and exit\n"; |
| 21 | 21 |
|
| ... | ... |
@@ -15,6 +15,7 @@ static const char *usage_str = |
| 15 | 15 |
" -e, --show-matches=QUERY Output the sorted matches of QUERY\n" |
| 16 | 16 |
" -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" |
| 17 | 17 |
" -s, --show-scores Show the scores of each match\n" |
| 18 |
+ " -j, --workers NUM Use NUM workers for searching. (default is number of CPU threads)\n" |
|
| 18 | 19 |
" -h, --help Display this help and exit\n" |
| 19 | 20 |
" -v, --version Output version information and exit\n"; |
| 20 | 21 |
|
| ... | ... |
@@ -44,13 +45,14 @@ void options_init(options_t *options) {
|
| 44 | 45 |
options->num_lines = 10; |
| 45 | 46 |
options->scrolloff = 1; |
| 46 | 47 |
options->prompt = "> "; |
| 48 |
+ options->workers = 0; |
|
| 47 | 49 |
} |
| 48 | 50 |
|
| 49 | 51 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| 50 | 52 |
options_init(options); |
| 51 | 53 |
|
| 52 | 54 |
int c; |
| 53 |
- while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) {
|
|
| 55 |
+ while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) {
|
|
| 54 | 56 |
switch (c) {
|
| 55 | 57 |
case 'v': |
| 56 | 58 |
printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]);
|
| ... | ... |
@@ -80,6 +82,12 @@ void options_parse(options_t *options, int argc, char *argv[]) {
|
| 80 | 82 |
case 'p': |
| 81 | 83 |
options->prompt = optarg; |
| 82 | 84 |
break; |
| 85 |
+ case 'j': |
|
| 86 |
+ if (sscanf(optarg, "%u", &options->workers) != 1) {
|
|
| 87 |
+ usage(argv[0]); |
|
| 88 |
+ exit(EXIT_FAILURE); |
|
| 89 |
+ } |
|
| 90 |
+ break; |
|
| 83 | 91 |
case 'l': {
|
| 84 | 92 |
int l; |
| 85 | 93 |
if (!strcmp(optarg, "max")) {
|
| ... | ... |
@@ -30,10 +30,11 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
|
| 30 | 30 |
{"show-scores", no_argument, NULL, 's'},
|
| 31 | 31 |
{"version", no_argument, NULL, 'v'},
|
| 32 | 32 |
{"benchmark", optional_argument, NULL, 'b'},
|
| 33 |
+ {"workers", required_argument, NULL, 'j'},
|
|
| 33 | 34 |
{"help", no_argument, NULL, 'h'},
|
| 34 | 35 |
{NULL, 0, NULL, 0}};
|
| 35 | 36 |
|
| 36 |
-void options_set_defaults(options_t *options) {
|
|
| 37 |
+void options_init(options_t *options) {
|
|
| 37 | 38 |
/* set defaults */ |
| 38 | 39 |
options->benchmark = 0; |
| 39 | 40 |
options->filter = NULL; |
| ... | ... |
@@ -46,7 +47,7 @@ void options_set_defaults(options_t *options) {
|
| 46 | 47 |
} |
| 47 | 48 |
|
| 48 | 49 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| 49 |
- options_set_defaults(options); |
|
| 50 |
+ options_init(options); |
|
| 50 | 51 |
|
| 51 | 52 |
int c; |
| 52 | 53 |
while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) {
|
This fixes issues on ARM, where char is unsigned.
| ... | ... |
@@ -48,7 +48,7 @@ void options_set_defaults(options_t *options) {
|
| 48 | 48 |
void options_parse(options_t *options, int argc, char *argv[]) {
|
| 49 | 49 |
options_set_defaults(options); |
| 50 | 50 |
|
| 51 |
- char c; |
|
| 51 |
+ int c; |
|
| 52 | 52 |
while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) {
|
| 53 | 53 |
switch (c) {
|
| 54 | 54 |
case 'v': |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,104 @@ |
| 1 |
+#include <getopt.h> |
|
| 2 |
+#include <limits.h> |
|
| 3 |
+#include <stdio.h> |
|
| 4 |
+#include <stdlib.h> |
|
| 5 |
+#include <string.h> |
|
| 6 |
+ |
|
| 7 |
+#include "options.h" |
|
| 8 |
+ |
|
| 9 |
+static const char *usage_str = |
|
| 10 |
+ "" |
|
| 11 |
+ "Usage: fzy [OPTION]...\n" |
|
| 12 |
+ " -l, --lines=LINES Specify how many lines of results to show (default 10)\n" |
|
| 13 |
+ " -p, --prompt=PROMPT Input prompt (default '> ')\n" |
|
| 14 |
+ " -q, --query=QUERY Use QUERY as the initial search string\n" |
|
| 15 |
+ " -e, --show-matches=QUERY Output the sorted matches of QUERY\n" |
|
| 16 |
+ " -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" |
|
| 17 |
+ " -s, --show-scores Show the scores of each match\n" |
|
| 18 |
+ " -h, --help Display this help and exit\n" |
|
| 19 |
+ " -v, --version Output version information and exit\n"; |
|
| 20 |
+ |
|
| 21 |
+static void usage(const char *argv0) {
|
|
| 22 |
+ fprintf(stderr, usage_str, argv0); |
|
| 23 |
+} |
|
| 24 |
+ |
|
| 25 |
+static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'},
|
|
| 26 |
+ {"query", required_argument, NULL, 'q'},
|
|
| 27 |
+ {"lines", required_argument, NULL, 'l'},
|
|
| 28 |
+ {"tty", required_argument, NULL, 't'},
|
|
| 29 |
+ {"prompt", required_argument, NULL, 'p'},
|
|
| 30 |
+ {"show-scores", no_argument, NULL, 's'},
|
|
| 31 |
+ {"version", no_argument, NULL, 'v'},
|
|
| 32 |
+ {"benchmark", optional_argument, NULL, 'b'},
|
|
| 33 |
+ {"help", no_argument, NULL, 'h'},
|
|
| 34 |
+ {NULL, 0, NULL, 0}};
|
|
| 35 |
+ |
|
| 36 |
+void options_set_defaults(options_t *options) {
|
|
| 37 |
+ /* set defaults */ |
|
| 38 |
+ options->benchmark = 0; |
|
| 39 |
+ options->filter = NULL; |
|
| 40 |
+ options->init_search = NULL; |
|
| 41 |
+ options->tty_filename = "/dev/tty"; |
|
| 42 |
+ options->show_scores = 0; |
|
| 43 |
+ options->num_lines = 10; |
|
| 44 |
+ options->scrolloff = 1; |
|
| 45 |
+ options->prompt = "> "; |
|
| 46 |
+} |
|
| 47 |
+ |
|
| 48 |
+void options_parse(options_t *options, int argc, char *argv[]) {
|
|
| 49 |
+ options_set_defaults(options); |
|
| 50 |
+ |
|
| 51 |
+ char c; |
|
| 52 |
+ while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) {
|
|
| 53 |
+ switch (c) {
|
|
| 54 |
+ case 'v': |
|
| 55 |
+ printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]);
|
|
| 56 |
+ exit(EXIT_SUCCESS); |
|
| 57 |
+ case 's': |
|
| 58 |
+ options->show_scores = 1; |
|
| 59 |
+ break; |
|
| 60 |
+ case 'q': |
|
| 61 |
+ options->init_search = optarg; |
|
| 62 |
+ break; |
|
| 63 |
+ case 'e': |
|
| 64 |
+ options->filter = optarg; |
|
| 65 |
+ break; |
|
| 66 |
+ case 'b': |
|
| 67 |
+ if (optarg) {
|
|
| 68 |
+ if (sscanf(optarg, "%d", &options->benchmark) != 1) {
|
|
| 69 |
+ usage(argv[0]); |
|
| 70 |
+ exit(EXIT_FAILURE); |
|
| 71 |
+ } |
|
| 72 |
+ } else {
|
|
| 73 |
+ options->benchmark = 100; |
|
| 74 |
+ } |
|
| 75 |
+ break; |
|
| 76 |
+ case 't': |
|
| 77 |
+ options->tty_filename = optarg; |
|
| 78 |
+ break; |
|
| 79 |
+ case 'p': |
|
| 80 |
+ options->prompt = optarg; |
|
| 81 |
+ break; |
|
| 82 |
+ case 'l': {
|
|
| 83 |
+ int l; |
|
| 84 |
+ if (!strcmp(optarg, "max")) {
|
|
| 85 |
+ l = INT_MAX; |
|
| 86 |
+ } else if (sscanf(optarg, "%d", &l) != 1 || l < 3) {
|
|
| 87 |
+ fprintf(stderr, "Invalid format for --lines: %s\n", optarg); |
|
| 88 |
+ fprintf(stderr, "Must be integer in range 3..\n"); |
|
| 89 |
+ usage(argv[0]); |
|
| 90 |
+ exit(EXIT_FAILURE); |
|
| 91 |
+ } |
|
| 92 |
+ options->num_lines = l; |
|
| 93 |
+ } break; |
|
| 94 |
+ case 'h': |
|
| 95 |
+ default: |
|
| 96 |
+ usage(argv[0]); |
|
| 97 |
+ exit(EXIT_SUCCESS); |
|
| 98 |
+ } |
|
| 99 |
+ } |
|
| 100 |
+ if (optind != argc) {
|
|
| 101 |
+ usage(argv[0]); |
|
| 102 |
+ exit(EXIT_FAILURE); |
|
| 103 |
+ } |
|
| 104 |
+} |