Skip to content

Commit b50ffd2

Browse files
committed
Use OSC 52 for copying
1 parent f09283e commit b50ffd2

File tree

4 files changed

+22
-99
lines changed

4 files changed

+22
-99
lines changed

Cargo.lock

Lines changed: 7 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ path = "src/main.rs"
3636
[dependencies]
3737
anyhow = "1.0.44"
3838
assert_matches = "1.5.0"
39+
base64 = "0.13.0"
3940
clap = { version = "3.1.8", features = ["cargo"] }
40-
clipboard = "0.5.0"
4141
crossterm = { version = "0.23.2", features = ["event-stream"] }
4242
dunce = "1.0.2"
4343
# Excluded "textfilter" feature that depends on regex (~0.7 MiB).

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,12 @@ server and a client, which allows the client to detach and reattach later,
334334
keeping the processes running. _mprocs_ is meant more for finite lifetime
335335
processes that you keep re-running, but when _mprocs_ ends, so do the processes
336336
it is running within its windows.
337+
338+
### Copying doesn't work in tmux
339+
340+
Tmux doesn't have escape sequences for copying enabled by default. To enable it
341+
add the following to `~/.tmux.conf`:
342+
343+
```
344+
set -g set-clipboard on
345+
```

src/app.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -746,18 +746,11 @@ impl App {
746746
if let CopyMode::Range(screen, start, end) = &proc.copy_mode {
747747
let (low, high) = Pos::to_low_high(start, end);
748748
let text = screen.get_selected_text(low.x, low.y, high.x, high.y);
749-
let ctx: Result<clipboard::ClipboardContext, _> =
750-
clipboard::ClipboardProvider::new();
751-
match ctx {
752-
Ok(mut ctx) => {
753-
match clipboard::ClipboardProvider::set_contents(&mut ctx, text)
754-
{
755-
Ok(()) => (),
756-
Err(err) => log::warn!("Failed to copy: {}", err),
757-
}
758-
}
759-
Err(err) => log::warn!("Failed to get clipboard: {}", err),
760-
}
749+
750+
let mut stdout = std::io::stdout().lock();
751+
use std::io::Write;
752+
let _r =
753+
write!(&mut stdout, "\x1b]52;;{}\x07", base64::encode(&text));
761754
}
762755
proc.copy_mode = CopyMode::None(None);
763756
}

0 commit comments

Comments
 (0)