Exemple #1
0
bool
open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool refresh, const char *notice)
{
	bool ok;

	if (silent) {
		ok = io_run_bg(argv, dir);

	} else {
		endwin();                  /* restore original tty modes */
		ok = io_run_fg(argv, dir);
		if (confirm || !ok) {
			if (!ok && *notice)
				fprintf(stderr, "%s", notice);
			if (!is_script_executing()) {
				fprintf(stderr, "Press Enter to continue");
				getc(opt_tty);
			}
		}
	}

	if (watch_update(WATCH_EVENT_AFTER_COMMAND) && refresh) {
		struct view *view;
		int i;

		foreach_displayed_view (view, i) {
			if (watch_dirty(&view->watch))
				refresh_view(view);
		}
	}
	redraw_display(true);
	return ok;
}
Exemple #2
0
bool
update_index(void)
{
    const char *update_index_argv[] = {
        "git", "update-index", "-q", "--unmerged", "--refresh", NULL
    };

    return io_run_bg(update_index_argv, repo.cdup);
}
Exemple #3
0
bool
open_external_viewer(const char *argv[], const char *dir, bool silent, bool confirm, bool echo, bool refresh, const char *notice)
{
	bool ok;

	if (echo) {
		char buf[SIZEOF_STR] = "";

		io_run_buf(argv, buf, sizeof(buf), dir, false);
		if (*buf) {
			report("%s", buf);
			return true;
		} else {
			report("No output");
			return false;
		}
	} else if (silent || is_script_executing()) {
		ok = io_run_bg(argv, dir);

	} else {
		clear();
		refresh();
		endwin();                  /* restore original tty modes */
		ok = io_run_fg(argv, dir);
		if (confirm || !ok) {
			if (!ok && *notice)
				fprintf(stderr, "%s", notice);
			fprintf(stderr, "Press Enter to continue");
			getc(opt_tty);
			fseek(opt_tty, 0, SEEK_END);
		}
		set_terminal_modes();
	}

	if (watch_update(WATCH_EVENT_AFTER_COMMAND) && refresh) {
		struct view *view;
		int i;

		foreach_displayed_view (view, i) {
			if (watch_dirty(&view->watch))
				refresh_view(view);
		}
	}
	redraw_display(true);
	return ok;
}
Exemple #4
0
Fichier : tig.c Projet : lcd047/tig
static enum request
open_run_request(struct view *view, enum request request)
{
	struct run_request *req = get_run_request(request);
	const char **argv = NULL;
	bool confirmed = FALSE;

	request = REQ_NONE;

	if (!req) {
		report("Unknown run request");
		return request;
	}

	if (argv_format(view->env, &argv, req->argv, FALSE, TRUE)) {
		if (req->internal) {
			char cmd[SIZEOF_STR];

			if (argv_to_string(argv, cmd, sizeof(cmd), " ")) {
				request = run_prompt_command(view, cmd);
			}
		}
		else {
			confirmed = !req->confirm;

			if (req->confirm) {
				char cmd[SIZEOF_STR], prompt[SIZEOF_STR];
				const char *and_exit = req->exit ? " and exit" : "";

				if (argv_to_string(argv, cmd, sizeof(cmd), " ") &&
				    string_format(prompt, "Run `%s`%s?", cmd, and_exit) &&
				    prompt_yesno(prompt)) {
					confirmed = TRUE;
				}
			}

			if (confirmed && argv_remove_quotes(argv)) {
				if (req->silent)
					io_run_bg(argv);
				else
					open_external_viewer(argv, NULL, !req->exit, "");
			}
		}
	}

	if (argv)
		argv_free(argv);
	free(argv);

	if (request == REQ_NONE) {
		if (req->confirm && !confirmed)
			request = REQ_NONE;

		else if (req->exit)
			request = REQ_QUIT;

		else if (view_has_flags(view, VIEW_REFRESH) && !view->unrefreshable)
			request = REQ_REFRESH;
	}
	return request;
}