curseOutput.hh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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<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 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. void write(const int &x, const int &y, const JSonElement *item, bool selected =false);
  35. void write(const int &x, const int &y, const std::string &item, bool selected =false);
  36. void write(const int &x, const int &y, const char item, bool selected =false);
  37. void write(const int &x, const int &y, const char *item, bool selected =false);
  38. bool writeKey(const std::string &key, std::pair<int, int> &cursor, const int maxHeight, bool selected);
  39. bool writeContainer(std::pair<int, int> &, const std::pair<int, int>&, const JSonContainer *);
  40. bool writeContent(std::pair<int, int> &cursor, const std::pair<int, int> &maxSize, const JSonArray * obj);
  41. bool writeContent(std::pair<int, int> &cursor, const std::pair<int, int> &maxSize, const JSonObject * 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. };