use std::collections::VecDeque;
const MAX_ITEMS: usize = 60;
pub struct KillRing {
items: VecDeque<String>,
}
#[derive(Debug, Clone, Copy)]
pub struct PutCycle {
pub at: usize,
pub chars: usize,
pub index: usize,
}
impl KillRing {
pub fn new() -> Self {
KillRing {
items: VecDeque::new(),
}
}
pub fn push(&mut self, text: String) {
if text.is_empty() {
return;
}
if let Ok(mut cb) = arboard::Clipboard::new() {
let _ = cb.set_text(&text);
}
self.items.push_front(text);
self.items.truncate(MAX_ITEMS);
}
pub fn top(&mut self) -> Option<String> {
if self.items.is_empty() {
if let Ok(text) = arboard::Clipboard::new().and_then(|mut cb| cb.get_text()) {
if !text.is_empty() {
self.items.push_front(text);
}
}
}
self.items.front().cloned()
}
pub fn get(&self, index: usize) -> Option<&String> {
self.items.get(index)
}
pub fn len(&self) -> usize {
self.items.len()
}
}
impl Default for KillRing {
fn default() -> Self {
Self::new()
}
}