Skip to content

Commit 7ecb4c9

Browse files
committed
feat: strip OSC paste codes
Relates to #104
1 parent eb2907d commit 7ecb4c9

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ env:
2121
CARGO_TERM_COLOR: always
2222
RUST_VERSION: 1.87.0
2323
RUST_BACKTRACE: 1
24+
RUST_LOG: "trace,tattoy_wezterm_term=off"
2425

2526
jobs:
2627
build-test:
@@ -71,7 +72,7 @@ jobs:
7172
--no-fail-fast --retries 2
7273
- name: Output e2e test logs (on failure)
7374
if: failure()
74-
run: cat crates/tests/tattoy.log
75+
run: cat crates/tests/tests.log
7576

7677
lints:
7778
name: "Lints 💅"

Cargo.lock

Lines changed: 2 additions & 2 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
@@ -23,7 +23,7 @@ tracing = "0.1.40"
2323
tracing-subscriber = {version = "0.3.18", features = ["env-filter"]}
2424

2525
[workspace.dependencies.shadow-terminal]
26-
version = "0.2.2"
26+
version = "0.2.3"
2727
# path = "../shadow-terminal/shadow-terminal/"
2828

2929
# Canonical lints for whole crate

crates/tattoy/src/tattoys/tattoyer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Tattoyer {
8383
message: crate::run::Protocol,
8484
) -> Result<()> {
8585
tracing::trace!(
86-
"'{}' tattoy recevied protocol message: {message:?}",
86+
"'{}' tattoy received protocol message: {message:?}",
8787
self.id
8888
);
8989

crates/tattoy/src/terminal_proxy/input_handler.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,25 @@ impl crate::terminal_proxy::proxy::Proxy {
1414
return Ok(());
1515
}
1616

17-
self.forward_input_to_pty(input).await
17+
self.forward_input_to_pty(input.to_owned()).await
1818
}
1919

2020
/// Forward raw input bytes to the underlying PTY.
21-
async fn forward_input_to_pty(&self, input: &crate::raw_input::ParsedInput) -> Result<()> {
21+
async fn forward_input_to_pty(&self, input: crate::raw_input::ParsedInput) -> Result<()> {
22+
// If the input is from an OSC paste event, then only forward the contents of the paste,
23+
// and not the surrounding OSC codes.
24+
let bytes = if let termwiz::input::InputEvent::Paste(string) = input.event {
25+
string.into_bytes()
26+
} else {
27+
input.bytes
28+
};
29+
2230
tracing::trace!(
2331
"Terminal proxy received input bytes: {}",
24-
String::from_utf8_lossy(&input.bytes)
32+
String::from_utf8_lossy(&bytes)
2533
);
26-
for chunk in input.bytes.chunks(128) {
34+
35+
for chunk in bytes.chunks(128) {
2736
let mut buffer: crate::raw_input::BytesFromSTDIN = [0; 128];
2837
for (i, chunk_byte) in chunk.iter().enumerate() {
2938
let buffer_byte = buffer.get_mut(i).context("Couldn't get byte from buffer")?;

crates/tests/e2e.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn basic_interactivity() {
1515

1616
crate::utils::assert_random_walker_moves(&mut tattoy).await;
1717

18-
tattoy.send_command("echo $((1+1))").unwrap();
18+
tattoy.send_command_with_osc_paste("echo $((1+1))").unwrap();
1919
tattoy.wait_for_string("2", None).await.unwrap();
2020

2121
crate::utils::assert_random_walker_moves(&mut tattoy).await;
@@ -112,7 +112,7 @@ async fn scrolling() {
112112

113113
let (mut tattoy, _) = crate::utils::start_tattoy(None).await;
114114
tattoy
115-
.send_command("cat resources/LOREM_IPSUM.txt")
115+
.send_command_with_osc_paste("cat resources/LOREM_IPSUM.txt")
116116
.unwrap();
117117
assert_scrolling_off(&mut tattoy).await;
118118

@@ -136,7 +136,7 @@ async fn palette_to_true_colour() {
136136
let (mut tattoy, _) = crate::utils::start_tattoy(None).await;
137137

138138
tattoy
139-
.send_command("echo -e \"\\033[0;31m$((1000-1))\\033[m\"")
139+
.send_command_with_osc_paste("echo -e \"\\033[0;31m$((1000-1))\\033[m\"")
140140
.unwrap();
141141
tattoy.wait_for_string("999", None).await.unwrap();
142142

@@ -157,7 +157,7 @@ async fn minimap() {
157157
let size = tattoy.shadow_terminal.terminal.get_size();
158158

159159
tattoy
160-
.send_command("cat resources/LOREM_IPSUM.txt")
160+
.send_command_with_osc_paste("cat resources/LOREM_IPSUM.txt")
161161
.unwrap();
162162
tattoy.wait_for_string("nulla", None).await.unwrap();
163163
tattoy
@@ -218,7 +218,7 @@ async fn plugins() {
218218
conf_file.write_all(config.as_bytes()).unwrap();
219219

220220
let (mut tattoy, _) = crate::utils::start_tattoy(Some(conf_dir.to_string_lossy().into())).await;
221-
tattoy.send_command("ls").unwrap();
221+
tattoy.send_command_with_osc_paste("ls").unwrap();
222222
let size = tattoy.shadow_terminal.terminal.get_size();
223223
let bottom = size.rows - 1;
224224
let right = size.cols - 1;
@@ -305,9 +305,11 @@ async fn auto_text_contrast() {
305305
bg.relative_contrast(fg)
306306
}
307307

308+
crate::utils::setup_logging();
309+
308310
let (mut tattoy, _) = crate::utils::start_tattoy(None).await;
309311
tattoy
310-
.send_command("resources/print_low_contrast_samples.sh")
312+
.send_command_with_osc_paste("resources/print_low_contrast_samples.sh")
311313
.unwrap();
312314
tattoy.wait_for_string("middle", None).await.unwrap();
313315
tattoy.wait_for_string("dark", None).await.unwrap();

0 commit comments

Comments
 (0)