aboutsummaryrefslogtreecommitdiffstats
path: root/RichString.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
commit85bb4ad9cb820ac3b8e935a930084a06cbfd2847 (patch)
tree681fd9b2d9fa80931b2a8bec4bb6667865b7c569 /RichString.c
parentea859f50d9438bc61ae96721a4d255b49de78653 (diff)
downloaddebian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.tar.gz
debian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.tar.bz2
debian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.zip
Imported Upstream version 0.6.3upstream/0.6.3
Diffstat (limited to 'RichString.c')
-rw-r--r--RichString.c52
1 files changed, 18 insertions, 34 deletions
diff --git a/RichString.c b/RichString.c
index 7a92e08..3bdc82b 100644
--- a/RichString.c
+++ b/RichString.c
@@ -12,6 +12,9 @@
/*{
+#define RichString_init(this) (this)->len = 0
+#define RichString_initVal(this) (this).len = 0
+
typedef struct RichString_ {
int len;
chtype chstr[RICHSTRING_MAXLEN+1];
@@ -23,24 +26,8 @@ typedef struct RichString_ {
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
-/* private property */
-WINDOW* workArea = NULL;
-
-RichString RichString_new() {
- RichString this;
- this.len = 0;
- return this;
-}
-
-void RichString_delete(RichString this) {
-}
-
-void RichString_prune(RichString* this) {
- this->len = 0;
-}
-
void RichString_write(RichString* this, int attrs, char* data) {
- this->len = 0;
+ RichString_init(this);
RichString_append(this, attrs, data);
}
@@ -49,35 +36,32 @@ inline void RichString_append(RichString* this, int attrs, char* data) {
}
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
- if (!workArea) {
- workArea = newpad(1, RICHSTRING_MAXLEN);
- }
- assert(workArea);
- wattrset(workArea, attrs);
- int maxToWrite = (RICHSTRING_MAXLEN - 1) - this->len;
- int wrote = MIN(maxToWrite, len);
- mvwaddnstr(workArea, 0, 0, data, maxToWrite);
- int oldstrlen = this->len;
- this->len += wrote;
- mvwinchnstr(workArea, 0, 0, this->chstr + oldstrlen, wrote);
- wattroff(workArea, attrs);
+ int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
+ for (int i = this->len, j = 0; i < last; i++, j++)
+ this->chstr[i] = data[j] | attrs;
+ this->chstr[last] = 0;
+ this->len = last;
}
void RichString_setAttr(RichString *this, int attrs) {
+ chtype* ch = this->chstr;
for (int i = 0; i < this->len; i++) {
- char c = this->chstr[i];
- this->chstr[i] = c | attrs;
+ *ch = (*ch & 0xff) | attrs;
+ ch++;
}
}
void RichString_applyAttr(RichString *this, int attrs) {
- for (int i = 0; i < this->len - 1; i++) {
- this->chstr[i] |= attrs;
+ chtype* ch = this->chstr;
+ for (int i = 0; i < this->len; i++) {
+ *ch |= attrs;
+ ch++;
}
}
RichString RichString_quickString(int attrs, char* data) {
- RichString str = RichString_new();
+ RichString str;
+ RichString_initVal(str);
RichString_write(&str, attrs, data);
return str;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy