adding tests and updating readme
parent
3a74e416e8
commit
2a86e7adac
11
README.md
11
README.md
|
@ -46,6 +46,7 @@
|
|||
- [Usage](#usage)
|
||||
- [Copy into the clipboard](#copy-into-the-clipboard)
|
||||
- [Copy into clipboard on Linux Wayland](#copy-into-clipboard-on-linux-wayland)
|
||||
- [Copy into clipboard on WSL](#copy-into-clipboard-on-wsl)
|
||||
- [Save the snapshot](#save-the-snapshot)
|
||||
- [Highlight code block](#highlight-code-block)
|
||||
- [How to use](#how-to-use)
|
||||
|
@ -169,6 +170,14 @@ Copy screenshots directly into the clipboard is cool, however, it doesn't work w
|
|||
|
||||
If you using CodeSnap.nvim on wl-clipboard, you can refer [wl-clip-persist](https://github.com/Linus789/wl-clip-persist), it reads all the clipboard data into memory and then overwrites the clipboard with the data from our memory to persist copied data.
|
||||
|
||||
|
||||
#### Copy into clipboard on WSL
|
||||
currently copy to clipboard in WSL works, but it has some potencial issues, inside of wsl normally is not possible to copy an image to the clipboard,
|
||||
how this works in wsl at this moment is the following, we create an image in the /tmp directory, then we try to execute powershell commands
|
||||
to copy the image to the clipboard
|
||||
> [!WARNING]
|
||||
> If the WSL distro name is not the default or the pretty_name/name in the /etc/os-release this feature will fai
|
||||
|
||||
### Save the snapshot
|
||||
|
||||
Of course, you can use `CodeSnapSave` command to save the snapshot to path where you defined it in `config.save_path`
|
||||
|
@ -181,6 +190,8 @@ require("codesnap").setup({
|
|||
-- parsed: "~/Pictures/CodeSnap_y-m-d_at_h:m:s.png"
|
||||
-- save_path = "~/Pictures/foo.png"
|
||||
-- parsed: "~/Pictures/foo.png"
|
||||
-- if you are on wsl and do you want to use a windows path
|
||||
-- save_path="/mnt/c/Users/user/Pictures/"
|
||||
save_path = ...
|
||||
})
|
||||
```
|
||||
|
|
|
@ -116,3 +116,56 @@ fn generate_random_filename() -> String {
|
|||
// Combine prefix, random part, and extension
|
||||
format!("codesnap_{}.png", random_part)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use super::copy_to_wsl_clipboard;
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn copy_to_wsl_test() -> std::result::Result<(), nvim_oxi::Error> {
|
||||
|
||||
if !wsl::is_wsl() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
//not sure about the best way to test this in a dynamic way
|
||||
//dir example
|
||||
//"\\\\wsl$\\DistroName\\\\home\\username\\path\\test.png";
|
||||
let src_path = "";// your director here
|
||||
return copy_to_wsl_clipboard(src_path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn check_if_folder_exist() {
|
||||
if !wsl::is_wsl() {
|
||||
return;
|
||||
}
|
||||
|
||||
let os_linux_release = sys_info::linux_os_release().unwrap();
|
||||
let wsl_path = format!(
|
||||
"\\\\wsl$\\{}",
|
||||
os_linux_release.name()
|
||||
);
|
||||
|
||||
println!("path {}", wsl_path);
|
||||
|
||||
let powershell = Command::new("/mnt/c/Windows//System32/WindowsPowerShell/v1.0/powershell.exe")
|
||||
.arg("-NoProfile")
|
||||
.arg("-Command")
|
||||
.arg(&format!("Test-Path -path \"{}\"", wsl_path))
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.output();
|
||||
|
||||
let stdout = String::from_utf8(powershell.unwrap().stdout).unwrap();
|
||||
|
||||
println!("output {:?}", stdout);
|
||||
println!("exist {}", stdout == "True\r\n");
|
||||
println!("does not exist {}", stdout == "False\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue