Skip to content
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

fix using wrong encoding on Windows #128

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

na-trium-144
Copy link
Contributor

@na-trium-144 na-trium-144 commented Oct 29, 2024

Hello, I'm using tmux installed with MSYS2 and Python installed with pyenv-win on Windows 11.
In this environment, extracto fails with the following error:

['fzf', '--multi', '--print-query', '--query=', '--header=\x1b[1menter\x1b[0m=insert, \x1b[1mtab\x1b[0m=copy, \x1b[1m^o\x1b[0m=open, \x1b[1m^e\x1b[0m=edit, \x1b[1m^f\x1b[0m=filter [\x1b[0;33m\x1b[1mword\x1b[0m], \x1b[1m^g\x1b[0m=grab [\x1b[0;33m\x1b[1mwindow full\x1b[0m], \x1b[1m^h\x1b[0m=help', '--expect=ctrl-c,ctrl-g,esc', '--expect=enter,tab,ctrl-f,ctrl-e,ctrl-o,ctrl-g,ctrl-h', '--tiebreak=index', '--layout=default', '--no-info']
Traceback (most recent call last):
  File "C:\msys64\home\shach\.tmux\plugins\extrakto\extrakto_plugin.py", line 315, in capture
    get_cap(mode, self.capture_panes()),
                  ^^^^^^^^^^^^^^^^^^^^
  File "C:\msys64\home\shach\.tmux\plugins\extrakto\extrakto_plugin.py", line 231, in capture_panes
    captured += subprocess.check_output(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\shach\.pyenv\pyenv-win\versions\3.12.6\Lib\subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\shach\.pyenv\pyenv-win\versions\3.12.6\Lib\subprocess.py", line 550, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\shach\.pyenv\pyenv-win\versions\3.12.6\Lib\subprocess.py", line 1196, in communicate
    stdout = self.stdout.read()
             ^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 45: illegal multibyte sequence

error: unable to extract - check/report errors above
If fzf is not found you need to set the fzf path in options (see readme).

Note that cp932 is ANSI encoding on Japanese Windows, which is used in Python by default, while MSYS2 tmux uses utf-8.
So explicitly specifying encoding as utf-8 fixed this error and I could use extracto on Windows.

This doesn't affect Linux or MacOS because utf-8 should be default there.
Since tmux does not support other locale than utf-8 (said in tmux Wiki), I think it's ok not to assume non-utf-8 environment.

@laktak
Copy link
Owner

laktak commented Nov 5, 2024

Thanks for you PR!

While I can't test this, I think it's a harmless change that should not break anything (famous last words) ;)

@laktak laktak merged commit d86e24b into laktak:master Nov 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants