Incorrect content copied from terminal (Japanese Toothpaste?) #19440

Closed
opened 2026-01-31 06:43:22 +00:00 by claunia · 24 comments
Owner

Originally created by @dadastoor on GitHub (Feb 22, 2023).

Originally assigned to: @DHowett on GitHub.

Windows Terminal version

1.17.1023

Windows build number

10.0.19044.0

Other Software

tmux 3.0a

$ cat ~/.tmux.conf| without_comments
set -g default-shell /usr/bin/zsh
bind S source-file ~/.tmux/bastion-quad
set -g default-terminal "tmux-256color"
set -g history-file ~/.tmux_history
set -g history-limit 150000
set-environment -g 'IGNOREEOF' 10
set -g prefix `
unbind -n C-l
unbind -n C-t
unbind -n C-u
unbind -n C-y
unbind -n C-d
unbind -n C-b
unbind C-d
bind ` send-prefix
bind r source-file ~/.tmux.conf \; display "Tmux config reloaded"
bind c new-window -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind = split-window -h -c "#{pane_current_path}"
bind -n C-S-Left swap-window -t -1\; select-window -t -1
bind -n C-S-Right swap-window -t +1\; select-window -t +1
bind -n C-o select-pane -t :.+
bind H resize-pane -L 5
bind J resize-pane -D 5
bind K resize-pane -U 5
bind L resize-pane -R 5
bind-key X set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
setw -g mouse on
setw -g automatic-rename off
set-window-option -g mode-style bg=colour25,fg=colour254
set -g pane-border-style fg=colour28
set -g pane-active-border-style bg=default,fg=colour98
set -g status-justify centre       # center window list for clarity
set-option -g status-position top  # position the status bar at top of screen
setw -g monitor-activity off
set -g visual-activity off
set -g status-style bg=colour28,fg=default
set -g window-status-style fg=colour7
set -g window-status-current-style fg=colour1,bg=colour7
bind m run "tmux new -d -s second; tmux movew -t second;"
bind M run "tmux movew -t base;"
set -g status-interval 300
set -g status-right-length 60
set -g status-right "#[fg=colour73] %d %b %Y %l:%M %p"
set -g @override_copy_command 'clip.exe'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
run '~/.tmux/plugins/tpm/tpm'

Here's terminal's interaction settings
image

Steps to reproduce

This seems to only be an issue in TMUX... however I've tested this in the current stable terminal version of 1.16.10261.0 and it is not a problem

try to copy the text sl iam token refresh. You have to be careful not to get any pre or post characters.

  • as far as I can tell, the terminal colouring has no effect on this

empty clipboard
image

selecting text to copy
image

Japanese text copied to clipboard
image

selecting text to copy - with additional text at beginning
image

proper text copied to clipboard
image

Expected Behavior

copy text sl iam token refresh into clipboard

Actual Behavior

copies out text 汳椠浡琠歯湥爠晥敲桳 which when pasted into google translate, is apparently Japanese for toothpaste

image

Originally created by @dadastoor on GitHub (Feb 22, 2023). Originally assigned to: @DHowett on GitHub. ### Windows Terminal version 1.17.1023 ### Windows build number 10.0.19044.0 ### Other Software tmux 3.0a ``` $ cat ~/.tmux.conf| without_comments set -g default-shell /usr/bin/zsh bind S source-file ~/.tmux/bastion-quad set -g default-terminal "tmux-256color" set -g history-file ~/.tmux_history set -g history-limit 150000 set-environment -g 'IGNOREEOF' 10 set -g prefix ` unbind -n C-l unbind -n C-t unbind -n C-u unbind -n C-y unbind -n C-d unbind -n C-b unbind C-d bind ` send-prefix bind r source-file ~/.tmux.conf \; display "Tmux config reloaded" bind c new-window -c "#{pane_current_path}" bind - split-window -v -c "#{pane_current_path}" bind = split-window -h -c "#{pane_current_path}" bind -n C-S-Left swap-window -t -1\; select-window -t -1 bind -n C-S-Right swap-window -t +1\; select-window -t +1 bind -n C-o select-pane -t :.+ bind H resize-pane -L 5 bind J resize-pane -D 5 bind K resize-pane -U 5 bind L resize-pane -R 5 bind-key X set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}" setw -g mouse on setw -g automatic-rename off set-window-option -g mode-style bg=colour25,fg=colour254 set -g pane-border-style fg=colour28 set -g pane-active-border-style bg=default,fg=colour98 set -g status-justify centre # center window list for clarity set-option -g status-position top # position the status bar at top of screen setw -g monitor-activity off set -g visual-activity off set -g status-style bg=colour28,fg=default set -g window-status-style fg=colour7 set -g window-status-current-style fg=colour1,bg=colour7 bind m run "tmux new -d -s second; tmux movew -t second;" bind M run "tmux movew -t base;" set -g status-interval 300 set -g status-right-length 60 set -g status-right "#[fg=colour73] %d %b %Y %l:%M %p" set -g @override_copy_command 'clip.exe' set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-yank' run '~/.tmux/plugins/tpm/tpm' ``` Here's terminal's interaction settings ![image](https://user-images.githubusercontent.com/72048428/220738245-eaf4eb9b-9ad4-4702-95e3-3abdb2d52155.png) ### Steps to reproduce **This seems to only be an issue in TMUX... however I've tested this in the current stable terminal version of `1.16.10261.0` and it is not a problem** try to copy the text `sl iam token refresh`. You have to be careful not to get any pre or post characters. - as far as I can tell, the terminal colouring has no effect on this empty clipboard ![image](https://user-images.githubusercontent.com/72048428/220736361-76e6c2e7-83cd-4ac4-8966-c9b7d2c6a8e5.png) selecting text to copy ![image](https://user-images.githubusercontent.com/72048428/220736429-1d1c5ee7-38ce-4a42-8e3b-fd1fc5069d2f.png) Japanese text copied to clipboard ![image](https://user-images.githubusercontent.com/72048428/220736490-5c81f5a7-880e-4b8d-bef3-71081dadca20.png) selecting text to copy - with additional text at beginning ![image](https://user-images.githubusercontent.com/72048428/220736583-91ea7734-0d51-460f-9202-7201596b6bb4.png) proper text copied to clipboard ![image](https://user-images.githubusercontent.com/72048428/220736624-3236dae8-40a1-4fb2-917b-5d87d402a083.png) ### Expected Behavior copy text `sl iam token refresh` into clipboard ### Actual Behavior copies out text `汳椠浡琠歯湥爠晥敲桳` which when pasted into google translate, is apparently Japanese for `toothpaste` ![image](https://user-images.githubusercontent.com/72048428/220736882-4befe27a-d69b-4e32-b2cb-f6a8d610dc79.png)
claunia added the Issue-BugNeeds-Tag-Fix labels 2026-01-31 06:43:22 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Feb 22, 2023):

wat

@zadjii-msft commented on GitHub (Feb 22, 2023): _wat_
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

I wish it were closer to April fools so I could pass this off as a prank... 🤯

@dadastoor commented on GitHub (Feb 22, 2023): I wish it were closer to April fools so I could pass this off as a prank... 🤯
Author
Owner

@DHowett commented on GitHub (Feb 22, 2023):

What on earth..! This is amazing!

It looks like you're using tmux' copy mode. Would you be able to grab us a trace of what's coming out of tmux by using the Debug Tap?

@DHowett commented on GitHub (Feb 22, 2023): _What on earth..!_ This is amazing! It looks like you're using tmux' copy mode. Would you be able to grab us a trace of what's coming out of tmux by using the [Debug Tap](https://github.com/microsoft/terminal/wiki/Enabling-the-debug-tap)?
Author
Owner

@DHowett commented on GitHub (Feb 22, 2023):

For what it's worth, when I do that I get this:

image
c2wgaWFtIHRva2VuIHJlZnJlc2g=

base64-decodes to...

00000000: 736c 2069 616d 2074 6f6b 656e 2072 6566  sl iam token ref
00000010: 7265 7368                                resh
@DHowett commented on GitHub (Feb 22, 2023): For what it's worth, when I do that I get this: <img width="482" alt="image" src="https://user-images.githubusercontent.com/189190/220753379-09c8d576-b8aa-46e8-9968-ee8baa4d34fe.png"> ``` c2wgaWFtIHRva2VuIHJlZnJlc2g= ``` base64-decodes to... ``` 00000000: 736c 2069 616d 2074 6f6b 656e 2072 6566 sl iam token ref 00000010: 7265 7368 resh ```
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

What on earth..! This is amazing!

It looks like you're using tmux' copy mode. Would you be able to grab us a trace of what's coming out of tmux by using the Debug Tap?

Oh neat!

That's right yeah, so that I can scroll back within the tmux buffer easily with my mouse

Alrighty, so I'm not getting stuff out in hex, seems ascii...

here's a pic of during the highlight (click-drag mouse, before letting go)
image

here's a pic of after letting go (getting the japanese copied into clip)
image

here's the text from the last screenshot - not sure how to get the text out from during the selection...

[36m␛[49m\␛[35mddastoor␣␛[32m~␛[K␛[m␍␊
$␣␛[32msl␣␛[miam␣token␣refresh␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␛[3;3H␛[?25h␛[O
@dadastoor commented on GitHub (Feb 22, 2023): > _What on earth..!_ This is amazing! > > It looks like you're using tmux' copy mode. Would you be able to grab us a trace of what's coming out of tmux by using the [Debug Tap](https://github.com/microsoft/terminal/wiki/Enabling-the-debug-tap)? Oh neat! That's right yeah, so that I can scroll back within the tmux buffer easily with my mouse Alrighty, so I'm not getting stuff out in hex, seems ascii... here's a pic of during the highlight (click-drag mouse, before letting go) ![image](https://user-images.githubusercontent.com/72048428/220766104-f6d71fd7-63d2-405a-8cd8-8cc9b35e68aa.png) here's a pic of after letting go (getting the japanese copied into clip) ![image](https://user-images.githubusercontent.com/72048428/220766212-0553a1c9-d473-4485-a253-4ce9c3b280e6.png) here's the text from the last screenshot - not sure how to get the text out from during the selection... ``` [36m␛[49m\␛[35mddastoor␣␛[32m~␛[K␛[m␍␊ $␣␛[32msl␣␛[miam␣token␣refresh␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␛[3;3H␛[?25h␛[O ```
Author
Owner

@DHowett commented on GitHub (Feb 22, 2023):

Interesting. I'm missing a bit of the output between the end of the first screenshot and the beginning of the next one. Can you make sure the debug pane is active, then use the command palette (Ctrl+Shift+P) to "Export text" on the entire thing?

Sorry to keep asking you to jump through hoops!

@DHowett commented on GitHub (Feb 22, 2023): _Interesting_. I'm missing a bit of the output between the end of the first screenshot and the beginning of the next one. Can you make sure the debug pane is active, then use the command palette (<kbd>Ctrl+Shift+P</kbd>) to "Export text" on the entire thing? Sorry to keep asking you to jump through hoops!
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

no worries... here's the exported text output
WSL 2.txt

base]␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␛[32X␛[31m␛[47m0:*␛[39m␛[48;5;28m␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␛[K␛[38;5;73m22␣Feb␣2023␣␣2:32␣PM␛[36m␛[49m\␛[35mddastoor␣␛[32m~␛[K␛[m␍␊
$␣␛[32msl␣␛[miam␣token␣refresh␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␍␊
␛[K␛[3;23H␛[?25h␛[O
@dadastoor commented on GitHub (Feb 22, 2023): no worries... here's the exported text output [WSL 2.txt](https://github.com/microsoft/terminal/files/10808846/WSL.2.txt) ``` base]␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␛[32X␛[31m␛[47m0:*␛[39m␛[48;5;28m␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␛[K␛[38;5;73m22␣Feb␣2023␣␣2:32␣PM␛[36m␛[49m\␛[35mddastoor␣␛[32m~␛[K␛[m␍␊ $␣␛[32msl␣␛[miam␣token␣refresh␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␍␊ ␛[K␛[3;23H␛[?25h␛[O ```
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

I'm guessing that tmux does a screen "clear" after you let go of the mouse highlight to copy the text... to get you back to a functioning prompt (and not stuck in the buffer scrollback)

@dadastoor commented on GitHub (Feb 22, 2023): I'm guessing that tmux does a screen "clear" after you let go of the mouse highlight to copy the text... to get you back to a functioning prompt (and not stuck in the buffer scrollback)
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

after further testing, turning of tmux "mouse" via the setw -g mouse off tmux setting seems to "resolve" the issue, but at the cost of losing the "mousey" features of tmux (easy scrollback with mousewheel and moving the scrollback buffer with the mouse during a copy to get >1page of text copied)

@dadastoor commented on GitHub (Feb 22, 2023): after further testing, turning of tmux "mouse" via the `setw -g mouse off` tmux setting seems to "resolve" the issue, but at the cost of losing the "mousey" features of tmux (easy scrollback with mousewheel and moving the scrollback buffer with the mouse during a copy to get >1page of text copied)
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

and after testing this again with the "old" (live 1.16) version of terminal, the japanese toothpaste seems to be reproducible there as well... so this is likely not a new bug and just some weirdness between tmux mouse-mode and windows terminal that has been going on for some time now

@dadastoor commented on GitHub (Feb 22, 2023): and after testing this again with the "old" (live 1.16) version of terminal, the japanese toothpaste seems to be reproducible there as well... so this is likely not a new bug and just some weirdness between tmux mouse-mode and windows terminal that has been going on for some time now
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

and after even further testing... tried just opening a bash (cmd.exe) and the issue is reproducible... so it's not a windows terminal issue at all 😭. Sorry for wasting y'alls time... I guess I'm gonna have to file a tmux bug now.

Really interesting one!

@dadastoor commented on GitHub (Feb 22, 2023): and after even further testing... tried just opening a `bash` (cmd.exe) and the issue is reproducible... so it's not a windows terminal issue at all 😭. Sorry for wasting y'alls time... I guess I'm gonna have to file a tmux bug now. Really interesting one!
Author
Owner

@DHowett commented on GitHub (Feb 22, 2023):

Whoa! Thanks so much for following up. Sorry about that :)

I'm gonna close our copy of the bug out for now -- if it ends up being on our side again, let me know and I'll reopen it!

@DHowett commented on GitHub (Feb 22, 2023): _Whoa_! Thanks so much for following up. Sorry about that :) I'm gonna close our copy of the bug out for now -- if it ends up being on our side again, let me know and I'll reopen it!
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

and after even more digging, it looks like it's actually clip.exe!?!?! 😱 😨

image

image

@dadastoor commented on GitHub (Feb 22, 2023): and after even more digging, it looks like it's actually `clip.exe`!?!?! 😱 😨 ![image](https://user-images.githubusercontent.com/72048428/220787012-5bcb0355-6eb4-4013-8ebb-656762ba8d61.png) ![image](https://user-images.githubusercontent.com/72048428/220787357-df19c8d3-a9dd-4ade-9e98-8ccdd2200d80.png)
Author
Owner

@DHowett commented on GitHub (Feb 22, 2023):

Oh. OH! OKAY.

This is a fascinating interaction between a couple different components. I was expecting that tmux would use the xterm pasteOps OSC to set the clipboard contents (thus the base 64 string!). Using that OSC, tmux tells Terminal to set the clipboard (and it works over SSH). Instead, your config has it shelling out to the Windows application clip.exe through WSL interop. I totally missed that.

Okay.

If you remove @override_paste_... from your config... does it suddenly start working right?

@DHowett commented on GitHub (Feb 22, 2023): Oh. _OH!_ OKAY. This is a fascinating interaction between a couple different components. I was expecting that tmux would use the xterm pasteOps OSC to set the clipboard contents (thus the base 64 string!). Using that OSC, tmux tells _Terminal_ to set the clipboard (and it works over SSH). Instead, your config has it shelling out to the Windows application `clip.exe` through WSL interop. I totally missed that. Okay. If you remove `@override_paste_...` from your config... does it suddenly start working right?
Author
Owner

@dadastoor commented on GitHub (Feb 22, 2023):

nope, it seems to still produce the same output for me (killing tmux and loading a new session, verifying that override is not set).

Furthermore, completely outside of WSL, just doing this inside a cmd prompt reproduces the issue 😂

  • create a file with only the text sl iam token refresh
  • pass it to the clip utility
  • profit

image

@dadastoor commented on GitHub (Feb 22, 2023): nope, it seems to still produce the same output for me (killing tmux and loading a new session, verifying that override is not set). Furthermore, completely outside of WSL, just doing this inside a `cmd` prompt reproduces the issue 😂 - create a file with only the text `sl iam token refresh` - pass it to the `clip` utility - profit ![image](https://user-images.githubusercontent.com/72048428/220790027-21cc904a-423e-42f2-8f6e-fcd1c9b6f087.png)
Author
Owner

@DHowett commented on GitHub (Feb 23, 2023):

Amazing.

You may need to follow one or more of the steps at https://github.com/tmux/tmux/wiki/Clipboard to get switched over to the OSC 52 experience. Ugh, sorry.

@DHowett commented on GitHub (Feb 23, 2023): _Amazing._ You may need to follow one or more of the steps at https://github.com/tmux/tmux/wiki/Clipboard to get switched over to the OSC 52 experience. Ugh, sorry.
Author
Owner

@DHowett commented on GitHub (Feb 23, 2023):

And, hey, if you run chcp in cmd.exe... what codepage are you using?

@DHowett commented on GitHub (Feb 23, 2023): And, hey, if you run `chcp` in cmd.exe... what codepage are you using?
Author
Owner

@DHowett commented on GitHub (Feb 23, 2023):

Nevermind, I can totally repro this. What on earth? Maybe we can fix clip...

@DHowett commented on GitHub (Feb 23, 2023): Nevermind, I can totally repro this. What on _earth_? Maybe we can fix clip...
Author
Owner

@dadastoor commented on GitHub (Feb 23, 2023):

C:\temp>chcp
Active code page: 437
@dadastoor commented on GitHub (Feb 23, 2023): > ``` C:\temp>chcp Active code page: 437 ```
Author
Owner

@dadastoor commented on GitHub (Feb 23, 2023):

hahaha, it's the ghost of clippy 📎 coming back to haunt us!

@dadastoor commented on GitHub (Feb 23, 2023): > hahaha, it's the ghost of clippy 📎 coming back to haunt us!
Author
Owner

@dadastoor commented on GitHub (Feb 23, 2023):

Amazing.

You may need to follow one or more of the steps at https://github.com/tmux/tmux/wiki/Clipboard to get switched over to the OSC 52 experience. Ugh, sorry.

oh neat, tnx for the details, I'll give this a read tonight. @DHowett so I'm guessing windows terminal understands the OSC 52 escape sequences for clipboard setting?

@dadastoor commented on GitHub (Feb 23, 2023): > _Amazing._ > > You may need to follow one or more of the steps at https://github.com/tmux/tmux/wiki/Clipboard to get switched over to the OSC 52 experience. Ugh, sorry. oh neat, tnx for the details, I'll give this a read tonight. @DHowett so I'm guessing windows terminal understands the `OSC 52` escape sequences for clipboard setting?
Author
Owner

@DHowett commented on GitHub (Feb 23, 2023):

so I'm guessing windows terminal understands the OSC 52 escape sequences for clipboard setting?

Absolutely 😄

Okay, so I've got some good news and some bad news.

This is one of the amazing strings that triggers a Windows function called IsTextUnicode to go haywire. Check this out.

is_unicode.cpp

#include <stdio.h>
#include <Windows.h>
int main() {
        const char* foo = "sl iam token refresh";
        BOOL ret = IsTextUnicode(foo, 20, NULL);
        fprintf(stderr, "Ret %d\r\n", ret);
        return 0;
}

output

$ ./is_unicode.exe
Ret 1

So, the thing about IsTextUnicode is that it makes guesses. Literally! The text is otherwise totally unencoded, so it looks like it might actually be Unicode.

clip puts it on the clipboard as a Unicode string...

Now, if we manually convert sl iam token refresh from UTF-16 to UTF-8, we get...

$ iconv -f UTF-16LE -t UTF-8 < /mnt/c/Users/duhowett/foo.txt
汳椠浡琠歯湥爠晥敲桳

toothpaste


This all tickled a memory. If you're interested in following along with me, it looks like Notepad used to have the same problem. Here's why:

@DHowett commented on GitHub (Feb 23, 2023): > so I'm guessing windows terminal understands the `OSC 52` escape sequences for clipboard setting? Absolutely 😄 Okay, so I've got some good news and some bad news. This is one of the amazing strings that triggers a Windows function called `IsTextUnicode` to go haywire. Check this out. ### is_unicode.cpp ```cpp #include <stdio.h> #include <Windows.h> int main() { const char* foo = "sl iam token refresh"; BOOL ret = IsTextUnicode(foo, 20, NULL); fprintf(stderr, "Ret %d\r\n", ret); return 0; } ``` ### output ```sh-session $ ./is_unicode.exe Ret 1 ``` So, the thing about `IsTextUnicode` is that it _makes guesses._ Literally! The text is otherwise totally unencoded, so it looks like it might actually be Unicode. `clip` puts it on the clipboard as a Unicode string... Now, if we manually convert `sl iam token refresh` from UTF-16 to UTF-8, we get... ```sh-session $ iconv -f UTF-16LE -t UTF-8 < /mnt/c/Users/duhowett/foo.txt 汳椠浡琠歯湥爠晥敲桳 ``` toothpaste --- This all tickled a memory. If you're interested in following along with me, it looks like _Notepad_ used to have the same problem. Here's why: - Part 1: [Some files come up strange in notepad](https://devblogs.microsoft.com/oldnewthing/20040324-00/?p=40093) - Part 2: [The Notepad file encoding problem, redux](https://devblogs.microsoft.com/oldnewthing/20070417-00/?p=27223)
Author
Owner

@dadastoor commented on GitHub (Feb 23, 2023):

Wow! Now it all makes sense! 🧠

OMG, your memory has totally thrown me back a few years ago to when I ran into BOM encoding issue at a previous job! It was a nightmare to figure out why a seemingly plaintext config file was not readable by this obscure utility (that required BOM encoding !?), but once we figured it out, we never forgot to ensure the encoding of that file never changed!

@dadastoor commented on GitHub (Feb 23, 2023): Wow! Now it all makes sense! 🧠 OMG, your memory has totally thrown me back a few years ago to when I ran into BOM encoding issue at a previous job! It was a nightmare to figure out why a seemingly `plaintext` config file was not readable by this obscure utility (that required BOM encoding _!?_), but once we figured it out, we never forgot to ensure the encoding of that file never changed!
Author
Owner

@zadjii-msft commented on GitHub (Feb 23, 2023):

this is by far the best issue on our repo

@zadjii-msft commented on GitHub (Feb 23, 2023): this is by far the best issue on our repo
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19440