1
1

curseSimpleOutput.hh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * curseOutput.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include "curseOutput.hh"
  8. class CurseSimpleOutput: public CurseOutput
  9. {
  10. public:
  11. CurseSimpleOutput(const Params &);
  12. ~CurseSimpleOutput();
  13. bool redraw();
  14. /**
  15. * Display data, and shutdown ncurses at the end
  16. **/
  17. void run(JSonElement *, const std::string &inputName);
  18. bool jumpToNextSearch(const JSonElement *current, bool &selectFound);
  19. bool jumpToNextSearch();
  20. unsigned int search(const SearchPattern &search_pattern, const JSonElement *current);
  21. /**
  22. * Release ncurses
  23. **/
  24. void shutdown();
  25. /**
  26. * get flags to be passed to write.
  27. * Contains indications on who to write item
  28. **/
  29. const OutputFlag getFlag(const JSonElement *item) const;
  30. const OutputFlag getFlag(const JSonElement *item, const JSonElement *selection) const;
  31. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
  32. unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
  33. void write(const std::string &str, const OutputFlag flags) const;
  34. bool writeKey(const std::string &key, const size_t keylen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag, unsigned int extraLen =0);
  35. bool writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, t_Cursor &cursor, const t_Cursor &maxSize, OutputFlag flags);
  36. bool writeKey(const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);
  37. bool writeContainer(t_Cursor &, const t_Cursor &maxSize, const JSonContainer *);
  38. bool writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement *> * obj);
  39. bool redraw(t_Cursor &, const t_Cursor &, JSonElement *);
  40. void checkSelection(const JSonElement *item, const t_Cursor &cursor);
  41. protected:
  42. inputResult selectUp();
  43. inputResult selectDown();
  44. inputResult selectPUp();
  45. inputResult selectPDown();
  46. inputResult expandSelection();
  47. inputResult collapseSelection();
  48. inputResult initSearch();
  49. inputResult nextResult();
  50. inputResult changeWindow(char, bool);
  51. /**
  52. * Root item
  53. **/
  54. JSonElement *data;
  55. const JSonElement *selection;
  56. /**
  57. * Viewport start
  58. **/
  59. unsigned int scrollTop;
  60. /**
  61. * currently searching pattern and its results
  62. **/
  63. std::list<const JSonElement*> search_result;
  64. /**
  65. * prev/next items to be selected on up/down keys
  66. **/
  67. const JSonElement *select_up, *select_down;
  68. /**
  69. * input name
  70. **/
  71. std::string inputName;
  72. /**
  73. * Selection helpers
  74. * Used for moving viewport
  75. **/
  76. bool selectFound, selectIsLast;
  77. };