kill_ring.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <string>
  3. #include <deque>
  4. #include <cstddef>
  5. namespace lumacs {
  6. /// Emacs-style kill ring for cut/copy/paste operations
  7. /// Maintains a circular buffer of killed/copied text
  8. class KillRing {
  9. public:
  10. /// Constructor with optional maximum size
  11. /// @param max_size Maximum number of entries to keep (default: 60)
  12. explicit KillRing(size_t max_size = 60);
  13. /// Push new text to the kill ring
  14. /// @param text Text to add to the ring
  15. void push(std::string text);
  16. /// Get the current entry in the kill ring
  17. /// @return Current text, or empty string if ring is empty
  18. std::string current() const;
  19. /// Move to previous entry and return it
  20. /// @return Previous text in the ring
  21. std::string previous();
  22. /// Move to next entry and return it
  23. /// @return Next text in the ring
  24. std::string next();
  25. /// Check if the kill ring is empty
  26. /// @return true if the ring contains no entries
  27. bool empty() const noexcept;
  28. /// Get the number of entries in the ring
  29. /// @return Number of entries currently stored
  30. size_t size() const noexcept;
  31. /// Clear all entries from the ring
  32. void clear();
  33. /// Enable append mode for the next push operation
  34. /// When append mode is active, the next push will append to the current entry
  35. /// instead of creating a new one
  36. void set_append_next(bool append = true) { append_next_ = append; }
  37. private:
  38. std::deque<std::string> ring_; ///< The circular buffer of text entries
  39. size_t max_size_; ///< Maximum number of entries to keep
  40. size_t current_index_ = 0; ///< Current position in the ring
  41. bool append_next_ = false; ///< Whether to append to current entry on next push
  42. };
  43. } // namespace lumacs