curseOutput.hh 2.4 KB

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