curseOutput.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /**
  2. * curseOutput.cpp for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #include <iostream>
  7. #include <sys/ioctl.h>
  8. #include <algorithm>
  9. #include <unistd.h>
  10. #include <signal.h>
  11. #include <string.h>
  12. #include "searchPattern.hh"
  13. #include "curseOutput.hh"
  14. #include "jsonPrimitive.hh"
  15. #include "jsonObject.hh"
  16. #include "jsonArray.hh"
  17. #include "except.hh"
  18. #include "streamConsumer.hh"
  19. static CurseOutput *runningInst = nullptr;
  20. CurseOutput::CurseOutput(const Params &p): data(nullptr), params(p)
  21. {
  22. runningInst = this;
  23. }
  24. CurseOutput::~CurseOutput()
  25. {
  26. runningInst = nullptr;
  27. }
  28. void CurseOutput::loop()
  29. {
  30. breakLoop = false;
  31. do
  32. {
  33. while (!redraw()) //TODO opti going down
  34. ;
  35. } while(readInput());
  36. }
  37. bool CurseOutput::onsig(int signo)
  38. {
  39. struct winsize size;
  40. switch (signo)
  41. {
  42. case SIGWINCH:
  43. if (ioctl(fileno(screen_fd ? screen_fd : stdout), TIOCGWINSZ, &size) == 0)
  44. resize_term(size.ws_row, size.ws_col);
  45. clear();
  46. while (!redraw());
  47. break;
  48. case SIGKILL:
  49. case SIGINT:
  50. case SIGTERM:
  51. breakLoop = true;
  52. break;
  53. default:
  54. return false;
  55. }
  56. return true;
  57. }
  58. void _resizeFnc(int signo)
  59. {
  60. if (!runningInst)
  61. return;
  62. runningInst->onsig(signo);
  63. }
  64. bool CurseOutput::redraw(const std::string &errorMsg)
  65. {
  66. bool result = redraw();
  67. writeBottomLine(errorMsg, OutputFlag::SPECIAL_ERROR);
  68. return result;
  69. }
  70. bool CurseOutput::redraw(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, JSonElement *item)
  71. {
  72. checkSelection(item, cursor);
  73. if (dynamic_cast<const JSonContainer*>(item))
  74. {
  75. if (!writeContainer(cursor, maxSize, (const JSonContainer *) item))
  76. return false;
  77. }
  78. else
  79. {
  80. cursor.second += write(cursor.first, cursor.second, item, maxSize.first, getFlag(item));
  81. if (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1)
  82. return false;
  83. }
  84. return true;
  85. }
  86. bool CurseOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *item)
  87. {
  88. char childDelimiter[2];
  89. if (dynamic_cast<const JSonObject *>(item))
  90. memcpy(childDelimiter, "{}", sizeof(*childDelimiter) * 2);
  91. else
  92. memcpy(childDelimiter, "[]", sizeof(*childDelimiter) * 2);
  93. if (collapsed.find((const JSonContainer *)item) != collapsed.end())
  94. {
  95. std::string ss;
  96. ss.append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
  97. cursor.second += write(cursor.first, cursor.second, ss, 7, maxSize.first, getFlag(item));
  98. }
  99. else
  100. {
  101. cursor.second += write(cursor.first, cursor.second, childDelimiter[0], maxSize.first, getFlag(item));
  102. if (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1)
  103. return false;
  104. if (!writeContent(cursor, maxSize, (std::list<JSonElement *> *)item))
  105. return false;
  106. cursor.second += write(cursor.first, cursor.second, childDelimiter[1], maxSize.first, getFlag(item));
  107. }
  108. return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second -1);
  109. }
  110. bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement*> *_item)
  111. {
  112. JSonContainer *item = (JSonContainer *)_item;
  113. bool containerIsObject = (dynamic_cast<JSonObject *>(item) != nullptr);
  114. bool result = true;
  115. cursor.first += INDENT_LEVEL;
  116. for (JSonElement *i : *item)
  117. {
  118. result = false;
  119. if (containerIsObject)
  120. {
  121. JSonObjectEntry *ent = (JSonObjectEntry*) i;
  122. bool isContainer = (dynamic_cast<JSonContainer *>(**ent) != nullptr);
  123. std::string key = ent->stringify();
  124. checkSelection(ent, cursor);
  125. if (isContainer && collapsed.find((JSonContainer*)(**ent)) != collapsed.cend())
  126. {
  127. if (dynamic_cast<JSonObject *>(**ent))
  128. {
  129. if (!writeKey(key, ent->lazystrlen(), "{ ... }", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
  130. break;
  131. }
  132. else if (!writeKey(key, ent->lazystrlen(), "[ ... ]", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
  133. break;
  134. }
  135. else if (!isContainer)
  136. {
  137. JSonElement *eContent = **ent;
  138. if (!writeKey(key, ent->lazystrlen(), eContent->stringify(), eContent->lazystrlen(), cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
  139. break;
  140. }
  141. else if (((JSonContainer*)(**ent))->size() == 0)
  142. {
  143. if (dynamic_cast<const JSonObject *>(**ent) )
  144. {
  145. if (!writeKey(key, ent->lazystrlen(), "{ }", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
  146. break;
  147. }
  148. else if (!writeKey(key, ent->lazystrlen(), "[ ]", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
  149. break;
  150. }
  151. else
  152. {
  153. if (!writeKey(key, ent->lazystrlen(), cursor, maxSize, getFlag(ent)))
  154. break;
  155. const JSonElement *saveSelection = selection;
  156. if (selection == ent)
  157. selection = **ent;
  158. cursor.first += INDENT_LEVEL /2;
  159. if (!redraw(cursor, maxSize, **ent))
  160. {
  161. selection = saveSelection;
  162. cursor.first -= INDENT_LEVEL /2;
  163. return false;
  164. }
  165. selection = saveSelection;
  166. cursor.first -= INDENT_LEVEL /2;
  167. }
  168. }
  169. else
  170. {
  171. if (!redraw(cursor, maxSize, i))
  172. break;
  173. }
  174. result = true;
  175. }
  176. cursor.first -= INDENT_LEVEL;
  177. //result will be false if for loop break'd at some time, true otherwise
  178. return result;
  179. }
  180. bool CurseOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
  181. {
  182. if (cursor.second - scrollTop < 0)
  183. {
  184. cursor.second++;
  185. return true;
  186. }
  187. char oldType = flags.type();
  188. flags.type(OutputFlag::TYPE_OBJKEY);
  189. write(cursor.first, cursor.second, key, 0, 1, flags);
  190. flags.type(OutputFlag::TYPE_OBJ);
  191. write(": ", flags);
  192. flags.type(oldType);
  193. write(after.c_str(), flags);
  194. cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxSize.first);
  195. return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second);
  196. }
  197. bool CurseOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
  198. {
  199. return writeKey(key, keylen, after, after.size(), cursor, maxSize, flags);
  200. }
  201. bool CurseOutput::writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags, unsigned int extraLen)
  202. {
  203. if (cursor.second - scrollTop < 0)
  204. {
  205. cursor.second++;
  206. return true;
  207. }
  208. char oldType = flags.type();
  209. flags.type(OutputFlag::TYPE_OBJKEY);
  210. cursor.second += write(cursor.first, cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
  211. flags.type(OutputFlag::TYPE_OBJ);
  212. write(": ", flags);
  213. flags.type(oldType);
  214. return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second);
  215. }
  216. unsigned int CurseOutput::write(const int &x, const int &y, JSonElement *item, unsigned int maxWidth, OutputFlag flags)
  217. {
  218. return write(x, y, item->stringify(), item->lazystrlen(), maxWidth, flags);
  219. }
  220. unsigned int CurseOutput::write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags)
  221. {
  222. int offsetY = y - scrollTop;
  223. char color = OutputFlag::SPECIAL_NONE;
  224. if (offsetY < 0)
  225. return 1;
  226. if (flags.selected())
  227. attron(A_REVERSE | A_BOLD);
  228. if (flags.searched())
  229. color = OutputFlag::SPECIAL_SEARCH;
  230. else if (colors.find(flags.type()) != colors.end())
  231. color = flags.type();
  232. if (color != OutputFlag::SPECIAL_NONE)
  233. attron(COLOR_PAIR(color));
  234. mvprintw(offsetY, x, "%c", item);
  235. attroff(A_REVERSE | A_BOLD);
  236. if (color != OutputFlag::SPECIAL_NONE)
  237. attroff(COLOR_PAIR(color));
  238. return getNbLines(x +1, maxWidth);
  239. }
  240. void CurseOutput::write(const std::string &str, const OutputFlag flags) const
  241. {
  242. char color = OutputFlag::SPECIAL_NONE;
  243. if (flags.selected())
  244. attron(A_REVERSE | A_BOLD);
  245. if (flags.searched())
  246. color = OutputFlag::SPECIAL_SEARCH;
  247. else if (colors.find(flags.type()) != colors.end())
  248. color = flags.type();
  249. if (color != OutputFlag::SPECIAL_NONE)
  250. attron(COLOR_PAIR(color));
  251. printw("%s", str.c_str());
  252. attroff(A_REVERSE | A_BOLD);
  253. if (color != OutputFlag::SPECIAL_NONE)
  254. attroff(COLOR_PAIR(color));
  255. }
  256. unsigned int CurseOutput::write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags)
  257. {
  258. int offsetY = y - scrollTop;
  259. if (offsetY < 0)
  260. return 1;
  261. move(offsetY, x);
  262. write(str, flags);
  263. return getNbLines(strlen +x, maxWidth);
  264. }
  265. unsigned int CurseOutput::getNbLines(const size_t nbChar, unsigned int maxWidth)
  266. {
  267. double nLine = (double) nbChar / maxWidth;
  268. if (nLine == (unsigned int) nLine)
  269. return nLine;
  270. return nLine +1;
  271. }
  272. const std::pair<unsigned int, unsigned int> CurseOutput::getScreenSize() const
  273. {
  274. std::pair<int, int> bs;
  275. std::pair<int, int> sc;
  276. getmaxyx(stdscr, sc.second, sc.first);
  277. getbegyx(stdscr, bs.second, bs.first);
  278. sc.first -= bs.first;
  279. sc.second -= bs.second;
  280. return sc;
  281. }
  282. const OutputFlag CurseOutput::getFlag(const JSonElement *item) const
  283. {
  284. OutputFlag res;
  285. const JSonElement *i = dynamic_cast<const JSonObjectEntry*>(item) ? **((const JSonObjectEntry*)item) : item;
  286. res.selected(item == selection);
  287. res.searched(std::find(search_result.cbegin(), search_result.cend(), item) != search_result.cend());
  288. if (dynamic_cast<const JSonPrimitive<std::string> *>(i))
  289. res.type(OutputFlag::TYPE_STRING);
  290. else if (dynamic_cast<const JSonPrimitive<bool> *>(i))
  291. res.type(OutputFlag::TYPE_BOOL);
  292. else if (dynamic_cast<const JSonPrimitive<Null> *>(i))
  293. res.type(OutputFlag::TYPE_NULL);
  294. else if (dynamic_cast<const AJSonPrimitive *>(i))
  295. res.type(OutputFlag::TYPE_NUMBER);
  296. else if (dynamic_cast<const JSonObject*>(i))
  297. res.type(OutputFlag::TYPE_OBJ);
  298. else if (dynamic_cast<const JSonArray*>(i))
  299. res.type(OutputFlag::TYPE_ARR);
  300. return res;
  301. }
  302. void CurseOutput::checkSelection(const JSonElement *item, const std::pair<int, int> &cursor)
  303. {
  304. if (!selectFound)
  305. {
  306. if (selection == item)
  307. {
  308. if (cursor.second < scrollTop) //Selection is above vp, move scroll pos to selection and start drawing
  309. scrollTop = cursor.second;
  310. selectFound = true;
  311. }
  312. else if (!item->getParent() || !dynamic_cast<const JSonObjectEntry*>(item->getParent()))
  313. select_up = item;
  314. }
  315. else if (!select_down)
  316. {
  317. const JSonElement *parent = item->getParent();
  318. if (!dynamic_cast<const JSonContainer*>(item) && parent && selection != parent && dynamic_cast<const JSonObjectEntry*>(parent))
  319. item = parent;
  320. if (!parent || !dynamic_cast<const JSonObjectEntry*>(parent))
  321. select_down = item;
  322. }
  323. }
  324. /**
  325. * Read input and expect signal
  326. * @Return true on:
  327. * - Windows resized
  328. * - Key press and need redraw
  329. * false on:
  330. * - exit signal
  331. **/
  332. bool CurseOutput::readInput()
  333. {
  334. while (!breakLoop)
  335. {
  336. int c;
  337. c = getch();
  338. switch (c)
  339. {
  340. case 'q':
  341. case 'Q':
  342. return false;
  343. case KEY_UP:
  344. case 'K':
  345. case 'k':
  346. selection = select_up;
  347. return true;
  348. case KEY_DOWN:
  349. case 'j':
  350. case 'J':
  351. if (selectIsLast)
  352. scrollTop += 2;
  353. else if (selection != select_down)
  354. selection = select_down;
  355. else
  356. break;
  357. return true;
  358. case KEY_PPAGE:
  359. {
  360. const JSonElement *brother = selection->findPrev();
  361. if (brother == nullptr)
  362. {
  363. const JSonElement *parent = selection->getParent();
  364. if (parent && dynamic_cast<const JSonContainer*>(parent))
  365. {
  366. selection = parent;
  367. if (selection->getParent() && dynamic_cast<const JSonObjectEntry*> (selection->getParent()))
  368. selection = selection->getParent();
  369. }
  370. else
  371. break;
  372. }
  373. else
  374. selection = brother;
  375. return true;
  376. break;
  377. }
  378. case KEY_NPAGE:
  379. {
  380. const JSonElement *brother = selection->findNext();
  381. if (brother)
  382. {
  383. selection = brother;
  384. return true;
  385. }
  386. break;
  387. }
  388. case 'l':
  389. case 'L':
  390. case KEY_RIGHT:
  391. {
  392. const JSonElement *_selection = selection;
  393. if (dynamic_cast<const JSonObjectEntry*>(selection))
  394. _selection = **((const JSonObjectEntry*)_selection);
  395. if (!dynamic_cast<const JSonContainer*>(_selection))
  396. break;
  397. if (collapsed.erase((const JSonContainer *)_selection))
  398. return true;
  399. if (!((const JSonContainer*)_selection)->size())
  400. break;
  401. selection = select_down;
  402. return true;
  403. }
  404. case 'h':
  405. case 'H':
  406. case KEY_LEFT:
  407. {
  408. const JSonElement *_selection = selection;
  409. if (dynamic_cast<const JSonObjectEntry*>(_selection))
  410. _selection = **((const JSonObjectEntry*)_selection);
  411. if (selection->getParent() && (!dynamic_cast<const JSonContainer*>(_selection)
  412. || collapsed.find((const JSonContainer *)_selection) != collapsed.end()
  413. || (dynamic_cast<const JSonContainer*>(_selection) && ((const JSonContainer*)_selection)->size() == 0)))
  414. {
  415. selection = selection->getParent();
  416. if (selection->getParent() && dynamic_cast<const JSonObjectEntry*>(selection->getParent()))
  417. selection = selection->getParent();
  418. }
  419. else if (_selection)
  420. collapsed.insert((const JSonContainer *)_selection);
  421. else
  422. break;
  423. return true;
  424. }
  425. case '/':
  426. {
  427. const SearchPattern *search_pattern = inputSearch();
  428. if (!search_pattern)
  429. return true;
  430. search_result.clear();
  431. if (search_pattern->isEmpty())
  432. return true;
  433. search(*search_pattern, data);
  434. delete search_pattern;
  435. }
  436. case 'n':
  437. case 'N':
  438. if (search_result.empty())
  439. this->redraw("Pattern not found");
  440. else if (jumpToNextSearch())
  441. return true;
  442. break;
  443. }
  444. }
  445. return false;
  446. }
  447. unsigned int CurseOutput::search(const SearchPattern &search_pattern, const JSonElement *current)
  448. {
  449. const JSonContainer *container = dynamic_cast<const JSonContainer *> (current);
  450. const JSonObjectEntry *objEntry = dynamic_cast<const JSonObjectEntry *> (current);
  451. unsigned int result =0;
  452. if (container)
  453. {
  454. if (!container->empty())
  455. for (const JSonElement *it : *container)
  456. result += search(search_pattern, it);
  457. }
  458. else
  459. {
  460. if (current && current->match(search_pattern))
  461. {
  462. if (current->getParent() && dynamic_cast<const JSonObjectEntry*>(current->getParent()))
  463. {
  464. if (current->getParent() != selection)
  465. search_result.push_back(current->getParent());
  466. }
  467. else
  468. search_result.push_back(current);
  469. result++;
  470. }
  471. if (objEntry)
  472. result += search(search_pattern, **objEntry);
  473. }
  474. result = search_result.size();
  475. return result;
  476. }
  477. bool CurseOutput::jumpToNextSearch(const JSonElement *current, bool &selectFound)
  478. {
  479. const JSonContainer *container = dynamic_cast<const JSonContainer *> (current);
  480. const JSonObjectEntry *objEntry = dynamic_cast<const JSonObjectEntry *> (current);
  481. if (selection == current)
  482. selectFound = true;
  483. if (container)
  484. {
  485. if (!container->empty())
  486. for (const JSonElement *it : *container)
  487. if (jumpToNextSearch(it, selectFound))
  488. return true;
  489. }
  490. else
  491. {
  492. if (current && std::find(search_result.cbegin(), search_result.cend(), current) != search_result.cend() && current != selection && selectFound)
  493. {
  494. selection = current;
  495. return true;
  496. }
  497. if (objEntry)
  498. if (jumpToNextSearch(**objEntry, selectFound))
  499. return true;
  500. }
  501. return false;
  502. }
  503. bool CurseOutput::jumpToNextSearch()
  504. {
  505. bool selectFound = false;
  506. bool res = jumpToNextSearch(data, selectFound);
  507. if (!res)
  508. {
  509. selection = *(search_result.cbegin());
  510. unfold(selection);
  511. redraw("Search hit BOTTOM, continuing at TOP");
  512. return false;
  513. }
  514. unfold(selection);
  515. return true;
  516. }
  517. void CurseOutput::unfold(const JSonElement *item)
  518. {
  519. while (item->getParent())
  520. {
  521. collapsed.erase((const JSonContainer*)item->getParent());
  522. item = item->getParent();
  523. }
  524. }
  525. const SearchPattern *CurseOutput::inputSearch()
  526. {
  527. std::wstring buffer;
  528. bool abort = false;
  529. curs_set(true);
  530. wtimeout(stdscr, -1);
  531. while (!abort)
  532. {
  533. int c;
  534. writeBottomLine(L'/' +buffer, OutputFlag::SPECIAL_SEARCH);
  535. refresh();
  536. c = getwchar();
  537. if (c == L'\r')
  538. break;
  539. else if (c == L'\b' || c == 127)
  540. {
  541. if (!buffer.empty())
  542. buffer.pop_back();
  543. }
  544. else if (c == 27)
  545. abort = true;
  546. else
  547. buffer += c;
  548. }
  549. wtimeout(stdscr, 150);
  550. curs_set(false);
  551. {
  552. const size_t size = buffer.size();
  553. char bytesString[size * sizeof(wchar_t)];
  554. wcstombs(&bytesString[0], buffer.c_str(), sizeof(bytesString));
  555. std::string str;
  556. if (params.isIgnoringUnicode())
  557. str = bytesString;
  558. else
  559. str = StreamConsumer::extractUnicode(bytesString);
  560. return abort ? nullptr : new SearchPattern(str);
  561. }
  562. }
  563. void CurseOutput::writeBottomLine(const std::string &buffer, short color) const
  564. {
  565. const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
  566. const size_t bufsize = buffer.size();
  567. if (params.colorEnabled())
  568. attron(COLOR_PAIR(color));
  569. mvprintw(screenSize.second -1, 0, "%s%*c", buffer.c_str(), screenSize.first - bufsize, ' ');
  570. move(screenSize.second -1, bufsize);
  571. if (params.colorEnabled())
  572. attroff(COLOR_PAIR(color));
  573. }
  574. void CurseOutput::writeBottomLine(const std::wstring &buffer, short color) const
  575. {
  576. const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
  577. const size_t bufsize = buffer.size();
  578. if (params.colorEnabled())
  579. attron(COLOR_PAIR(color));
  580. mvprintw(screenSize.second -1, 0, "%S%*c", buffer.c_str(), screenSize.first - bufsize, ' ');
  581. move(screenSize.second -1, bufsize);
  582. if (params.colorEnabled())
  583. attroff(COLOR_PAIR(color));
  584. }