curseSplitOutput.hh 4.0 KB

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