curseSimpleOutput.hh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. 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);
  38. 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);
  39. bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *);
  40. bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement *> * obj);
  41. bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &, JSonElement *);
  42. Optional<bool> evalKey(int k);
  43. void checkSelection(const JSonElement *item, const std::pair<int, int> &cursor);
  44. protected:
  45. /**
  46. * Root item
  47. **/
  48. JSonElement *data;
  49. const JSonElement *selection;
  50. /**
  51. * Viewport start
  52. **/
  53. int scrollTop;
  54. /**
  55. * currently searching pattern and its results
  56. **/
  57. std::list<const JSonElement*> search_result;
  58. /**
  59. * prev/next items to be selected on up/down keys
  60. **/
  61. const JSonElement *select_up, *select_down;
  62. };