1
1

curseOutput.hh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * curseOutput.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include <ncurses.h>
  8. #include <fstream>
  9. #include <list>
  10. #include <set>
  11. #include <map>
  12. #include "outputFlag.hh"
  13. #include "params.hh"
  14. class JSonElement;
  15. class JSonContainer;
  16. class JSonArray;
  17. class JSonObject;
  18. template<class T> class Optional;
  19. class CurseOutput
  20. {
  21. public:
  22. CurseOutput(JSonElement *rootData, const Params &);
  23. virtual ~CurseOutput();
  24. void run();
  25. bool onsig(int signo);
  26. private:
  27. virtual void loop();
  28. protected:
  29. void init();
  30. void shutdown();
  31. /**
  32. * return false if bottom of screen is touched
  33. **/
  34. bool redraw();
  35. bool redraw(const std::string &errorMsg);
  36. bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxWidth, const JSonElement *, const JSonContainer *);
  37. bool readInput();
  38. void getScreenSize(std::pair<unsigned int, unsigned int> &) const;
  39. void getScreenSize(std::pair<unsigned int, unsigned int> &, std::pair<int, int> &) const;
  40. void checkSelection(const JSonElement *item, const JSonElement *parent, const std::pair<int, int>&);
  41. static unsigned int getNbLines(float nbChar, unsigned int maxWidth);
  42. const OutputFlag getFlag(const JSonElement *item) const;
  43. void write(const std::string &str, unsigned int maxWidth, const OutputFlag flags) const;
  44. unsigned int write(const int &x, const int &y, const JSonElement *item, unsigned int maxWidth, const OutputFlag);
  45. unsigned int write(const int &x, const int &y, const std::string &item, unsigned int maxWidth, const OutputFlag);
  46. unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, const OutputFlag);
  47. bool writeKey(const std::string &key, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag, unsigned int extraLen =0);
  48. bool writeKey(const std::string &key, const std::string &after, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag);
  49. bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *);
  50. bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const std::list<JSonElement *> * obj);
  51. bool jumpToNextSearch(bool scanParent, bool redraw, const JSonElement *initial_selection);
  52. const std::string search();
  53. void writeBottomLine(const std::string &currentBuffer, short color) const;
  54. /**
  55. * unfold all item's parents
  56. **/
  57. void unfold(const JSonElement *);
  58. std::set<const JSonContainer *> collapsed;
  59. const JSonElement *data, *selection;
  60. const Params &params;
  61. std::string search_pattern;
  62. SCREEN *screen;
  63. FILE *screen_fd;
  64. bool breakLoop;
  65. int topleft;
  66. std::set<char> colors;
  67. const JSonElement *select_up, *select_down;
  68. bool selectFound, selectIsLast, selectIsFirst;
  69. };