RichString.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef HEADER_RichString
  2. #define HEADER_RichString
  3. /*
  4. htop - RichString.h
  5. (C) 2004,2011 Hisham H. Muhammad
  6. Released under the GNU GPLv2+, see the COPYING file
  7. in the source distribution for its full text.
  8. */
  9. #include "Macros.h"
  10. #include "ProvideCurses.h"
  11. #define RichString_size(this) ((this)->chlen)
  12. #define RichString_sizeVal(this) ((this).chlen)
  13. #define RichString_begin(this) RichString this; RichString_beginAllocated(this)
  14. #define RichString_beginAllocated(this) \
  15. do { \
  16. (this).chlen = 0; \
  17. (this).chptr = (this).chstr; \
  18. RichString_setChar(&(this), 0, 0); \
  19. (this).highlightAttr = 0; \
  20. } while(0)
  21. #ifdef HAVE_LIBNCURSESW
  22. #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr)
  23. #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n)
  24. #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0])
  25. #define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while (0)
  26. #define CharType cchar_t
  27. #else
  28. #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr)
  29. #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n)
  30. #define RichString_getCharVal(this, i) ((this).chptr[i] & 0xff)
  31. #define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while (0)
  32. #define CharType chtype
  33. #endif
  34. #define RICHSTRING_MAXLEN 350
  35. typedef struct RichString_ {
  36. int chlen;
  37. CharType* chptr;
  38. CharType chstr[RICHSTRING_MAXLEN + 1];
  39. int highlightAttr;
  40. } RichString;
  41. void RichString_delete(RichString* this);
  42. void RichString_rewind(RichString* this, int count);
  43. void RichString_setAttrn(RichString* this, int attrs, int start, int charcount);
  44. int RichString_findChar(const RichString* this, char c, int start);
  45. void RichString_setAttr(RichString* this, int attrs);
  46. void RichString_appendChr(RichString* this, int attrs, char c, int count);
  47. /* All appending and writing functions return the number of written characters (not columns). */
  48. int RichString_appendWide(RichString* this, int attrs, const char* data);
  49. ATTR_ACCESS3_R(3, 4)
  50. int RichString_appendnWide(RichString* this, int attrs, const char* data, int len);
  51. /* columns takes the maximum number of columns to write and contains on return the number of columns written. */
  52. int RichString_appendnWideColumns(RichString* this, int attrs, const char* data, int len, int* columns);
  53. int RichString_writeWide(RichString* this, int attrs, const char* data);
  54. int RichString_appendAscii(RichString* this, int attrs, const char* data);
  55. ATTR_ACCESS3_R(3, 4)
  56. int RichString_appendnAscii(RichString* this, int attrs, const char* data, int len);
  57. int RichString_writeAscii(RichString* this, int attrs, const char* data);
  58. #endif