curseOutput.hh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <ncurses.h>
  3. #include <fstream>
  4. #include <set>
  5. #include <list>
  6. class JSonElement;
  7. class JSonContainer;
  8. class JSonArray;
  9. class JSonObject;
  10. template<class T> class Optional;
  11. class CurseOutput
  12. {
  13. public:
  14. CurseOutput(JSonElement *rootData);
  15. virtual ~CurseOutput();
  16. void run();
  17. bool onsig(int signo);
  18. private:
  19. virtual void loop();
  20. protected:
  21. void init();
  22. void shutdown();
  23. /**
  24. * return false if bottom of screen is touched
  25. **/
  26. bool redraw();
  27. bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxWidth, const JSonElement *, const JSonContainer *);
  28. bool readInput();
  29. void getScreenSize(std::pair<unsigned int, unsigned int> &, std::pair<int, int> &) const;
  30. void checkSelection(const JSonElement *item, const JSonElement *parent, const std::pair<int, int>&);
  31. static unsigned int getNbLines(float nbChar, unsigned int maxWidth);
  32. unsigned int write(const int &x, const int &y, const JSonElement *item, unsigned int maxWidth, bool selected =false);
  33. unsigned int write(const int &x, const int &y, const std::string &item, unsigned int maxWidth, bool selected =false);
  34. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, bool selected =false);
  35. unsigned int write(const int &x, const int &y, const char *item, unsigned int maxWidth, bool selected =false);
  36. bool writeKey(const std::string &key, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, bool selected);
  37. bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *);
  38. bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const std::list<JSonElement *> * obj);
  39. std::set<const JSonContainer *> collapsed;
  40. const JSonElement *data, *selection;
  41. SCREEN *screen;
  42. FILE *screen_fd;
  43. bool breakLoop;
  44. int topleft;
  45. const unsigned int indentLevel;
  46. const JSonElement *select_up, *select_down;
  47. bool selectFound, selectIsLast, selectIsFirst;
  48. };