curseOutput.hh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <fstream>
  3. #include <ios>
  4. #include <set>
  5. #include <ncurses.h>
  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. typedef Optional<std::pair<Optional<const std::string>, const JSonElement *> > t_nextKey;
  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 CurseOutput::t_nextKey findPrev(const JSonElement *);
  32. static CurseOutput::t_nextKey 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 JSonArray * obj);
  42. bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const JSonObject * obj);
  43. std::set<const JSonContainer *> collapsed;
  44. const JSonElement *data, *selection;
  45. SCREEN *screen;
  46. FILE *screen_fd;
  47. bool breakLoop;
  48. int topleft;
  49. const unsigned int indentLevel;
  50. //FIXME optimize
  51. const JSonElement *select_up, *select_down;
  52. bool selectFound, selectIsLast, selectIsFirst;
  53. };