curseSimpleOutput.hh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 *);
  18. bool jumpToNextSearch(const JSonElement *current, bool &selectFound);
  19. bool jumpToNextSearch();
  20. unsigned int search(const SearchPattern &search_pattern, const JSonElement *current);
  21. /**
  22. * Initialize ncurses
  23. **/
  24. void init();
  25. /**
  26. * Release ncurses
  27. **/
  28. void shutdown();
  29. /**
  30. * get flags to be passed to write.
  31. * Contains indications on who to write item
  32. **/
  33. const OutputFlag getFlag(const JSonElement *item) const;
  34. const OutputFlag getFlag(const JSonElement *item, const JSonElement *selection) const;
  35. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
  36. unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
  37. void write(const std::string &str, const OutputFlag flags) const;
  38. bool writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag, unsigned int extraLen =0);
  39. bool 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);
  40. bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *);
  41. bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement *> * obj);
  42. bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &, JSonElement *);
  43. void checkSelection(const JSonElement *item, const std::pair<int, int> &cursor);
  44. protected:
  45. inputResult selectUp();
  46. inputResult selectDown();
  47. inputResult selectPUp();
  48. inputResult selectPDown();
  49. inputResult expandSelection();
  50. inputResult collapseSelection();
  51. inputResult initSearch();
  52. inputResult nextResult();
  53. inputResult changeWindow(char, bool);
  54. /**
  55. * Root item
  56. **/
  57. JSonElement *data;
  58. const JSonElement *selection;
  59. /**
  60. * Viewport start
  61. **/
  62. int scrollTop;
  63. /**
  64. * currently searching pattern and its results
  65. **/
  66. std::list<const JSonElement*> search_result;
  67. /**
  68. * prev/next items to be selected on up/down keys
  69. **/
  70. const JSonElement *select_up, *select_down;
  71. };