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

Fixes in panels: correct color crop + correct rendering of graph in panels #10422

Merged
merged 3 commits into from Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 25 additions & 6 deletions libr/cons/canvas.c
Expand Up @@ -114,7 +114,7 @@ static void stamp_attr(RConsCanvas *c, int loc, int length) {
s = attr_at (c, loc);

if (s) {
if (strlen (*s) > 2 && *(*s + 2) == '0') {
if (*s != 0 && strlen (*s) > 2 && *(*s + 2) == '0') {
if (strlen (c->attr) == 5 && *(c->attr + 2) != '0') {
char tmp[9];
memcpy (tmp, c->attr, 2);
Expand All @@ -135,7 +135,7 @@ static void stamp_attr(RConsCanvas *c, int loc, int length) {
for (i = 1; i < length; i++) {
s = attr_at (c, loc + i);
if (s) {
*s = Color_RESET;
*s = 0;
}
}
}
Expand Down Expand Up @@ -285,10 +285,13 @@ static int bytes_utf8len(const char *s, int n, int left) {
}
i++;
}
return i - 1;
return n == -1 ? i - 1 : i;
}

static int expand_line (RConsCanvas *c, int real_len, int utf8_len) {
if (real_len == 0) {
return true;
}
int buf_utf8_len = bytes_utf8len (c->b[c->y] + c->x, utf8_len, c->blen[c->y] - c->x);
int goback = R_MAX (0, (buf_utf8_len - real_len));
int padding = (real_len - utf8_len) - goback;
Expand All @@ -304,13 +307,20 @@ static int expand_line (RConsCanvas *c, int real_len, int utf8_len) {
c->b[c->y] = newline;
c->bsize[c->y] = newsize;
}
int size = c->blen[c->y] - c->x - utf8_len;
int size = R_MAX (c->blen[c->y] - c->x - utf8_len, 0);
char *start = c->b[c->y] + c->x + utf8_len;
char *tmp = malloc (size);
if (!tmp) {
return false;
}
memcpy (tmp, start, size);
if (padding < 0) {
int lap = R_MAX (0, c->b[c->y] - (start + padding));
memcpy (start + padding + lap, tmp + lap, size - lap);
free (tmp);
c->blen[c->y] += padding;
return true;
}
memcpy (start + padding, tmp, size);
free (tmp);
c->blen[c->y] += padding;
Expand Down Expand Up @@ -339,8 +349,15 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {
if (piece_len == 0 && ch == '\0' && s_part == s) {
break;
}
left = c->blen[c->y] - c->x;
slen = R_MIN (left, piece_len);
left = c->blen[c->y] - c->x;
slen = piece_len;

if (piece_len > left) {
int utf8_piece_len = utf8len_fixed (s_part, piece_len);
if (utf8_piece_len >= c->w - attr_x) {
slen = left;
}
}

int real_len = r_str_nlen (s_part, slen);
int utf8_len = utf8len_fixed (s_part, slen);
Expand All @@ -360,6 +377,8 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {

s = s_part;
if (ch == '\n') {
c->attr = Color_RESET;
stamp_attr (c, c->y*c->w + attr_x, strlen (Color_RESET));
c->y++;
s++;
if (*s == '\0' || c->y >= c->h) {
Expand Down
3 changes: 3 additions & 0 deletions libr/core/panels.c
Expand Up @@ -725,6 +725,9 @@ R_API void r_core_panels_refresh(RCore *core) {
}

static void doPanelsRefresh(RCore *core) {
if (!core->panels) {
return;
}
core->panels->isResizing = true;
r_core_panels_layout (core->panels);
r_core_panels_refresh (core);
Expand Down