Skip to content

Commit

Permalink
Handle newline in summary panel to open page
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Sep 7, 2024
1 parent e25543e commit 67ba601
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
7 changes: 4 additions & 3 deletions plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ CFLAGS+=-g -fPIC
# CFLAGS+=-fsanitize=address

all:
$(CC) $(CFLAGS) $(R2_CFLAGS) $(R2_LDFLAGS) core_r2book.c -shared -o core_r2book.$(EXT_SO)
$(CC) $(CFLAGS) $(R2_CFLAGS) $(R2_LDFLAGS) \
core_r2book.c -shared -o core_r2book.$(EXT_SO)
$(MAKE) install

install:
user-install install:
mkdir -p $(R2_USER_PLUGINS)
cp *.$(EXT_SO) $(R2_USER_PLUGINS)

uninstall:
uninstall user-uninstall:
rm -f $(R2_USER_PLUGINS)/core_r2book.$(EXT_SO)
61 changes: 54 additions & 7 deletions plugin/core_r2book.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ static void r2book_view(RCore *core, const char *path) {
int scroll[2] = {0, 0};
reload:

free (index);
index = r2book_index_str (core);
free (body);
body = r2book_body_str (core, path);

char *firstline = NULL;
r_cons_enable_mouse (true);
while (!stop) {
int h, w = r_cons_get_size (&h);
Expand All @@ -241,11 +244,21 @@ static void r2book_view(RCore *core, const char *path) {
}
r_cons_println (".");
sb = r_str_append (sb, Color_RESET);
r_cons_printat (sb, split + 2, 1);
r_cons_printat (sb, split + 2, 2);
/// r_cons_print (Color_RESET);
r_cons_printat (si, 0, 3);
r_cons_line (split, 2, split + 1, h + 1, '|');
}
char *sinl = strchr (si, '*');
if (sinl) {
free (firstline);
firstline = strdup (r_str_trim_head_ro (sinl + 1));
r_str_ansi_strip (firstline);
sinl = strchr (firstline, '\n');
if (sinl) {
*sinl = 0;
}
}
free (si);
free (sb);
r_cons_flush ();
Expand All @@ -255,6 +268,40 @@ static void r2book_view(RCore *core, const char *path) {
case 9: // TAB
col = !col;
break;
case '\r':
case '\n':
if (col) {
scroll[col]++;
} else {
char *summary = r_file_slurp (R2BOOK_HOME"/SUMMARY.md", NULL);
if (summary) {
char *kw = r_str_newf ("[%s", firstline);
char *s = strstr (summary, kw);
if (s) {
char *nl = strchr (s, '\n');
if (nl) {
*nl = 0;
}
char *par = strchr (s, '(');
if (par) {
s = par + 1;
par = strstr (s, ".md)");
if (par) {
*par = 0;
scroll[1] = 0;
char *p = strdup (s);
// free (path);
path = p;
goto reload;
}
}
}
} else {
R_LOG_ERROR ("Cannot open summary");
r_sys_sleep (1);
}
}
break;
case '!':
r_sys_cmdf ("echo;cd '%s/..'; PS1='$ ' sh", R2BOOK_HOME);
break;
Expand All @@ -275,8 +322,8 @@ static void r2book_view(RCore *core, const char *path) {
break;
case 'e':
edit_page (core, path);
free (index);
free (body);
R_FREE (index);
R_FREE (body);
goto reload;
break;
case 'h':
Expand Down Expand Up @@ -333,8 +380,8 @@ static void r2book_view(RCore *core, const char *path) {
char *ch = strstr (p, ".md:");
*ch = 0;
path = p;
free (index);
free (body);
R_FREE (index);
R_FREE (body);
free (files);
goto reload;
}
Expand All @@ -354,8 +401,8 @@ static void r2book_view(RCore *core, const char *path) {
scroll[1] = 0;
// free (path);
path = p;
free (index);
free (body);
R_FREE (index);
R_FREE (body);
free (files);
goto reload;
}
Expand Down
2 changes: 1 addition & 1 deletion src/intro/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is the official book of the radare project.

_This is a collaborative and community-driven project, if you want to improve the status of the documentation check out the contributing chapter and submit pullrequests to the repository_
_This is a collaborative and community-driven project, if you want to improve the status of the documentation check out the contributing chapter and submit pull requests to the repository_

* [GitHub](https://github.com/radareorg/radare2-book)
* [PDF](https://github.com/radareorg/radare2-book/releases/latest/download/r2book.pdf)
Expand Down

0 comments on commit 67ba601

Please sign in to comment.