curseSplitOutput.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include <deque>
  3. #include <stack>
  4. #include "curseOutput.hh"
  5. #include "levenshtein.hpp"
  6. #include "jsonContainer.hh"
  7. class LevenshteinMatrice_base;
  8. typedef struct
  9. {
  10. std::string fileName;
  11. JSonElement *root;
  12. const JSonElement *selection, *select_up, *select_down;
  13. WINDOW *innerWin, *outerWin;
  14. std::list<const JSonElement*> searchResults;
  15. unsigned int scrollTop;
  16. t_Cursor cursor;
  17. std::stack<JSonContainer::const_iterator> parentsIterators;
  18. bool selectFound, selectIsLast;
  19. } t_subWindow;
  20. class CurseSplitOutput: public CurseOutput
  21. {
  22. public:
  23. CurseSplitOutput(const Params &);
  24. virtual ~CurseSplitOutput();
  25. /**
  26. * Display data, and shutdown ncurses at the end
  27. **/
  28. void run(const std::deque<std::string> &, const std::deque<JSonElement *> &);
  29. void checkSelection(const JSonElement *item);
  30. bool redraw();
  31. bool redraw(const t_Cursor &screenSize, JSonContainer::const_iterator, bool isRoot =false);
  32. bool redraw(const t_Cursor &screenSize, JSonElement *, bool isRoot =false);
  33. bool writeContainer(const t_Cursor &maxSize, JSonContainer *);
  34. bool writeContent(const t_Cursor &maxSize, std::list<JSonElement*> *_item);
  35. bool writeKey(const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen =0);
  36. bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);
  37. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
  38. unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
  39. void write(const std::string &str, const OutputFlag flags) const;
  40. void writeTopLine(const std::string &currentBuffer, short color) const;
  41. bool jumpToNextSearch(const JSonElement *current, bool &selectFound);
  42. bool jumpToNextSearch();
  43. unsigned int search(const SearchPattern &searchPattern);
  44. unsigned int search(const SearchPattern &searchPattern, const JSonElement *current);
  45. /**
  46. * get the screen size
  47. **/
  48. const t_Cursor getScreenSize() const;
  49. /**
  50. * Release ncurses
  51. **/
  52. void shutdown();
  53. void destroyAllSubWin();
  54. /**
  55. * get flags to be passed to write.
  56. * Contains indications on who to write item
  57. **/
  58. const OutputFlag getFlag(const JSonElement *item) const;
  59. const OutputFlag getFlag(const JSonElement *item, const JSonElement *selection) const;
  60. protected:
  61. inputResult selectUp();
  62. inputResult selectDown();
  63. inputResult selectPUp();
  64. inputResult selectPDown();
  65. inputResult expandSelection();
  66. inputResult collapseSelection();
  67. inputResult initSearch();
  68. inputResult nextResult();
  69. inputResult changeWindow(char, bool);
  70. void computeDiff();
  71. std::deque<t_subWindow> subWindows;
  72. /**
  73. * currently searching pattern and its results
  74. **/
  75. const LevenshteinMatrice_base *diffMatrice;
  76. /**
  77. * Viewport start
  78. **/
  79. unsigned short nbInputs, selectedWin, workingWin;
  80. class reachNext {};
  81. // TODO t_subWindow &workingSubwin, &selectedSubwin ??
  82. };