selection/
lib.rs

1// Project: selection
2// File: lib.rs
3// Created Date: 2023-06-04
4// Author: Pylogmon <pylogmon@outlook.com>
5
6#[cfg(target_os = "linux")]
7mod linux;
8#[cfg(target_os = "macos")]
9mod macos;
10#[cfg(target_os = "windows")]
11mod windows;
12
13#[cfg(target_os = "linux")]
14use crate::linux::get_text as _get_text;
15#[cfg(target_os = "macos")]
16use crate::macos::get_text as _get_text;
17#[cfg(target_os = "windows")]
18use crate::windows::get_text as _get_text;
19
20/// Get the text selected by the cursor
21///
22/// Return empty string if no text is selected or error occurred
23/// # Example
24///
25/// ```
26/// use selection::get_text;
27///
28/// let text = get_text();
29/// println!("{}", text);
30/// ```
31pub fn get_text() -> String {
32    _get_text().trim().to_owned()
33}
34
35#[cfg(test)]
36mod tests {
37    use crate::get_text;
38    #[test]
39    fn it_works() {
40        println!("{}", get_text());
41    }
42}