Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to keep TTY after exiting #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fzy.1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Non-interactive mode. Print the matches in sorted order for QUERY to stdout.
Read input delimited by ASCII NUL characters.
.
.TP
.BR \-n ", " \-\-do-not-clear-tty\fR
Don't clear TTY device after exiting.
.
.TP
.BR \-h ", " \-\-help
Usage help.
.
Expand Down
12 changes: 9 additions & 3 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ static const char *usage_str =
" -0, --read-null Read input delimited by ASCII NUL characters\n"
" -j, --workers NUM Use NUM workers for searching. (default is # of CPUs)\n"
" -i, --show-info Show selection info line\n"
" -h, --help Display this help and exit\n"
" -v, --version Output version information and exit\n";
" -n, --do-not-clear-tty Don't clear TTY device after exiting\n"
" -h, --help Display this help and exit\n"
" -v, --version Output version information and exit\n";

static void usage(const char *argv0) {
fprintf(stderr, usage_str, argv0);
Expand All @@ -38,6 +39,7 @@ static struct option longopts[] = {{"show-matches", required_argument, NULL, 'e'
{"benchmark", optional_argument, NULL, 'b'},
{"workers", required_argument, NULL, 'j'},
{"show-info", no_argument, NULL, 'i'},
{"do-not-clear-tty", no_argument, NULL, 'n'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};

Expand All @@ -54,13 +56,14 @@ void options_init(options_t *options) {
options->workers = DEFAULT_WORKERS;
options->input_delimiter = '\n';
options->show_info = DEFAULT_SHOW_INFO;
options->clear_after_exiting = 1;
}

void options_parse(options_t *options, int argc, char *argv[]) {
options_init(options);

int c;
while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:i", longopts, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "vhs0e:q:l:t:p:j:i:n", longopts, NULL)) != -1) {
switch (c) {
case 'v':
printf("%s " VERSION " © 2014-2018 John Hawthorn\n", argv[0]);
Expand Down Expand Up @@ -114,6 +117,9 @@ void options_parse(options_t *options, int argc, char *argv[]) {
case 'i':
options->show_info = 1;
break;
case 'n':
options->clear_after_exiting = 0;
break;
case 'h':
default:
usage(argv[0]);
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
unsigned int workers;
char input_delimiter;
int show_info;
unsigned int clear_after_exiting;
} options_t;

void options_init(options_t *options);
Expand Down
4 changes: 3 additions & 1 deletion src/tty_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ static void action_autocomplete(tty_interface_t *state) {
}

static void action_exit(tty_interface_t *state) {
clear(state);
if (state->options->clear_after_exiting) {
clear(state);
}
tty_close(state->tty);

state->exit = EXIT_FAILURE;
Expand Down