Skip to main content

codetether_agent/cli/
clipboard.rs

1//! Clipboard bridge CLI commands.
2
3use anyhow::Result;
4use clap::{Parser, Subcommand};
5
6/// Clipboard bridge arguments.
7#[derive(Parser, Debug)]
8pub struct ClipboardArgs {
9    /// Clipboard bridge operation to run.
10    #[command(subcommand)]
11    pub command: ClipboardCommand,
12}
13
14/// Clipboard bridge subcommands.
15#[derive(Subcommand, Debug)]
16pub enum ClipboardCommand {
17    /// Copy the local clipboard image as text for pasting over SSH
18    Image(ClipboardImageArgs),
19}
20
21/// Arguments for copying a clipboard image into pasteable text.
22#[derive(Parser, Debug)]
23pub struct ClipboardImageArgs {
24    /// Print the data URL instead of copying it back to the clipboard
25    #[arg(long)]
26    pub print: bool,
27}
28
29/// Execute a clipboard bridge subcommand.
30///
31/// # Errors
32///
33/// Returns an error when the requested clipboard operation cannot read or
34/// write the system clipboard.
35pub fn execute(args: ClipboardArgs) -> Result<()> {
36    match args.command {
37        ClipboardCommand::Image(args) => image(args.print),
38    }
39}
40
41fn image(print: bool) -> Result<()> {
42    let image = crate::image_clipboard::capture_image()?;
43    if print {
44        println!("{}", image.data_url);
45        return Ok(());
46    }
47    crate::image_clipboard::copy_text(&image.data_url)?;
48    eprintln!("Copied image paste text. Paste it into the remote CodeTether TUI.");
49    Ok(())
50}