1
1

curseSplitOutput.hh 3.2 KB

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