curseSimpleOutput.hh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 writeContainer(t_Cursor &, const t_Cursor &maxSize, const JSonContainer *);
  37. bool writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement *> * obj);
  38. bool redraw(t_Cursor &, const t_Cursor &, JSonElement *);
  39. void checkSelection(const JSonElement *item, const t_Cursor &cursor);
  40. protected:
  41. inputResult selectUp();
  42. inputResult selectDown();
  43. inputResult selectPUp();
  44. inputResult selectPDown();
  45. inputResult expandSelection();
  46. inputResult collapseSelection();
  47. inputResult initSearch();
  48. inputResult nextResult();
  49. inputResult changeWindow(char, bool);
  50. /**
  51. * Root item
  52. **/
  53. JSonElement *data;
  54. const JSonElement *selection;
  55. /**
  56. * Viewport start
  57. **/
  58. unsigned int scrollTop;
  59. /**
  60. * currently searching pattern and its results
  61. **/
  62. std::list<const JSonElement*> search_result;
  63. /**
  64. * prev/next items to be selected on up/down keys
  65. **/
  66. const JSonElement *select_up, *select_down;
  67. /**
  68. * input name
  69. **/
  70. std::string inputName;
  71. /**
  72. * Selection helpers
  73. * Used for moving viewport
  74. **/
  75. bool selectFound, selectIsLast;
  76. };