2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
#include "RichString.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <curses.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define RICHSTRING_MAXLEN 300
|
|
|
|
|
|
|
|
/*{
|
|
|
|
|
2006-07-12 01:16:03 +00:00
|
|
|
#define RichString_init(this) (this)->len = 0
|
|
|
|
#define RichString_initVal(this) (this).len = 0
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef struct RichString_ {
|
|
|
|
int len;
|
|
|
|
chtype chstr[RICHSTRING_MAXLEN+1];
|
|
|
|
} RichString;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void RichString_write(RichString* this, int attrs, char* data) {
|
2006-07-12 01:16:03 +00:00
|
|
|
RichString_init(this);
|
2006-03-04 18:16:49 +00:00
|
|
|
RichString_append(this, attrs, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RichString_append(RichString* this, int attrs, char* data) {
|
|
|
|
RichString_appendn(this, attrs, data, strlen(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
|
2006-07-12 01:16:03 +00:00
|
|
|
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;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RichString_setAttr(RichString *this, int attrs) {
|
2006-07-12 01:16:03 +00:00
|
|
|
chtype* ch = this->chstr;
|
2006-03-04 18:16:49 +00:00
|
|
|
for (int i = 0; i < this->len; i++) {
|
2006-07-12 01:16:03 +00:00
|
|
|
*ch = (*ch & 0xff) | attrs;
|
|
|
|
ch++;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RichString_applyAttr(RichString *this, int attrs) {
|
2006-07-12 01:16:03 +00:00
|
|
|
chtype* ch = this->chstr;
|
|
|
|
for (int i = 0; i < this->len; i++) {
|
|
|
|
*ch |= attrs;
|
|
|
|
ch++;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RichString RichString_quickString(int attrs, char* data) {
|
2006-07-12 01:16:03 +00:00
|
|
|
RichString str;
|
|
|
|
RichString_initVal(str);
|
2006-03-04 18:16:49 +00:00
|
|
|
RichString_write(&str, attrs, data);
|
|
|
|
return str;
|
|
|
|
}
|