~ubuntu-branches/ubuntu/dapper/htop/dapper

« back to all changes in this revision

Viewing changes to RichString.c

  • Committer: Bazaar Package Importer
  • Author(s): Bartosz Fenski
  • Date: 2004-11-27 10:10:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041127101017-vwknw2ipfvxchno4
Tags: 0.5-1
* New upstream version.
  - fixes problem with wrongly displayed CPU bar (Closes: #283212)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <stdlib.h>
5
5
#include <string.h>
6
6
#include <curses.h>
7
 
#include <assert.h>
8
7
#include <sys/param.h>
9
8
 
10
9
#include "debug.h"
 
10
#include <assert.h>
11
11
 
12
 
#define RICHSTRING_MAXLEN 512
 
12
#define RICHSTRING_MAXLEN 300
13
13
 
14
14
/*{
15
15
 
36
36
   this->len = 0;
37
37
}
38
38
 
39
 
void RichString_attrOn(int attrs) {
40
 
   wattron(workArea, attrs);
41
 
}
42
 
 
43
 
void RichString_attrOff(int attrs) {
44
 
   wattroff(workArea, attrs);
45
 
}
46
 
 
47
39
void RichString_write(RichString* this, int attrs, char* data) {
48
40
   this->len = 0;
49
41
   RichString_append(this, attrs, data);
50
42
}
51
43
 
52
 
void RichString_append(RichString* this, int attrs, char* data) {
 
44
inline void RichString_append(RichString* this, int attrs, char* data) {
 
45
   RichString_appendn(this, attrs, data, strlen(data));
 
46
}
 
47
 
 
48
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
53
49
   if (!workArea) {
54
50
      workArea = newpad(1, RICHSTRING_MAXLEN);
55
51
   }
56
52
   assert(workArea);
57
 
   wattron(workArea, attrs);
58
 
   int len = strlen(data);
 
53
   wattrset(workArea, attrs);
59
54
   int maxToWrite = (RICHSTRING_MAXLEN - 1) - this->len;
60
55
   int wrote = MIN(maxToWrite, len);
61
56
   mvwaddnstr(workArea, 0, 0, data, maxToWrite);
73
68
}
74
69
 
75
70
void RichString_applyAttr(RichString *this, int attrs) {
76
 
   for (int i = 0; i < this->len; i++) {
 
71
   for (int i = 0; i < this->len - 1; i++) {
77
72
      this->chstr[i] |= attrs;
78
73
   }
79
74
}
 
75
 
 
76
RichString RichString_quickString(int attrs, char* data) {
 
77
   RichString str = RichString_new();
 
78
   RichString_write(&str, attrs, data);
 
79
   return str;
 
80
}