MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / read_image_windows

Function read_image_windows

crates/opencode-tui/src/ui/clipboard.rs:243–271  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

241}
242
243fn read_image_windows() -> anyhow::Result<String> {
244 let ps_script = concat!(
245 "Add-Type -AssemblyName System.Windows.Forms; ",
246 "$img = [System.Windows.Forms.Clipboard]::GetImage(); ",
247 "if ($img -eq $null) { exit 1 }; ",
248 "$ms = New-Object System.IO.MemoryStream; ",
249 "$img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); ",
250 "[Convert]::ToBase64String($ms.ToArray())"
251 );
252
253 let output = Command::new("powershell")
254 .args(&["-NoProfile", "-Command", ps_script])
255 .output()
256 .context("failed to execute PowerShell for clipboard image")?;
257
258 if !output.status.success() {
259 anyhow::bail!(
260 "PowerShell clipboard image read failed with status {}",
261 output.status
262 );
263 }
264
265 let b64 = String::from_utf8_lossy(&output.stdout).trim().to_string();
266 if b64.is_empty() {
267 anyhow::bail!("PowerShell clipboard image read returned empty output");
268 }
269
270 Ok(b64)
271}

Callers 1

Calls 4

newFunction · 0.85
outputMethod · 0.80
is_emptyMethod · 0.80
successMethod · 0.45

Tested by

no test coverage detected