Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.1 KiB

  1. int
  2. width_status2d(Bar *bar, BarArg *a)
  3. {
  4. int width;
  5. width = status2dtextlength(rawstext);
  6. return width ? width + lrpad : 0;
  7. }
  8. int
  9. draw_status2d(Bar *bar, BarArg *a)
  10. {
  11. return drawstatusbar(a, rawstext);
  12. }
  13. int
  14. drawstatusbar(BarArg *a, char* stext)
  15. {
  16. int i, w, len;
  17. int x = a->x;
  18. int y = a->y;
  19. short isCode = 0;
  20. char *text;
  21. char *p;
  22. Clr oldbg, oldfg;
  23. len = strlen(stext) + 1;
  24. if (!(text = (char*) malloc(sizeof(char)*len)))
  25. die("malloc");
  26. p = text;
  27. copyvalidchars(text, stext);
  28. x += lrpad / 2;
  29. drw_setscheme(drw, scheme[LENGTH(colors)]);
  30. drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
  31. drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
  32. /* process status text */
  33. i = -1;
  34. while (text[++i]) {
  35. if (text[i] == '^' && !isCode) {
  36. isCode = 1;
  37. text[i] = '\0';
  38. w = TEXTWM(text) - lrpad;
  39. drw_text(drw, x, y, w, bh, 0, text, 0, True);
  40. x += w;
  41. /* process code */
  42. while (text[++i] != '^') {
  43. if (text[i] == 'c') {
  44. char buf[8];
  45. if (i + 7 > len) {
  46. i += 7;
  47. break;
  48. }
  49. memcpy(buf, (char*)text+i+1, 7);
  50. buf[7] = '\0';
  51. drw_clr_create(drw, &drw->scheme[ColFg], buf);
  52. i += 7;
  53. } else if (text[i] == 'b') {
  54. char buf[8];
  55. if (i + 7 > len) {
  56. i += 7;
  57. break;
  58. }
  59. memcpy(buf, (char*)text+i+1, 7);
  60. buf[7] = '\0';
  61. drw_clr_create(drw, &drw->scheme[ColBg], buf);
  62. i += 7;
  63. } else if (text[i] == 'd') {
  64. drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
  65. drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
  66. } else if (text[i] == 'w') {
  67. Clr swp;
  68. swp = drw->scheme[ColFg];
  69. drw->scheme[ColFg] = drw->scheme[ColBg];
  70. drw->scheme[ColBg] = swp;
  71. } else if (text[i] == 'v') {
  72. oldfg = drw->scheme[ColFg];
  73. oldbg = drw->scheme[ColBg];
  74. } else if (text[i] == 't') {
  75. drw->scheme[ColFg] = oldfg;
  76. drw->scheme[ColBg] = oldbg;
  77. } else if (text[i] == 'r') {
  78. int rx = atoi(text + ++i);
  79. while (text[++i] != ',');
  80. int ry = atoi(text + ++i);
  81. while (text[++i] != ',');
  82. int rw = atoi(text + ++i);
  83. while (text[++i] != ',');
  84. int rh = atoi(text + ++i);
  85. if (ry < 0)
  86. ry = 0;
  87. if (rx < 0)
  88. rx = 0;
  89. drw_rect(drw, rx + x, y + ry, rw, rh, 1, 0);
  90. } else if (text[i] == 'f') {
  91. x += atoi(text + ++i);
  92. }
  93. }
  94. text = text + i + 1;
  95. i=-1;
  96. isCode = 0;
  97. }
  98. }
  99. if (!isCode) {
  100. w = TEXTWM(text) - lrpad;
  101. drw_text(drw, x, y, w, bh, 0, text, 0, True);
  102. x += w;
  103. }
  104. free(p);
  105. drw_setscheme(drw, scheme[SchemeNorm]);
  106. return len - 1;
  107. }
  108. int
  109. status2dtextlength(char* stext)
  110. {
  111. int i, w, len;
  112. short isCode = 0;
  113. char *text;
  114. char *p;
  115. len = strlen(stext) + 1;
  116. if (!(text = (char*) malloc(sizeof(char)*len)))
  117. die("malloc");
  118. p = text;
  119. copyvalidchars(text, stext);
  120. /* compute width of the status text */
  121. w = 0;
  122. i = -1;
  123. while (text[++i]) {
  124. if (text[i] == '^') {
  125. if (!isCode) {
  126. isCode = 1;
  127. text[i] = '\0';
  128. w += TEXTWM(text) - lrpad;
  129. text[i] = '^';
  130. if (text[++i] == 'f')
  131. w += atoi(text + ++i);
  132. } else {
  133. isCode = 0;
  134. text = text + i + 1;
  135. i = -1;
  136. }
  137. }
  138. }
  139. if (!isCode)
  140. w += TEXTWM(text) - lrpad;
  141. free(p);
  142. return w;
  143. }