1
1

curseOutput.hh 1.6 KB

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