int show_jobs_menu(FileView *view) { job_t *p; #ifndef _WIN32 sigset_t new_mask; #endif int i; static menu_info m; init_menu_info(&m, JOBS, strdup("No jobs currently running")); m.title = strdup(" Pid --- Command "); /* * SIGCHLD needs to be blocked anytime the finished_jobs list * is accessed from anywhere except the received_sigchld(). */ #ifndef _WIN32 sigemptyset(&new_mask); sigaddset(&new_mask, SIGCHLD); sigprocmask(SIG_BLOCK, &new_mask, NULL); #else check_background_jobs(); #endif p = jobs; i = 0; while(p != NULL) { if(p->running) { char item_buf[strlen(p->cmd) + 24]; if(p->pid == -1) snprintf(item_buf, sizeof(item_buf), " %d/%d %s ", p->done + 1, p->total, p->cmd); else snprintf(item_buf, sizeof(item_buf), " " PRINTF_PID_T " %s ", p->pid, p->cmd); i = add_to_string_array(&m.items, i, 1, item_buf); } p = p->next; } #ifndef _WIN32 /* Unblock SIGCHLD signal. */ sigprocmask(SIG_UNBLOCK, &new_mask, NULL); #endif m.len = i; return display_menu(&m, view); }
int show_jobs_menu(FileView *view) { job_t *p; int i; static menu_info m; init_menu_info(&m, strdup("Pid --- Command"), strdup("No jobs currently running")); m.execute_handler = &execute_jobs_cb; check_background_jobs(); bg_jobs_freeze(); p = jobs; i = 0; while(p != NULL) { if(p->running) { char info_buf[24]; char item_buf[sizeof(info_buf) + strlen(p->cmd)]; if(p->type == BJT_COMMAND) { snprintf(info_buf, sizeof(info_buf), "%" PRINTF_ULL, (unsigned long long)p->pid); } else if(p->bg_op.total == BG_UNDEFINED_TOTAL) { snprintf(info_buf, sizeof(info_buf), "n/a"); } else { snprintf(info_buf, sizeof(info_buf), "%d/%d", p->bg_op.done + 1, p->bg_op.total); } snprintf(item_buf, sizeof(item_buf), "%-8s %s", info_buf, p->cmd); i = add_to_string_array(&m.items, i, 1, item_buf); } p = p->next; } bg_jobs_unfreeze(); m.len = i; return display_menu(&m, view); }
static int read_char(WINDOW *win, wint_t *c, int timeout) { static const int T = 150; static const int IPC_F = 10; int i; int result = ERR; for(i = 0; i <= timeout/T; i++) { int j; if(is_redraw_scheduled()) { modes_redraw(); } if(!is_status_bar_multiline() && !is_in_menu_like_mode() && get_mode() != CMDLINE_MODE) { check_if_filelists_have_changed(curr_view); if(curr_stats.number_of_windows != 1 && !curr_stats.view) check_if_filelists_have_changed(other_view); } check_background_jobs(); for(j = 0; j < IPC_F; j++) { ipc_check(); wtimeout(win, MIN(T, timeout)/IPC_F); if((result = wget_wch(win, c)) != ERR) break; if(is_redraw_scheduled()) { modes_redraw(); } } if(result != ERR) break; timeout -= T; } return result; }
static int read_char(WINDOW *win, wint_t *c, int timeout) { static const int T = 150; static const int IPC_F = 10; int i; int result = ERR; for(i = 0; i <= timeout/T; i++) { int j; process_scheduled_updates(); if(should_check_views_for_changes()) { check_view_for_changes(curr_view); check_view_for_changes(other_view); } check_background_jobs(); for(j = 0; j < IPC_F; j++) { ipc_check(); wtimeout(win, MIN(T, timeout)/IPC_F); if((result = wget_wch(win, c)) != ERR) { break; } process_scheduled_updates(); } if(result != ERR) { break; } timeout -= T; } return result; }
void event_loop(const int *quit) { /* TODO: refactor this function event_loop(). */ LOG_FUNC_ENTER; const wchar_t *const prev_input_buf = curr_input_buf; const size_t *const prev_input_buf_pos = curr_input_buf_pos; wchar_t input_buf[128]; size_t input_buf_pos; int last_result = 0; int wait_for_enter = 0; int timeout = cfg.timeout_len; input_buf[0] = L'\0'; input_buf_pos = 0; curr_input_buf = &input_buf[0]; curr_input_buf_pos = &input_buf_pos; while(!*quit) { wint_t c; size_t counter; int got_input; if(!ensure_term_is_ready()) { wait_for_enter = 0; continue; } lwin.user_selection = 1; rwin.user_selection = 1; modes_pre(); /* Waits for timeout then skips if no keypress. Short-circuit if we're not * waiting for the next key after timeout. */ do { modes_periodic(); check_background_jobs(); got_input = get_char_async_loop(status_bar, &c, timeout) != ERR; if(!got_input && input_buf_pos == 0) { timeout = cfg.timeout_len; continue; } break; } while(1); /* Ensure that current working directory is set correctly (some pieces of * code rely on this). */ (void)vifm_chdir(flist_get_dir(curr_view)); if(got_input) { if(wait_for_enter) { wait_for_enter = 0; curr_stats.save_msg = 0; clean_status_bar(); if(c == L'\x0d') { continue; } } if(c == L'\x1a') /* Ctrl-Z */ { def_prog_mode(); endwin(); stop_process(); continue; } if(input_buf_pos < ARRAY_LEN(input_buf) - 2) { input_buf[input_buf_pos++] = c; input_buf[input_buf_pos] = L'\0'; } else { /* Recover from input buffer overflow by resetting its contents. */ reset_input_buf(input_buf, &input_buf_pos); clear_input_bar(); continue; } } counter = get_key_counter(); if(!got_input && last_result == KEYS_WAIT_SHORT) { last_result = execute_keys_timed_out(input_buf); counter = get_key_counter() - counter; assert(counter <= input_buf_pos); if(counter > 0) { memmove(input_buf, input_buf + counter, (wcslen(input_buf) - counter + 1)*sizeof(wchar_t)); } } else { if(got_input) { curr_stats.save_msg = 0; } last_result = execute_keys(input_buf); counter = get_key_counter() - counter; assert(counter <= input_buf_pos); if(counter > 0) { input_buf_pos -= counter; memmove(input_buf, input_buf + counter, (wcslen(input_buf) - counter + 1)*sizeof(wchar_t)); } if(last_result == KEYS_WAIT || last_result == KEYS_WAIT_SHORT) { if(got_input) { modupd_input_bar(input_buf); } if(last_result == KEYS_WAIT_SHORT && wcscmp(input_buf, L"\033") == 0) { timeout = 1; } if(counter > 0) { clear_input_bar(); } if(!curr_stats.save_msg && curr_view->selected_files && !vle_mode_is(CMDLINE_MODE)) { print_selected_msg(); } continue; } } timeout = cfg.timeout_len; process_scheduled_updates(); reset_input_buf(input_buf, &input_buf_pos); clear_input_bar(); if(is_status_bar_multiline()) { wait_for_enter = 1; update_all_windows(); continue; } /* Ensure that current working directory is set correctly (some pieces of * code rely on this). PWD could be changed during command execution, but * it should be correct for modes_post() in case of preview modes. */ (void)vifm_chdir(flist_get_dir(curr_view)); modes_post(); } curr_input_buf = prev_input_buf; curr_input_buf_pos = prev_input_buf_pos; }