1
0
Fork 0
forked from AbleOS/ableos
ableos_time/ableos/src/experiments/clip.rs

54 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-24 07:03:15 -06:00
use alloc::{string::String, vec, vec::Vec};
2022-04-11 17:23:11 -05:00
pub static CLIPBOARD: spin::Mutex<Clipboard> = spin::Mutex::new(Clipboard::new());
2021-11-16 00:09:27 -06:00
#[derive(Debug)]
pub enum Mime {
None,
Text(String),
}
// ctrl+v paste but not pop and pastes
// ctrl+shift+v pops from the stack and pastes
// ctrl+c pushes to the stack
// ctrl+shift+< move stack pointer left
// ctrl+shift+> move stack pointer right
pub struct Clipboard {
pub index: usize,
pub pages: Vec<Mime>,
}
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
impl Clipboard {
pub const fn new() -> Clipboard {
2021-11-16 00:09:27 -06:00
Clipboard {
index: 0,
pages: vec![],
}
}
2021-11-16 00:09:27 -06:00
pub fn clear(&mut self) {
self.pages = vec![];
}
2021-11-16 00:09:27 -06:00
pub fn set_index(&mut self, index_new: usize) {
self.index = index_new;
}
2021-11-16 00:09:27 -06:00
pub fn clip_end(&mut self) {
self.index = 0;
}
2021-11-16 00:09:27 -06:00
pub fn clip_home(&mut self) {
self.index = self.pages.len();
}
2021-11-16 00:09:27 -06:00
pub fn copy(&mut self, copy_mime: Mime) {
self.pages.push(copy_mime);
}
2021-11-16 00:09:27 -06:00
pub fn paste(&mut self) -> &Mime {
&self.pages[self.index] as _
2021-11-16 00:09:27 -06:00
}
}