Add scr.wheelspeed and implement dynamic asm.lineswidth in scr.responsive

This commit is contained in:
pancake 2015-02-11 00:13:04 +01:00
parent 1deb6eddde
commit 18c451f2c2
5 changed files with 47 additions and 31 deletions

View File

@ -173,6 +173,7 @@ R_API RCons *r_cons_new () {
I.teefile = NULL;
I.fix_columns = 0;
I.fix_rows = 0;
I.mouse_event = 0;
I.force_rows = 0;
I.force_columns = 0;
I.event_resize = NULL;
@ -296,7 +297,7 @@ R_API void r_cons_clear_line(int std_err) {
if (I.columns<sizeof (white))
white[I.columns-1] = 0;
else white[sizeof (white)-1] = 0; // HACK
fprintf (std_err? stderr:stdout, "\r%s\r", white);
fprintf (std_err? stderr: stdout, "\r%s\r", white);
#else
fprintf (std_err? stderr: stdout,"\x1b[0K\r");
#endif

View File

@ -40,6 +40,7 @@ R_API int r_cons_controlz(int ch) {
}
R_API int r_cons_arrow_to_hjkl(int ch) {
I->mouse_event = 0;
/* emacs */
switch ((ut8)ch) {
case 0xc3: r_cons_readchar(); ch='K'; break; // emacs repag (alt + v)
@ -151,6 +152,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) {
} else
if (ch >= 64 + 32) {
/* Grab wheel events only */
I->mouse_event = 1;
ch = "kj"[(ch - (64 + 32))&1];
} else {
// temporary disable the mouse wheel to allow select

View File

@ -1156,6 +1156,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF("scr.responsive", "false", "Auto-adjust Visual depending on screen (disable asm.bytes and other)");
#endif
SETPREF("scr.wheel", "true", "Enable the use of mouse wheel in visual mode");
SETI("scr.wheelspeed", 1, "mouse wheel speed");
// DEPRECATED: USES hex.cols now SETI("scr.colpos", 80, "Column position of cmd.cprompt in visual");
SETICB("scr.columns", 0, &cb_scrcolumns, "Set the columns number");
SETICB("scr.rows", 0, &cb_rows, "Force specific console rows (height)");

View File

@ -533,9 +533,17 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
ut64 offset = core->offset;
char buf[4096];
int i, ret, offscreen, cols = core->print->cols, delta = 0;
int wheelspeed;
ch = r_cons_arrow_to_hjkl (ch);
ch = visual_nkey (core, ch);
if (ch<2) return 1;
if (r_cons_singleton()->mouse_event) {
wheelspeed = r_config_get_i (core->config, "scr.wheelspeed");
} else {
wheelspeed = 1;
}
// do we need hotkeys for data references? not only calls?
if (ch>='0'&& ch<='9') {
@ -556,15 +564,17 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
switch (ch) {
case 0x0d:
{
RAnalOp *op;
int wheel = r_config_get_i (core->config, "scr.wheel");
if (wheel)
r_cons_enable_mouse (R_TRUE);
RAnalOp *op = r_core_anal_op (core, core->offset+cursor);
if (op) {
if (op->type == R_ANAL_OP_TYPE_JMP ||
op->type == R_ANAL_OP_TYPE_CJMP ||
op->type == R_ANAL_OP_TYPE_CALL ||
op->type == R_ANAL_OP_TYPE_CCALL) {
do {
op = r_core_anal_op (core, core->offset+cursor);
if (op) {
if (op->type == R_ANAL_OP_TYPE_JMP ||
op->type == R_ANAL_OP_TYPE_CJMP ||
op->type == R_ANAL_OP_TYPE_CALL ||
op->type == R_ANAL_OP_TYPE_CCALL) {
if (curset) {
int delta = R_ABS ((st64)op->jump-(st64)offset);
if ( op->jump < core->offset || op->jump > last_printed_address) {
@ -576,11 +586,12 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
}
} else {
r_io_sundo_push (core->io, offset);
r_core_visual_seek_animation(core, op->jump);
r_core_visual_seek_animation (core, op->jump);
}
}
}
r_anal_op_free (op);
}
r_anal_op_free (op);
} while (--wheelspeed>0);
}
break;
case 90: // shift+tab
@ -979,23 +990,17 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
}
}
} else {
if (core->printidx == 1 || core->printidx == 2) {
cols = r_asm_disassemble (core->assembler,
&op, core->block, 32);
if (cols<1) cols = op.size;
if (cols<1) cols = 1;
#if 0
cols = core->inc;
//cols = r_asm_disassemble (core->assembler,
// &op, core->block+cursor, 32);
core->asmsteps[core->curasmstep].offset = core->offset+cols;
core->asmsteps[core->curasmstep].cols = cols;
if (core->curasmstep < R_CORE_ASMSTEPS-1)
core->curasmstep++;
else core->curasmstep = 0;
#endif
int times = wheelspeed;
if (times<1) times = 1;
while (times--) {
if (core->printidx == 1 || core->printidx == 2) {
cols = r_asm_disassemble (core->assembler,
&op, core->block, 32);
if (cols<1) cols = op.size;
if (cols<1) cols = 1;
}
r_core_seek (core, core->offset+cols, 1);
}
r_core_seek (core, core->offset+cols, 1);
}
break;
case 'J':
@ -1038,12 +1043,16 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
}
}
} else {
if (core->printidx == 1 || core->printidx == 2) {
cols = prevopsz (core, core->offset);
int times = wheelspeed;
if (times<1) times = 1;
while (times--) {
if (core->printidx == 1 || core->printidx == 2) {
cols = prevopsz (core, core->offset);
}
if (core->offset >= cols)
r_core_seek (core, core->offset-cols, 1);
else r_core_seek (core, 0, 1);
}
if (core->offset >= cols)
r_core_seek (core, core->offset-cols, 1);
else r_core_seek (core, 0, 1);
}
break;
case 'K':
@ -1453,6 +1462,8 @@ static void r_core_visual_refresh (RCore *core) {
}
if (w>80) {
r_config_set_i (core->config, "asm.lineswidth", 14);
r_config_set_i (core->config, "asm.lineswidth", w-(w/1.2));
r_config_set_i (core->config, "asm.cmtcol", w-(w/2.5));
} else {
r_config_set_i (core->config, "asm.lineswidth", 7);
}

View File

@ -150,6 +150,7 @@ typedef struct r_cons_t {
RConsEvent event_resize;
void *data;
void *event_data;
int mouse_event;
RConsEditorCallback editor;
void *user; // Used by <RCore*>