Skip to content
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

Merged
merged 12 commits into from Mar 8, 2018
30 changes: 30 additions & 0 deletions libr/cons/dietline.c
Expand Up @@ -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;
/*char line[R_LINE_BUFSIZE - 1];*/
Copy link
Contributor

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.

if (I.offset_index <= -undo->undos) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

}
I.offset_index--;
char *line = r_str_newf("0x%"PFMT64x, undo->seek[undo->idx + I.offset_index].off);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use space before (

strncpy(I.buffer.data, line, R_LINE_BUFSIZE - 1);
I.buffer.index = I.buffer.length = strlen (I.buffer.data);
return true;
}
if (I.history.index > 0) {
strncpy (I.buffer.data, I.history.data[--I.history.index], R_LINE_BUFSIZE - 1);
I.buffer.index = I.buffer.length = strlen (I.buffer.data);
Expand All @@ -325,6 +338,23 @@ static int r_line_hist_down() {
if (I.hist_down) {
return I.hist_down (I.user);
}
if (I.offset_prompt) {
RCore *core = I.user;
RIOUndo *undo = &core->io->undo;
if (I.offset_index >= undo->redos) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

}
I.offset_index++;
if (I.offset_index == undo->redos) {
I.buffer.data[0] = '\0';
I.buffer.index = I.buffer.length = 0;
return false;
}
char *line = r_str_newf("0x%"PFMT64x, undo->seek[undo->idx + I.offset_index].off);
strncpy(I.buffer.data, line, R_LINE_BUFSIZE - 1);
I.buffer.index = I.buffer.length = strlen (I.buffer.data);
return true;
}
I.buffer.index = 0;
if (!I.history.data) {
inithist ();
Expand Down
6 changes: 4 additions & 2 deletions libr/core/core.c
Expand Up @@ -1230,9 +1230,11 @@ static int autocomplete(RLine *line) {
|| !strncmp (line->buffer.data, "agfl ", 5)
|| !strncmp (line->buffer.data, "aecu ", 5)
|| !strncmp (line->buffer.data, "aesu ", 5)
|| !strncmp (line->buffer.data, "aeim ", 5)) {
|| !strncmp (line->buffer.data, "aeim ", 5)
|| line->offset_prompt) {
int n, i = 0;
int sdelta = (line->buffer.data[1] == ' ')
int sdelta = line->offset_prompt
? 0 : (line->buffer.data[1] == ' ')
? 2 : (line->buffer.data[2] == ' ')
? 3 : (line->buffer.data[3] == ' ')
? 4 : 5;
Expand Down
3 changes: 3 additions & 0 deletions libr/core/visual.c
Expand Up @@ -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;
Copy link
Collaborator

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?

strcpy (buf, "s ");
if (r_cons_fgets (buf + 2, sizeof (buf) - 3, 0, NULL) > 0) {
if (buf[2] == '.') {
buf[1] = '.';
}
r_core_cmd0 (core, buf);
reset_print_cur (core->print);
core->cons->line->offset_prompt = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions libr/include/r_cons.h
Expand Up @@ -796,6 +796,8 @@ struct r_line_t {
int (*hist_down)(void *user);
char *contents;
bool zerosep;
bool offset_prompt;
int offset_index;
}; /* RLine */

#ifdef R_API
Expand Down