curseSplitOutput.hh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, *lastSelection, *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<std::pair<int, JSonContainer*> > parentsIterators; // Offset in JSonContainer::list
  18. //TODO back to std::stack<JSonContainer::const_iterator> ?
  19. bool selectFound, selectIsLast;
  20. } t_subWindow;
  21. class CurseSplitOutput: public CurseOutput
  22. {
  23. public:
  24. CurseSplitOutput(const Params &);
  25. virtual ~CurseSplitOutput();
  26. /**
  27. * Display data, and shutdown ncurses at the end
  28. **/
  29. void run(const std::deque<std::string> &, const std::deque<JSonElement *> &);
  30. void checkSelection(const JSonElement *item);
  31. bool redraw();
  32. bool redraw(const t_Cursor &screenSize, std::pair<int, JSonContainer *> &);
  33. bool redraw(const t_Cursor &screenSize, JSonElement *);
  34. const Optional<bool> redrawOneItemToWorkingWin(t_subWindow &w, const t_Cursor &);
  35. bool isAdded(const std::pair<int, JSonContainer *> &) const;
  36. bool isAdded(const JSonElement *e) const;
  37. bool writeContainer(const t_Cursor &maxSize, JSonContainer *, bool opening = true);
  38. bool writeContent(const t_Cursor &maxSize, std::list<JSonElement*> *_item);
  39. bool writeKey(const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen =0);
  40. 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);
  41. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
  42. unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
  43. void write(const std::string &str, const OutputFlag flags) const;
  44. void displayDiffOp(WINDOW *w, const int &y, const eLevenshteinOperator &op) const;
  45. void writeTopLine(const std::string &currentBuffer, short color) const;
  46. bool jumpToNextSearch(const JSonElement *current, bool &selectFound);
  47. bool jumpToNextSearch();
  48. unsigned int search(const SearchPattern &searchPattern);
  49. unsigned int search(const SearchPattern &searchPattern, const JSonElement *current);
  50. /**
  51. * get the screen size
  52. **/
  53. const t_Cursor getScreenSize() const;
  54. /**
  55. * Release ncurses
  56. **/
  57. void shutdown();
  58. void destroyAllSubWin();
  59. /**
  60. * get flags to be passed to write.
  61. * Contains indications on who to write item
  62. **/
  63. const OutputFlag getFlag(const JSonElement *item) const;
  64. const OutputFlag getFlag(const JSonElement *item, const JSonElement *selection) const;
  65. protected:
  66. inputResult selectUp();
  67. inputResult selectDown();
  68. inputResult selectPUp();
  69. inputResult selectPDown();
  70. inputResult expandSelection();
  71. inputResult collapseSelection();
  72. inputResult initSearch();
  73. inputResult nextResult();
  74. inputResult changeWindow(char, bool);
  75. void setSelection(const JSonElement *);
  76. void computeDiff();
  77. std::deque<t_subWindow> subWindows;
  78. /**
  79. * currently searching pattern and its results
  80. **/
  81. const LevenshteinMatrice_base *diffMatrice;
  82. /**
  83. * Viewport start
  84. **/
  85. unsigned short nbInputs, selectedWin, workingWin;
  86. class reachNext {};
  87. // TODO t_subWindow &workingSubwin, &selectedSubwin ??
  88. };