Add scr.timeout covering the ^C blocks ##shell

This commit is contained in:
pancake 2024-02-28 16:48:53 +01:00 committed by GitHub
parent 3803f33f6c
commit 6b0032fa68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 6 deletions

View File

@ -446,10 +446,14 @@ R_API void r_cons_context_break_pop(RConsContext *context, bool sig) {
}
R_API void r_cons_break_push(RConsBreak cb, void *user) {
if (r_stack_size (C->break_stack) > 0) {
r_cons_break_timeout (I->otimeout);
}
r_cons_context_break_push (C, cb, user, true);
}
R_API void r_cons_break_pop(void) {
I->timeout = 0;
r_cons_context_break_pop (C, true);
}
@ -478,11 +482,12 @@ R_API bool r_cons_is_breaked(void) {
I->cb_break (I->user);
}
if (R_UNLIKELY (I->timeout)) {
if (r_time_now_mono () > I->timeout) {
C->breaked = true;
C->was_breaked = true;
eprintf ("\nTimeout!\n");
I->timeout = 0;
if (r_stack_size (C->break_stack) > 0) {
if (r_time_now_mono () > I->timeout) {
C->breaked = true;
C->was_breaked = true;
r_cons_break_timeout (I->otimeout);
}
}
}
if (R_UNLIKELY (!C->was_breaked)) {
@ -539,8 +544,17 @@ R_API int r_cons_get_cur_line(void) {
}
R_API void r_cons_break_timeout(int timeout) {
if (timeout > 0) {
I->timeout = r_time_now_mono () + (timeout * 1000);
I->otimeout = timeout;
} else {
I->otimeout = 0;
I->timeout = 0;
}
#if 0
I->timeout = (timeout && !I->timeout)
? r_time_now_mono () + ((ut64) timeout << 20) : 0;
#endif
}
R_API void r_cons_break_end(void) {

View File

@ -2457,6 +2457,12 @@ static bool cb_scroptimize(void* user, void* data) {
return true;
}
static bool cb_scrtimeout(void* user, void* data) {
RConfigNode *node = (RConfigNode*) data;
r_cons_break_timeout (node->i_value);
return true;
}
static bool cb_scrcolumns(void* user, void* data) {
RConfigNode *node = (RConfigNode*) data;
RCore *core = (RCore*) user;
@ -4287,6 +4293,7 @@ R_API int r_core_config_init(RCore *core) {
SETCB ("scr.gadgets", "true", &cb_scr_gadgets, "run pg in prompt, visual and panels");
SETBPREF ("scr.panelborder", "false", "specify panels border active area (0 by default)");
SETCB ("scr.theme", "default", &cb_scrtheme, "specify the theme name to load on startup (See 'ec?')");
SETICB ("scr.timeout", 0, &cb_scrtimeout, "check for timeout during the break.(push|pop) contexts");
SETICB ("scr.cols", 0, &cb_scrcolumns, "force console column count (width)");
SETICB ("scr.optimize", 0, &cb_scroptimize, "optimize the amount of ansi escapes and spaces (0, 1, 2 passes)");
SETBPREF ("scr.dumpcols", "false", "prefer pC commands before p ones");

View File

@ -543,7 +543,8 @@ typedef struct r_cons_t {
int maxpage;
char *break_word;
int break_word_len;
ut64 timeout; // must come from r_time_now_mono()
ut64 timeout;
int otimeout;
char* (*rgbstr)(char *str, size_t sz, ut64 addr);
bool click_set;
int click_x;