| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #pragma once
- #include <string>
- #include <deque>
- #include <cstddef>
- namespace lumacs {
- /// Emacs-style kill ring for cut/copy/paste operations
- /// Maintains a circular buffer of killed/copied text
- class KillRing {
- public:
- /// Constructor with optional maximum size
- /// @param max_size Maximum number of entries to keep (default: 60)
- explicit KillRing(size_t max_size = 60);
- /// Push new text to the kill ring
- /// @param text Text to add to the ring
- void push(std::string text);
- /// Get the current entry in the kill ring
- /// @return Current text, or empty string if ring is empty
- std::string current() const;
- /// Move to previous entry and return it
- /// @return Previous text in the ring
- std::string previous();
- /// Move to next entry and return it
- /// @return Next text in the ring
- std::string next();
- /// Check if the kill ring is empty
- /// @return true if the ring contains no entries
- bool empty() const noexcept;
- /// Get the number of entries in the ring
- /// @return Number of entries currently stored
- size_t size() const noexcept;
- /// Clear all entries from the ring
- void clear();
- /// Enable append mode for the next push operation
- /// When append mode is active, the next push will append to the current entry
- /// instead of creating a new one
- void set_append_next(bool append = true) { append_next_ = append; }
- private:
- std::deque<std::string> ring_; ///< The circular buffer of text entries
- size_t max_size_; ///< Maximum number of entries to keep
- size_t current_index_ = 0; ///< Current position in the ring
- bool append_next_ = false; ///< Whether to append to current entry on next push
- };
- } // namespace lumacs
|