yazi_core/spot/commands/
copy.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::borrow::Cow;

use yazi_plugin::CLIPBOARD;
use yazi_shared::event::CmdCow;

use crate::spot::Spot;

struct Opt {
	type_: Cow<'static, str>,
}

impl From<CmdCow> for Opt {
	fn from(mut c: CmdCow) -> Self { Self { type_: c.take_first_str().unwrap_or_default() } }
}

impl Spot {
	#[yazi_codegen::command]
	pub fn copy(&mut self, opt: Opt) {
		let Some(lock) = &self.lock else { return };
		let Some(table) = lock.table() else { return };

		let mut s = String::new();
		match opt.type_.as_ref() {
			"cell" => {
				let Some(cell) = table.selected_cell() else { return };
				s = cell.to_string();
			}
			"line" => {
				// TODO
			}
			_ => {}
		}

		futures::executor::block_on(CLIPBOARD.set(s));
	}
}