You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

  1. // Buffer.h
  2. #ifndef _Buffer_h_
  3. #define _Buffer_h_
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <iostream>
  8. #include <string>
  9. #include <vector>
  10. class Buffer
  11. {
  12. public:
  13. void display() const;
  14. const std::string & file_name() const { return file_name_; }
  15. void move_to_next_page();
  16. void move_to_previous_page();
  17. bool open(const std::string & file_name);
  18. std::string* get_lines() const;
  19. void set_window_height(int h) { window_height_ = h; }
  20. private:
  21. std::vector<std::string> v_lines_;
  22. std::vector<std::pair<std::string, std::string>> v_links_;
  23. int ix_top_line_ = 0;
  24. std::string file_name_;
  25. int window_height_;
  26. };
  27. inline void Buffer::move_to_next_page()
  28. {
  29. ix_top_line_ += window_height_;
  30. if (ix_top_line_ >= v_lines_.size())
  31. ix_top_line_ -= window_height_;
  32. }
  33. inline void Buffer::move_to_previous_page()
  34. {
  35. ix_top_line_ -= window_height_;
  36. if (ix_top_line_ < 0)
  37. ix_top_line_ = 0;
  38. }
  39. #endif