asweigart / asweigart/pyperclip

Workaround for powershell raster font problem

Open
#175 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.8k
Forks
221
PR merge metrics
No merged PRs in 30d

Description

paste_wsl() uses powershell.exe, which triggers the powershell raster font problem.

See https://patrickwu.space/2019/08/03/wsl-powershell-raster-font-problem/

I verified that his technique works at least for me, and I implemented an alternative paste_wsl() based on it:

def paste_wsl():
cmd = ("oemcp=$(reg.exe query 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage'"
" /v OEMCP 2>&1 | sed -n 3p | sed -e 's|\\r||g' | grep -o '[[:digit:]]*')"
"\nchcp.com $oemcp >/dev/null 2>/dev/null"
"\npowershell.exe Get-Clipboard"
"\nchcp.com 65001 >/dev/null 2>/dev/null")
stdout = os.popen(cmd).read()
return stdout[:-1]

It's super-ugly though, so in my case I put this in the client code, and I haven't issued a pull request. It seems like there ought to be a cleaner way. I tried shelling out the commands separately, but for some reason that didn't work. I'm also not sure how universal this solution is.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting paste_wsl() and the linked PowerShell raster-font workaround. Reproduce the clipboard behavior under WSL, compare the proposed approach with separate shell commands, and determine a cleaner, broadly applicable fix; done means WSL pasting avoids the raster-font problem without requiring client-side workaround code.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, python
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.