2021-12-24 07:03:15 -06:00
|
|
|
use alloc::{string::String, vec, vec::Vec};
|
|
|
|
// use crate::String;
|
|
|
|
// use crate::Vec;
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Mime {
|
|
|
|
None,
|
|
|
|
Text(String),
|
|
|
|
}
|
|
|
|
|
2022-04-11 15:51:54 -05:00
|
|
|
pub static CLIPBOARD: spin::Mutex<Clipboard> = spin::Mutex::new(Clipboard::new());
|
2021-11-16 00:09:27 -06:00
|
|
|
|
|
|
|
// 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>,
|
|
|
|
}
|
|
|
|
impl Clipboard {
|
2022-04-11 15:51:54 -05:00
|
|
|
pub const fn new() -> Clipboard {
|
2021-11-16 00:09:27 -06:00
|
|
|
Clipboard {
|
|
|
|
index: 0,
|
|
|
|
pages: vec![],
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn clear(&mut self) {
|
|
|
|
self.pages = vec![];
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn set_index(&mut self, index_new: usize) {
|
|
|
|
self.index = index_new;
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn clip_end(&mut self) {
|
|
|
|
self.index = 0;
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn clip_home(&mut self) {
|
|
|
|
self.index = self.pages.len();
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn copy(&mut self, copy_mime: Mime) {
|
|
|
|
self.pages.push(copy_mime);
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn paste(&mut self) -> &Mime {
|
2022-04-11 15:51:54 -05:00
|
|
|
&self.pages[self.index] as _
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
}
|