curseSimpleOutput.hh 2.7 KB

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