-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Preserve colors/highlighting for highlighted lines #243
Comments
Idea for a patch: diff --git a/Panel.c b/Panel.c
index fd9de2b..831452f 100644
--- a/Panel.c
+++ b/Panel.c
@@ -278,7 +278,7 @@ void Panel_draw(Panel* this, bool focus) {
}
if (item.highlightAttr) {
attrset(item.highlightAttr);
- RichString_setAttr(&item, item.highlightAttr);
+ RichString_setAttr_preserveBold(&item, item.highlightAttr);
this->selectedLen = itemLen;
}
mvhline(y + line, x, ' ', this->w);
diff --git a/RichString.c b/RichString.c
index 904b44b..1a0d6ce 100644
--- a/RichString.c
+++ b/RichString.c
@@ -69,6 +69,15 @@ inline void RichString_setAttrn(RichString* this, int attrs, int start, int fini
}
}
+inline void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish) {
+ cchar_t* ch = this->chptr + start;
+ finish = CLAMP(finish, 0, this->chlen - 1);
+ for (int i = start; i <= finish; i++) {
+ ch->attr = (ch->attr & A_BOLD) ? (attrs | A_BOLD) : attrs;
+ ch++;
+ }
+}
+
int RichString_findChar(RichString* this, char c, int start) {
wchar_t wc = btowc(c);
cchar_t* ch = this->chptr + start;
@@ -100,6 +109,15 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
}
}
+void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish) {
+ chtype* ch = this->chptr + start;
+ finish = CLAMP(finish, 0, this->chlen - 1);
+ for (int i = start; i <= finish; i++) {
+ *ch = (*ch & 0xff) | attrs | (*ch & A_BOLD);
+ ch++;
+ }
+}
+
int RichString_findChar(RichString* this, char c, int start) {
chtype* ch = this->chptr + start;
for (int i = start; i < this->chlen; i++) {
@@ -123,6 +141,10 @@ void RichString_setAttr(RichString* this, int attrs) {
RichString_setAttrn(this, attrs, 0, this->chlen - 1);
}
+void RichString_setAttr_preserveBold(RichString* this, int attrs) {
+ RichString_setAttrn_preserveBold(this, attrs, 0, this->chlen - 1);
+}
+
void RichString_append(RichString* this, int attrs, const char* data) {
RichString_writeFrom(this, attrs, data, this->chlen, strlen(data));
}
diff --git a/RichString.h b/RichString.h
index 12b0954..c690f8c 100644
--- a/RichString.h
+++ b/RichString.h
@@ -44,12 +44,16 @@ typedef struct RichString_ {
void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
+void RichString_setAttrn_preserveBold(RichString* this, int attrs, int start, int finish);
+
int RichString_findChar(RichString* this, char c, int start);
void RichString_prune(RichString* this);
void RichString_setAttr(RichString* this, int attrs);
+void RichString_setAttr_preserveBold(RichString* this, int attrs);
+
void RichString_append(RichString* this, int attrs, const char* data);
void RichString_appendn(RichString* this, int attrs, const char* data, int len); |
On first look the patch looks reasonable; mind to create a pull request? |
The issue with this patch is some runtime behaviour that's kinda nasty IMO: I don't really mind making a PR for this, but I think this caveat should be mentioned and discussed. |
While reviewing #240 it became quite visible, that when highlighting lines (e.g. with space, or with the newly added highlighting for new/dead processes) the markup of the line is dropped. With only a few lines affected with the search or manually selected processes this isn't a big issue, but when highlighting of lines becomes more visible, so becomes the dropped formatting for these lines.
Thus we should build some mechanism to add highlighting for a line AND keep it's formatting apart from the added highlighting.
The text was updated successfully, but these errors were encountered: