Skip to content

Commit

Permalink
POC refresh display on filesystem change via entr
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker committed Aug 17, 2017
1 parent aa4b1ac commit bcfa241
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ get_input(int prompt_position, struct key *key)
{
struct view *view;
int i, key_value, cursor_y, cursor_x;
static time_t last_winch = 0;
int winch_refresh_throttle = 1;

if (prompt_position > 0)
input_mode = true;
Expand Down Expand Up @@ -766,6 +768,21 @@ get_input(int prompt_position, struct key *key)

} else if (key_value == KEY_RESIZE) {
int height, width;
bool refs_refreshed = false;
time_t now = time(NULL);

if ((now - last_winch) >= winch_refresh_throttle) {
foreach_displayed_view (view, i) {
if (view_can_refresh(view)) {
if (!refs_refreshed) {
load_refs(true);
refs_refreshed = true;
}
refresh_view(view);
}
}
}
last_winch = now;

getmaxyx(stdscr, height, width);

Expand Down
19 changes: 19 additions & 0 deletions src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ die_if_failed(enum status_code code, const char *msg)
die("%s: %s", msg, get_status_message(code));
}

void
hangup_children(void)
{
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
return;
killpg(getpid(), SIGHUP);
}

int
main(int argc, const char *argv[])
{
Expand All @@ -722,6 +730,8 @@ main(int argc, const char *argv[])
enum request request = parse_options(argc, argv, pager_mode);
struct view *view;

atexit(hangup_children);

if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
die("Failed to setup signal handler");

Expand Down Expand Up @@ -768,6 +778,15 @@ main(int argc, const char *argv[])
run_prompt_command(NULL, script_command);
}

if (repo.git_dir[0]) {
const char *watcher_argv[] = { "sh", "-c", NULL, NULL };
char cmd[SIZEOF_STR] = "";
int restart_interval = 30; /* better would be 300 */
string_format(cmd, "(export TIG_PID=\"%d\"; export ENTR_RESTART_SEC=\"%d\"; test \"$TIG_PID\" -gt 0 || exit; which entr || exit; sleep 1; while true; do git ls-files \"$(git rev-parse --show-toplevel)\" | entr -d kill -WINCH \"$TIG_PID\" & export ENTR_PID=\"$!\"; (sleep \"$ENTR_RESTART_SEC\" && kill -INT \"$ENTR_PID\") & export RESTARTER_PID=\"$!\"; wait \"$ENTR_PID\"; kill -WINCH \"$TIG_PID\"; kill -HUP \"$RESTARTER_PID\"; sleep 1; kill -0 \"$TIG_PID\" || break; done) &", getpid(), restart_interval);
watcher_argv[2] = cmd;
io_run_bg(watcher_argv, repo.cdup);
}

while (view_driver(display[current_view], request)) {
view = display[current_view];
request = read_key_combo(view->keymap);
Expand Down
2 changes: 1 addition & 1 deletion test/main/filter-args-test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps '

test_tig --exclude=refs/remotes/origin/* --exclude=refs/heads/master --all -- common tracer

grep 'git rev-parse' < "$TIG_TRACE" > rev-parse.trace
grep 'git rev-parse' < "$TIG_TRACE" | grep -v 'TIG_PID' > rev-parse.trace
grep 'git log' < "$TIG_TRACE" > log.trace

assert_equals 'rev-parse.trace' <<EOF
Expand Down

0 comments on commit bcfa241

Please sign in to comment.