curseSplitOutput.hh 3.5 KB

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