1
1

curseOutput.hh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. void redraw();
  25. /**
  26. * return false if bottom of screen is touched
  27. **/
  28. bool redraw(std::pair<int, int> &, const std::pair<int, int>&, const JSonElement *, const JSonContainer *);
  29. bool readInput();
  30. void getScreenSize(std::pair<int, int> &, std::pair<int, int> &);
  31. static CurseOutput::t_nextKey findNext(const JSonElement *);
  32. void checkSelection(const JSonElement *item, const JSonElement *parent);
  33. void write(const int &x, const int &y, const JSonElement *item, bool selected =false);
  34. void write(const int &x, const int &y, const std::string &item, bool selected =false);
  35. void write(const int &x, const int &y, const char item, bool selected =false);
  36. void write(const int &x, const int &y, const char *item, bool selected =false);
  37. bool writeKey(const std::string &key, std::pair<int, int> &cursor, const int maxHeight, bool selected);
  38. bool writeContainer(std::pair<int, int> &, const std::pair<int, int>&, const JSonContainer *);
  39. bool writeContent(std::pair<int, int> &cursor, const std::pair<int, int> &maxSize, const JSonArray * obj);
  40. bool writeContent(std::pair<int, int> &cursor, const std::pair<int, int> &maxSize, const JSonObject * obj);
  41. std::set<const JSonContainer *> collapsed;
  42. const JSonElement *data, *selection;
  43. SCREEN *screen;
  44. FILE *screen_fd;
  45. bool breakLoop;
  46. std::pair<std::pair<unsigned int, unsigned int>, const JSonElement *> topleft;
  47. const unsigned int indentLevel;
  48. //FIXME optimize
  49. const JSonElement *select_up, *select_down, *select_parent;
  50. bool selectFound;
  51. };