curseSimpleOutput.hh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /**
  54. * Root item
  55. **/
  56. JSonElement *data;
  57. const JSonElement *selection;
  58. /**
  59. * Viewport start
  60. **/
  61. int scrollTop;
  62. /**
  63. * currently searching pattern and its results
  64. **/
  65. std::list<const JSonElement*> search_result;
  66. /**
  67. * prev/next items to be selected on up/down keys
  68. **/
  69. const JSonElement *select_up, *select_down;
  70. };