New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Offset history #9591
Offset history #9591
Conversation
libr/cons/dietline.c
Outdated
@@ -313,6 +313,13 @@ static int r_line_hist_up() { | |||
if (!I.history.data) { | |||
inithist (); | |||
} | |||
if (strcmp(r_line_get_prompt(), "[offset]> ") == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ! Instead of ==0 and add space before (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm this strcmp is kind of a hack, prompt shouldnt change the behaviour
We should use a different history for the offset and the shell prompt, or just disable the history to avoid unexpected behaviour, Also, theres an issue discussing about removing Vo because i odnt know how many people use it. I mainly do V:s... |
What about using the seek history? (The one that can be scrolled using
I agree completely with that, in fact in the PR statement I suggested to add a boolean flag to control this behaviour, but I was waiting for the opinion of a more expert developer.
If you think this command is likely going to be removed, please state so because than this PR is useless and I'll close it. In the meantime I fixed according to your reviews. |
On 5 Mar 2018, at 18:36, cyanpencil ***@***.***> wrote:
We should use a different history for the offset and the shell prompt, or just disable the history to avoid unexpected behaviour
What about using the seek history? (The one that can be scrolled using s+ and s-)
yep, sounds good to me
Uhm this strcmp is kind of a hack, prompt shouldnt change the behaviour
I agree completely with that, in fact in the PR statement I suggested to add a boolean flag to control this behaviour, but I was waiting for the opinion of a more expert developer.
Also, theres an issue discussing about removing Vo because i odnt know how many people use it. I mainly do V:s...
If you think this command is likely going to be removed, please state so because than this PR is useless and I'll close it.
In the meantime I fixed according to your reviews.
+1
… —
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#9591 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA3-lsrtApduOZgVR539JaxakzWEktrmks5tbXeGgaJpZM4SclVM>.
|
Using "o" is shorter and with this just seek history will be useful to filter out unneeded things. I think we can keep that, afair @Maijin is also using 'Vo' |
Yeah Vo is nice |
Also while you are on it - can you please add also the TAB auto-completion for the offsets, like it is done for |
@cyanpencil ping |
Sorry for the silence, I had some urgent college homework. I'll start working on it in a couple of hours, I think I'll finish before tomorrow.
No problem 👍 |
I think I have finished. |
|
And one more, when you list the history in |
libr/cons/dietline.c
Outdated
@@ -325,6 +338,24 @@ static int r_line_hist_down() { | |||
if (I.hist_down) { | |||
return I.hist_down (I.user); | |||
} | |||
if (I.offset_prompt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use tabs. not spaces
libr/cons/dietline.c
Outdated
return false; | ||
} | ||
char line[R_LINE_BUFSIZE - 1]; | ||
sprintf(line, "0x%"PFMT64x, undo->seek[undo->idx + I.offset_index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use snprintf or r_str_newf and avoid abusing the stack with this char line[R_LINE_BUFSIZE] because to fill a PFMT64x you dont need more than 64 bytes. not 4096
libr/cons/dietline.c
Outdated
if (I.offset_prompt) { | ||
RCore *core = I.user; | ||
RIOUndo *undo = &core->io->undo; | ||
char line[R_LINE_BUFSIZE - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont do 4096 in the stack. you only need 64bytes to do an snprintf of pfmt64x
libr/cons/dietline.c
Outdated
@@ -313,6 +313,19 @@ static int r_line_hist_up() { | |||
if (!I.history.data) { | |||
inithist (); | |||
} | |||
if (I.offset_prompt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally the solution should be to delegate the logic of the history to the caller, not embed that in here
libr/cons/dietline.c
Outdated
@@ -313,6 +313,19 @@ static int r_line_hist_up() { | |||
if (!I.history.data) { | |||
inithist (); | |||
} | |||
if (I.offset_prompt) { | |||
RCore *core = I.user; | |||
RIOUndo *undo = &core->io->undo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rcons shouldnt have access to core or io
libr/core/visual.c
Outdated
@@ -845,13 +845,16 @@ static void reset_print_cur(RPrint *p) { | |||
static void visual_offset(RCore *core) { | |||
char buf[256]; | |||
r_line_set_prompt ("[offset]> "); | |||
core->cons->line->offset_prompt = true; | |||
core->cons->line->offset_index = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about doing: r_line_set_history_callback() and implement the logic of offset_prompt in here?
Pancake, thank you for your useful reviews. I fixed the whitespace and changed sprintf to r_str_newf as you suggested.
Yes, I have an idea on how to do that. I was thinking about using |
libr/cons/dietline.c
Outdated
if (I.offset_prompt) { | ||
RCore *core = I.user; | ||
RIOUndo *undo = &core->io->undo; | ||
/*char line[R_LINE_BUFSIZE - 1];*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not used - remove it.
libr/cons/dietline.c
Outdated
RIOUndo *undo = &core->io->undo; | ||
/*char line[R_LINE_BUFSIZE - 1];*/ | ||
if (I.offset_index <= -undo->undos) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation
libr/cons/dietline.c
Outdated
return false; | ||
} | ||
I.offset_index--; | ||
char *line = r_str_newf("0x%"PFMT64x, undo->seek[undo->idx + I.offset_index].off); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use space before (
libr/cons/dietline.c
Outdated
RCore *core = I.user; | ||
RIOUndo *undo = &core->io->undo; | ||
if (I.offset_index >= undo->redos) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation
Sorry for the delay: I had more difficulty than expected with callbacks. I'm not totally sure about the positions I chose for those functions... (I chose to put Also, I added the fact that if a given offset matches a flag, the flag name is displayed instead of the numeric offset. I tried to remove In the final commit I also added the same functionality to offset prompt inside graph view. Again, thanks for the reviews; they help me improve a lot. |
🎉🎉🎉
… On 8 Mar 2018, at 23:47, cyanpencil ***@***.***> wrote:
Sorry for the delay: I had more difficulty than expected with callbacks.
Now r_line_hist_up() calls the callback I.history_up_cb(), which can be either cmd_history_up() or offset_history_up(), depending if we are in offset prompt mode or in normal command line mode. Viceversa for r_line_hist_down().
I'm not totally sure about the positions I chose for those functions... (I chose to put cmd_history_up inside dietline.c and offset_history_up() in visual.c for clarity; but I had to add #include <r_cons.h> inside visual.c). Please tell me if there is a better way to organize this piece of code.
Also, I added the fact that if a given offset matches a flag, the flag name is displayed instead of the numeric offset.
I tried to remove RCore *rcore = line->user to avoid RCons accessing RCore (and io); but I have no ideas on how to retrieve the seek history without it (because it is stored in core->io->undo->seek[])...
In the final commit I also added the same functionality to offset prompt inside graph view.
Again, thanks for the reviews; they help me improve a lot.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Closes #6756.
When pressing the arrow keys while in "offset mode" (after pressing 'o' in visual) the history will only show seek commands, and truncate them to show only the offset.
Before: asciinema
After: asciinema
Inside
r_line_hist_up()
, to check if r2 is in offset mode, I usedif (strcmp(r_line_get_prompt(), "[offset]> ") == 0) {...}
I know it's ugly, but it was just a test to see if it worked, as this is my first pull request here and I didn't want to change too much code without advice.
So, do you have any suggestions on how could I check more correctly if r2 is in "offset mode" or not?
I was thinking about adding a flag like
offset_prompt
to structRLine
, and then doingif (I.offset_prompt) {...}
to keep things as simple as possible, but please tell me if you have better ideas.
Feel free to tell me if it's wrong, I still have a lot to learn...