-
-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(copy): allow osc52 copy destination configuration (#1022)
add copy_cliboard option to allow configuring copy destination to primary selection instead of default clipboard
- Loading branch information
Showing
12 changed files
with
189 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use zellij_tile::prelude::CopyDestination; | ||
use zellij_utils::{anyhow::Result, input::options::Clipboard}; | ||
|
||
use crate::ClientId; | ||
|
||
use super::{copy_command::CopyCommand, Output}; | ||
|
||
pub(crate) enum ClipboardProvider { | ||
Command(CopyCommand), | ||
Osc52(Clipboard), | ||
} | ||
|
||
impl ClipboardProvider { | ||
pub(crate) fn set_content( | ||
&self, | ||
content: &str, | ||
output: &mut Output, | ||
client_ids: impl Iterator<Item = ClientId>, | ||
) -> Result<()> { | ||
match &self { | ||
ClipboardProvider::Command(command) => { | ||
command.set(content.to_string())?; | ||
} | ||
ClipboardProvider::Osc52(clipboard) => { | ||
let dest = match clipboard { | ||
#[cfg(not(target_os = "macos"))] | ||
Clipboard::Primary => 'p', | ||
#[cfg(target_os = "macos")] // primary selection does not exist on macos | ||
Clipboard::Primary => 'c', | ||
Clipboard::System => 'c', | ||
}; | ||
output.push_str_to_multiple_clients( | ||
&format!("\u{1b}]52;{};{}\u{1b}\\", dest, base64::encode(content)), | ||
client_ids, | ||
); | ||
} | ||
}; | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn as_copy_destination(&self) -> CopyDestination { | ||
match self { | ||
ClipboardProvider::Command(_) => CopyDestination::Command, | ||
ClipboardProvider::Osc52(clipboard) => match clipboard { | ||
Clipboard::Primary => CopyDestination::Primary, | ||
Clipboard::System => CopyDestination::System, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.