-
Notifications
You must be signed in to change notification settings - Fork 515
Add support for OSC52 clipboard codes for the REPL .copy command. #1280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/utils/clipboard.rs
Outdated
} | ||
|
||
#[cfg(any(target_os = "android", target_os = "emscripten"))] | ||
pub fn set_text(_text: &str) -> anyhow::Result<()> { | ||
Err(anyhow::anyhow!("No clipboard available").context("Failed to copy")) | ||
pub fn set_text(text: &str) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This function must return
anyhow::Result
, otherwise it will cause a compilation error.
-pub fn set_text(text: &str) -> Result<()> {
+pub fn set_text(text: &str) -> anyhow::Result<()> {
- Even in Android or WASM environments, OSC52 clipboard support is unlikely. I suggest leaving the function as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Fixed.
@gcv Thank you for your contribution. OSC52 clipboard code support is definitely necessary. However, there are a few minor issues; would you have time to fix them? |
Yes, I’ll fix those. I’m surprised I didn’t get compilation errors with that namespace problem. Edit: Probably because it’s conditionally compiled. |
I reversed the changes to the function handling unsupported platforms. Thanks for the code review! |
@gcv please fix clippy error https://github.com/sigoden/aichat/actions/runs/14840017582/job/41713010102?pr=1280 |
Clippy warnings fixed in the latest commit. |
Formatting fixed. |
The
.copy
REPL command does not work when aichat runs on a headless server. It appears that the arboard crate only works with graphical Linux interfaces, X11 and Wayland. When these are not available, it fails. This PR adds a fallback to use an OSC52 terminal codes to access the clipboard through the terminal emulator. This works on pretty much all modern emulators. Seems to work on my testing, and seems to work correctly under X11 (I don’t have a Wayland system to test with).Thanks for this excellent package! aichat is the best CLI/TUI LLM interface I found, and I use it every day.