1 module clipboard_linux;
2 
3 version(linux) {
4 	import std.process;
5 	import std.algorithm;
6 	import std.array;
7 
8 	/**
9 		Read a string from the clipboard.
10 	*/
11 	public wstring readClipboard() {
12 		auto clip = pipeProcess(["xclip", "-out", "-selection", "clipboard"], Redirect.stdout);
13 		scope(exit) {
14 			wait(dot.pid);
15 		}
16 
17 		return clip.stdout.byChunk(4096).joiner().array;
18 	}
19 
20 	/**
21 		Write a string to the clipboard.
22 	*/
23 	public void writeClipboard(wstring text) {
24 		auto clip = pipeProcess(["xclip", "-in", "-selection", "clipboard"], Redirect.stdin);
25 		scope(exit) {
26 			wait(dot.pid);
27 		}
28 
29 		clip.stdin.write(text);
30 		clip.stdin.flush();
31 		clip.stdin.close();
32 	}
33 
34 	/**
35 		Clears the clipboard.
36 	*/
37 	public void clearClipboard() {
38 		writeClipboard(""w);
39 	}
40 
41 	/**
42 		Prepare the console in order to read and write UTF8 strings.
43 	*/
44 	public void prepareConsole() {
45 	}
46 }