curseSplitOutput.hh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 unsigned int &x, const unsigned int &y, const char item, unsigned int maxWidth, OutputFlag flags);
  44. unsigned int write(const unsigned int &x, const unsigned 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. virtual void writeBottomLine(const std::string &currentBuffer, short color) const;
  51. virtual void writeBottomLine(const std::wstring &currentBuffer, short color) const;
  52. unsigned int search(const SearchPattern &searchPattern);
  53. unsigned int search(const SearchPattern &searchPattern, const JSonElement *current);
  54. /**
  55. * get the screen size
  56. **/
  57. const t_Cursor getScreenSize() const;
  58. /**
  59. * Release ncurses
  60. **/
  61. void shutdown();
  62. void destroyAllSubWin();
  63. /**
  64. * get flags to be passed to write.
  65. * Contains indications on who to write item
  66. **/
  67. const OutputFlag getFlag(const JSonElement *item) const;
  68. const OutputFlag getFlag(const JSonElement *item, const JSonElement *selection) const;
  69. protected:
  70. inputResult selectUp();
  71. inputResult selectDown();
  72. inputResult selectPUp();
  73. inputResult selectPDown();
  74. inputResult expandSelection();
  75. inputResult collapseSelection();
  76. inputResult initSearch();
  77. inputResult nextResult();
  78. inputResult changeWindow(char, bool);
  79. void onResizeHandler();
  80. void setSelection(const JSonElement *);
  81. void computeDiff();
  82. std::deque<t_subWindow> subWindows;
  83. /**
  84. * currently searching pattern and its results
  85. **/
  86. const LevenshteinMatrice_base *diffMatrice;
  87. /**
  88. * Viewport start
  89. **/
  90. unsigned short nbInputs, selectedWin, workingWin;
  91. WINDOW *bottomLine;
  92. // TODO t_subWindow &workingSubwin, &selectedSubwin ??
  93. };