1
1

curseSimpleOutput.hh 3.0 KB

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