display.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /* display.c, Ait, BSD 3-Clause, Kevin Bloom, 2023-2024,
  2. Derived from: Atto January 2017
  3. Derived from: Anthony's Editor January 93
  4. */
  5. #include "header.h"
  6. #include "util.h"
  7. #define TB_IMPL
  8. #include "termbox.h"
  9. int moving_past = FALSE;
  10. /* Reverse scan for start of logical line containing offset */
  11. point_t lnstart(buffer_t *bp, register point_t off)
  12. {
  13. register char_t *p;
  14. do
  15. p = ptr(bp, --off);
  16. while (bp->b_buf < p && *p != '\n');
  17. return (bp->b_buf < p ? ++off : 0);
  18. }
  19. /* Forward scan for start of logical line segment (corresponds to screen line) containing 'finish' */
  20. point_t segstart(buffer_t *bp, window_t *wp, point_t start, point_t finish)
  21. {
  22. char_t *p;
  23. int c = 0;
  24. point_t scan = start;
  25. while (scan < finish) {
  26. p = ptr(bp, scan);
  27. if (*p == '\n') {
  28. c = 0;
  29. start = scan + 1;
  30. } else if (wp->w_cols <= c) {
  31. c = 0;
  32. start = scan;
  33. }
  34. scan += utf8_size(*ptr(bp,scan));
  35. if(*p == '\t')
  36. c += TAB_SIZE;
  37. else if(*p < 32)
  38. c += 2;
  39. else
  40. c++;
  41. }
  42. return (c < wp->w_cols ? start : finish);
  43. }
  44. /* Forward scan for start of logical line segment following 'finish' */
  45. point_t segnext(buffer_t *bp, window_t *wp, point_t start, point_t finish)
  46. {
  47. char_t *p;
  48. int c = 0;
  49. point_t scan = segstart(bp, wp, start, finish);
  50. for (;;) {
  51. p = ptr(bp, scan);
  52. if (bp->b_ebuf <= p || wp->w_cols <= c)
  53. break;
  54. scan += utf8_size(*ptr(bp,scan));
  55. if (*p == '\n')
  56. break;
  57. if(*p == '\t')
  58. c += TAB_SIZE;
  59. else if(*p < 32)
  60. c += 2;
  61. else
  62. c++;
  63. }
  64. return (p < bp->b_ebuf ? scan : pos(bp, bp->b_ebuf));
  65. }
  66. /* Move up one screen line */
  67. point_t upup(buffer_t *bp, window_t *wp, point_t off)
  68. {
  69. point_t curr = lnstart(bp, off);
  70. point_t seg = segstart(bp, wp, curr, off);
  71. if(wp->w_row == wp->w_top)
  72. moving_past = TRUE;
  73. if (curr < seg)
  74. off = segstart(bp, wp, curr, seg-1);
  75. else
  76. off = segstart(bp, wp, lnstart(bp,curr-1), curr-1);
  77. return (off);
  78. }
  79. /* Move down one screen line */
  80. point_t dndn(buffer_t *bp, window_t *wp, point_t off)
  81. {
  82. if(wp->w_row == wp->w_rows - wp->w_top - 1)
  83. moving_past = TRUE;
  84. return (segnext(bp, wp, lnstart(bp,off), off));
  85. }
  86. /* Return the offset of a column on the specified line */
  87. point_t lncolumn(buffer_t *bp, point_t offset, int column)
  88. {
  89. int c = 0;
  90. char_t *p;
  91. while ((p = ptr(bp, offset)) < bp->b_ebuf && *p != '\n' && c < column) {
  92. c += *p == '\t' ? TAB_SIZE : 1;
  93. offset += utf8_size(*ptr(bp,offset));
  94. }
  95. return (offset);
  96. }
  97. void display(window_t *wp, int flag)
  98. {
  99. char_t *p, z, *g;
  100. int i, j, nch, region = 0, searchlen = strlen(searchtext), b = 0, case_sense = FALSE;
  101. int trailing_whitespace = FALSE, w = 0, token_type = ID_DEFAULT, color = TB_DEFAULT;
  102. int matched = 0;
  103. buffer_t *bp = wp->w_bufp;
  104. point_t matching_bracket = -1;
  105. int prow = bp->b_row, max_col = 0;
  106. /* find start of screen, handle scroll up off page or top of file */
  107. /* point is always within b_page and b_epage */
  108. if (bp->b_point < bp->b_page)
  109. bp->b_page = segstart(bp, wp, lnstart(bp,bp->b_point), bp->b_point);
  110. /* reframe when scrolled off bottom */
  111. if (bp->b_reframe == 1 ||
  112. (bp->b_epage <= bp->b_point && curbp->b_point != pos(curbp, curbp->b_ebuf) &&
  113. (found_point > 0 || wp->w_rows-1 == wp->w_row - wp->w_top))) {
  114. bp->b_reframe = 0;
  115. /* Find end of screen plus one. */
  116. bp->b_page = dndn(bp, wp, bp->b_point);
  117. /* if we scroll to EOF we show 1 blank line at bottom of screen */
  118. if (pos(bp, bp->b_ebuf) <= bp->b_page) {
  119. bp->b_page = pos(bp, bp->b_ebuf);
  120. i = wp->w_rows - 1;
  121. } else {
  122. i = wp->w_rows - 0;
  123. }
  124. /* Scan backwards the required number of lines. */
  125. while (0 < i--)
  126. bp->b_page = upup(bp, wp, bp->b_page);
  127. }
  128. i = wp->w_top;
  129. j = wp->w_left;
  130. bp->b_epage = bp->b_page;
  131. set_parse_state(bp, bp->b_epage); /* are we in a multline comment ? */
  132. /* paint screen from top of page until we hit maxline */
  133. while (1) {
  134. /* reached point - store the cursor position */
  135. if (bp->b_point == bp->b_epage) {
  136. bp->b_row = i;
  137. bp->b_col = j;
  138. }
  139. p = ptr(bp, bp->b_epage);
  140. nch = 1;
  141. if (wp->w_top + wp->w_rows <= i || bp->b_ebuf <= p) /* maxline */
  142. break;
  143. if(curwp == wp && found_point == -1 && is_bracket(*ptr(bp, bp->b_point), FALSE) && (z = is_bracket(*p, TRUE)) != 0) {
  144. int dir = (z == '}' || z == ']' || z == ')' || z == '>');
  145. matching_bracket = find_matching_bracket(bp, wp, dir ? -1 : 1, TRUE);
  146. }
  147. nch = utf8_size(*p);
  148. if(wp == curwp &&
  149. bp->b_mark != NOMARK &&
  150. ((bp->b_mark <= bp->b_epage &&
  151. bp->b_point > bp->b_epage) ||
  152. (bp->b_point <= bp->b_epage &&
  153. bp->b_mark > bp->b_epage))
  154. ) {
  155. region = 1;
  156. } else if(matching_bracket >= 0 && bp->b_epage == matching_bracket) {
  157. matched = 1;
  158. } else if(curwp == wp) {
  159. if(found_point > 0 &&
  160. search_dir == 1 &&
  161. found_point - searchlen <= bp->b_epage &&
  162. bp->b_epage < found_point)
  163. region = 1;
  164. else if(found_point > 0 &&
  165. search_dir == 2 &&
  166. found_point + searchlen >= bp->b_epage &&
  167. bp->b_epage > found_point)
  168. region = 1;
  169. else if(found_point > 0 && tolower(searchtext[0]) == tolower(*p) && b == 0) {
  170. if(isupper(searchtext[0]))
  171. case_sense = TRUE;
  172. while(b < searchlen) {
  173. if(isupper(searchtext[b])) {
  174. case_sense = TRUE;
  175. if(searchtext[b] == *(p+b)) {
  176. region = 1;
  177. } else {
  178. region = 0;
  179. b = 0;
  180. break;
  181. }
  182. } else if (case_sense) {
  183. if(searchtext[b] == *(p+b)) {
  184. region = 1;
  185. } else {
  186. region = 0;
  187. b = 0;
  188. break;
  189. }
  190. } else if(!case_sense && searchtext[b] == tolower(*(p+b))) {
  191. region = 1;
  192. } else {
  193. region = 0;
  194. b = 0;
  195. break;
  196. }
  197. b++;
  198. }
  199. b = b < 0 ? 0 : b - 1;
  200. } else if(b > 0) {
  201. b--;
  202. region = 1;
  203. } else {
  204. region = 0;
  205. b = 0;
  206. }
  207. }
  208. if(nch > 1) {
  209. j++;
  210. uint32_t uni;
  211. tb_utf8_char_to_unicode(&uni, (char *)p);
  212. tb_set_cell(j-1, i, uni, region ? TB_BLACK : TB_DEFAULT, region ? TB_WHITE : TB_DEFAULT);
  213. } else if(*p < 32 && *p != '\n' && *p != '\t') {
  214. char ctrl = unctrl(*p);
  215. tb_set_cell(j, i, '^', TB_RED, region ? TB_WHITE : TB_DEFAULT);
  216. tb_set_cell(j+1, i, ctrl, TB_RED, region ? TB_WHITE : TB_DEFAULT);
  217. j += 2;
  218. } else if (isprint(*p) || *p == '\t' || *p == '\n') {
  219. /* Figure out if the whitespace is trailing or not. */
  220. g = ptr(bp, bp->b_epage);
  221. while(isspace(*p) && *p != '\n' && *g != '\n' && isspace(*(g = ptr(bp, bp->b_epage + w))) && bp->b_point != bp->b_epage + w) {
  222. if(*g == '\n') {
  223. trailing_whitespace = TRUE;
  224. break;
  225. }
  226. w++;
  227. }
  228. w = 0;
  229. if(trailing_whitespace && *p != '\t') {
  230. j++;
  231. uint32_t uni;
  232. tb_utf8_char_to_unicode(&uni, (char *)p);
  233. tb_set_cell(j-1, i, uni, TB_DEFAULT, TB_RED);
  234. } else if(*p == '\t') {
  235. j += TAB_SIZE;
  236. for(int t = TAB_SIZE; t > 0; t--)
  237. tb_set_cell(j-t, i, 0x2500, TB_YELLOW, region ? TB_WHITE : TB_DEFAULT);
  238. } else {
  239. j++;
  240. uint32_t uni;
  241. tb_utf8_char_to_unicode(&uni, (char *)p);
  242. token_type = parse_text(bp, bp->b_epage);
  243. switch(token_type) {
  244. case ID_SYMBOL: {
  245. color = TB_MAGENTA;
  246. break;
  247. }
  248. case ID_DOUBLE_STRING: {
  249. color = TB_GREEN;
  250. break;
  251. }
  252. case ID_SINGLE_STRING: {
  253. color = TB_GREEN;
  254. break;
  255. }
  256. case ID_BACK_STRING: {
  257. color = TB_CYAN;
  258. break;
  259. }
  260. case ID_DIGITS: {
  261. color = TB_CYAN;
  262. break;
  263. }
  264. case ID_LINE_COMMENT: {
  265. color = TB_BLUE;
  266. break;
  267. }
  268. case ID_BLOCK_COMMENT: {
  269. color = TB_BLUE;
  270. break;
  271. }
  272. default: {
  273. color = TB_DEFAULT;
  274. break;
  275. }
  276. }
  277. int mc = matched ? TB_MAGENTA : TB_DEFAULT;
  278. mc = region ? TB_WHITE : mc;
  279. tb_set_cell(j-1, i, uni, region ? TB_BLACK : color, mc);
  280. }
  281. if(j > max_col) {
  282. max_col = j;
  283. }
  284. }
  285. trailing_whitespace = FALSE;
  286. matched = 0;
  287. if (*p == '\n' || wp->w_cols <= j - wp->w_left) {
  288. int cutoff = wp->w_mcol == 0 ? wp->w_left + wp->w_cols : wp->w_mcol;
  289. for(;*p == '\n' && j <= cutoff; j++) {
  290. int x = j - 1, y = i;
  291. struct tb_cell *front_wide, *back_wide;
  292. uint32_t space = (uint32_t)' ';
  293. int fg = TB_DEFAULT;
  294. int bg = TB_DEFAULT;
  295. /* RESEARCH: this makes the first line of the page go blank sometime
  296. and I don't know why.
  297. */
  298. if(y > 0)
  299. cellbuf_get(&global.front, x, y, &front_wide);
  300. cellbuf_get(&global.back, x, y, &back_wide);
  301. send_attr(fg, bg);
  302. send_char(x, y, space);
  303. if(y > 0)
  304. cell_set(front_wide, &space, 1, fg, bg);
  305. cell_set(back_wide, &space, 1, fg, bg);
  306. }
  307. j -= wp->w_cols + 1;
  308. if (j < wp->w_left)
  309. j = wp->w_left;
  310. ++i;
  311. }
  312. bp->b_epage = bp->b_epage + nch;
  313. }
  314. /* Clean up unused chars and, if at the end of buffer, display ~ to
  315. inform the user it's the end.
  316. */
  317. int first = TRUE;
  318. for(;i <= wp->w_top + wp->w_rows - 1; i++) {
  319. for(; j < wp->w_left + wp->w_cols; j++) {
  320. int x = j, y = i;
  321. struct tb_cell *front_wide, *back_wide;
  322. uint32_t space = j == wp->w_left && !first ? (uint32_t)'~' : (uint32_t)' ';
  323. int fg = j == wp->w_left ? TB_CYAN : TB_DEFAULT;
  324. int bg = TB_DEFAULT;
  325. if(y > 0)
  326. cellbuf_get(&global.front, x, y, &front_wide);
  327. cellbuf_get(&global.back, x, y, &back_wide);
  328. send_attr(fg, bg);
  329. send_char(x, y, space);
  330. if(y > 0)
  331. cell_set(front_wide, &space, 1, fg, bg);
  332. cell_set(back_wide, &space, 1, fg, bg);
  333. first = FALSE;
  334. }
  335. j -= wp->w_cols + 1;
  336. if (j < wp->w_left)
  337. j = wp->w_left;
  338. }
  339. wp->w_mcol = max_col;
  340. b2w(wp); /* save buffer stuff on window */
  341. modeline(wp);
  342. if (wp == curwp && flag) {
  343. dispmsg();
  344. tb_set_cursor(bp->b_col, bp->b_row); /* set cursor */
  345. }
  346. wp->w_update = FALSE;
  347. if(bp->b_row == prow && !moving_past) {
  348. bp->b_pcol = bp->b_col;
  349. wp->w_pcol = bp->b_col;
  350. }
  351. moving_past = FALSE;
  352. }
  353. void modeline(window_t *wp)
  354. {
  355. int i, k, col = wp->w_col - wp->w_left + 1;
  356. int tabs = 0, ccs = 0;
  357. char lch, mch, och;
  358. char mltemp[TEMPBUF];
  359. char *percent = NULL;
  360. char_t *p;
  361. point_t pg = lnstart(curbp, curbp->b_page),
  362. ebuf = pos(curbp, curbp->b_ebuf);
  363. float dec = 0.0, mod = 0.0;
  364. lch = (wp == curwp ? '=' : '-');
  365. mch = ((wp->w_bufp->b_flags & B_MODIFIED) ? '*' : lch);
  366. och = ((wp->w_bufp->b_flags & B_OVERWRITE) ? 'O' : lch);
  367. /* Based on the b_page, determine if you're at the top, bottom or
  368. somewhere in-between the buffer. If in-between, calculate the
  369. percentage from the bottom. We round up always because that's
  370. what Emacs does.
  371. */
  372. percent = (char *) malloc(sizeof(char *)*3);
  373. if(pg == 0) {
  374. percent = "Top";
  375. } else if(curbp->b_epage == ebuf) {
  376. percent = "Bot";
  377. } else {
  378. mod = curbp->b_page * 100 % ebuf;
  379. dec = curbp->b_page * 100.0 / ebuf;
  380. if(mod != 0)
  381. dec++;
  382. sprintf(percent, "%d%%", (int)(dec));
  383. }
  384. for(k = 0; k <= wp->w_cols; k++) {
  385. if(wp->w_bufp->b_point-k < 0) {
  386. break;
  387. }
  388. p = ptr(wp->w_bufp, wp->w_bufp->b_point-k);
  389. if(k != 0) {
  390. if(*p == '\n') {
  391. break;
  392. }
  393. if(*p == '\t') {
  394. tabs++;
  395. }
  396. if(*p < 32) {
  397. ccs++;
  398. }
  399. }
  400. }
  401. if(k >= wp->w_cols && col != wp->w_cols) {
  402. col += wp->w_cols;
  403. }
  404. /* remove the extra spaces from the control and tab characters */
  405. if(col > 1) {
  406. col -= tabs * 2;
  407. col -= ccs;
  408. }
  409. sprintf(mltemp, "%c%c%c %s %c%c (%d,%d) %c%c %s ", lch,och,mch, wp->w_bufp->b_bname,
  410. lch, lch, wp->w_bufp->b_line, col, lch, lch, percent);
  411. addstrxy(mltemp, wp->w_left, wp->w_top + wp->w_rows, 1);
  412. if(wp->w_update || wp->w_mlen != strlen(mltemp))
  413. for (i = strlen(mltemp); i < wp->w_cols; i++)
  414. addchxy(lch, i+wp->w_left, wp->w_top + wp->w_rows, 1);
  415. wp->w_mlen = strlen(mltemp);
  416. }
  417. void dispmsg()
  418. {
  419. tb_set_cursor(0, MSGLINE);
  420. if (msgflag) {
  421. addstr(msgline);
  422. msgflag = FALSE;
  423. }
  424. clrtoeol(msgline, MSGLINE);
  425. }
  426. void display_prompt_and_response(char *prompt, char *response)
  427. {
  428. char full[PATH_MAX];
  429. strcpy(full, prompt);
  430. strcat(full, response);
  431. print_to_msgline(prompt);
  432. /* if we have a value print it and go to end of it */
  433. if (response[0] != '\0')
  434. addstr(response);
  435. clrtoeol(full, MSGLINE);
  436. }
  437. void update_display()
  438. {
  439. window_t *wp;
  440. buffer_t *bp;
  441. bp = curwp->w_bufp;
  442. bp->b_cpoint = bp->b_point; /* cpoint only ever set here */
  443. /* only one window */
  444. if (wheadp->w_next == NULL) {
  445. display(curwp, TRUE);
  446. tb_present();
  447. bp->b_psize = bp->b_size;
  448. return;
  449. }
  450. display(curwp, FALSE); /* this is key, we must call our win first to get accurate page and epage etc */
  451. if(curwp->w_left != 0)
  452. for(int i = curwp->w_top; i < curwp->w_rows+curwp->w_top+1; i++)
  453. tb_set_cell(curwp->w_left - 1, i, '|', TB_WHITE, TB_DEFAULT);
  454. /* never curwp, but same buffer in different window or update flag set*/
  455. for (wp=wheadp; wp != NULL; wp = wp->w_next) {
  456. if (wp != curwp && (wp->w_bufp == bp || wp->w_update)) {
  457. w2b(wp);
  458. for(int i = wp->w_top; i < wp->w_rows+wp->w_top+1; i++)
  459. tb_set_cell(wp->w_left - 1, i, '|', TB_WHITE, TB_DEFAULT);
  460. display(wp, FALSE);
  461. }
  462. }
  463. /* now display our window and buffer */
  464. w2b(curwp);
  465. dispmsg();
  466. tb_set_cursor(curwp->w_col, curwp->w_row); /* set cursor for curwp */
  467. tb_present();
  468. bp->b_psize = bp->b_size; /* now safe to save previous size for next time */
  469. }
  470. void w2b(window_t *w)
  471. {
  472. w->w_bufp->b_point = w->w_point;
  473. w->w_bufp->b_page = w->w_page;
  474. w->w_bufp->b_epage = w->w_epage;
  475. w->w_bufp->b_row = w->w_row;
  476. w->w_bufp->b_col = w->w_col;
  477. w->w_bufp->b_pcol = w->w_pcol;
  478. /* fixup pointers in other windows of the same buffer, if size of edit text changed */
  479. if (w->w_bufp->b_point > w->w_bufp->b_cpoint) {
  480. w->w_bufp->b_point += (w->w_bufp->b_size - w->w_bufp->b_psize);
  481. w->w_bufp->b_page += (w->w_bufp->b_size - w->w_bufp->b_psize);
  482. w->w_bufp->b_epage += (w->w_bufp->b_size - w->w_bufp->b_psize);
  483. }
  484. }
  485. void b2w(window_t *w)
  486. {
  487. w->w_point = w->w_bufp->b_point;
  488. w->w_page = w->w_bufp->b_page;
  489. w->w_epage = w->w_bufp->b_epage;
  490. w->w_row = w->w_bufp->b_row;
  491. w->w_col = w->w_bufp->b_col;
  492. w->w_pcol = w->w_bufp->b_pcol;
  493. w->w_bufp->b_size = (w->w_bufp->b_ebuf - w->w_bufp->b_buf) - (w->w_bufp->b_egap - w->w_bufp->b_gap);
  494. }
  495. /* flag = default answer, FALSE=n, TRUE=y */
  496. int yesno(int flag)
  497. {
  498. struct tb_event ev;
  499. tb_present();
  500. if(tb_poll_event(&ev) != TB_OK) return 0;
  501. if (ev.ch == '\r' || ev.ch == '\n')
  502. return (flag);
  503. return (tolower(ev.ch) == 'y');
  504. }
  505. char yesnomaybeso(char d)
  506. {
  507. struct tb_event ev;
  508. tb_present();
  509. if(tb_poll_event(&ev) != TB_OK) return 0;
  510. if (ev.ch == '\r' || ev.ch == '\n')
  511. return (d);
  512. return tolower(ev.ch);
  513. }
  514. void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg)
  515. {
  516. while (*str) {
  517. uint32_t uni;
  518. str += tb_utf8_char_to_unicode(&uni, str);
  519. tb_set_cell(x, y, uni, fg, bg);
  520. x++;
  521. }
  522. }
  523. void printf_tb(int x, int y, uint16_t fg, uint16_t bg, const char *fmt, ...)
  524. {
  525. char buf[4096];
  526. va_list vl;
  527. va_start(vl, fmt);
  528. vsnprintf(buf, sizeof(buf), fmt, vl);
  529. va_end(vl);
  530. print_tb(buf, x, y, fg, bg);
  531. }
  532. void addstr(const char *str)
  533. {
  534. printf_tb(global.cursor_x, global.cursor_y, TB_DEFAULT, TB_DEFAULT, str);
  535. tb_set_cursor(global.cursor_x+strlen(str), global.cursor_y);
  536. }
  537. void addch(char c)
  538. {
  539. printf_tb(global.cursor_x, global.cursor_y, TB_DEFAULT, TB_DEFAULT, "%c", c);
  540. tb_set_cursor(global.cursor_x+1, global.cursor_y);
  541. }
  542. /*
  543. Print char at point x,y. If within the region, highlight it.
  544. */
  545. void addchxy(char c, int x, int y, int region)
  546. {
  547. int fg = region == 0 ? TB_DEFAULT : TB_BLACK;
  548. int bg = region == 0 ? TB_DEFAULT : TB_WHITE;
  549. if(c != '\n' && c != '\r')
  550. printf_tb(x, y, fg, bg, "%c", c);
  551. else
  552. printf_tb(x, y, fg, bg, " ");
  553. }
  554. void addstrxy(char *c, int x, int y, int region)
  555. {
  556. int fg = region == 0 ? TB_DEFAULT : TB_BLACK;
  557. int bg = region == 0 ? TB_DEFAULT : TB_WHITE;
  558. printf_tb(x, y, fg, bg, "%s", c);
  559. }
  560. void clrtoeol(const char *str, int line)
  561. {
  562. int l = strlen(str);
  563. int size = COLS-l;
  564. char blanks[size], entire[COLS];
  565. if(size == 0) {
  566. for(int i=0; i<size; i++) {
  567. entire[i]=' ';
  568. }
  569. printf_tb(l, line, TB_DEFAULT, TB_DEFAULT, "%s", entire);
  570. } else {
  571. for(int i=0; i<size; i++) {
  572. blanks[i]=' ';
  573. }
  574. printf_tb(l, line, TB_DEFAULT, TB_DEFAULT, "%s", blanks);
  575. }
  576. }