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

Espanso does not support UTF-8 return values from PowerShell #1736

Closed
phorcys420 opened this issue Oct 30, 2023 · 8 comments
Closed

Espanso does not support UTF-8 return values from PowerShell #1736

phorcys420 opened this issue Oct 30, 2023 · 8 comments
Labels
documentation Documentation related to this repo (for devs) windows Related to the Windows operating system

Comments

@phorcys420
Copy link
Contributor

phorcys420 commented Oct 30, 2023

Describe the bug
Espanso does not accept return values from PowerShell (I have not tested with other shells).
Using the config below, the :ps_é trigger returns an unknown character (�)

To Reproduce

  1. Use the matches from the next paragraph
  2. Type :ps_é

Config

  - trigger: ":é"
    replace: "é"

  - trigger: ":ps_é"
    replace: "{{text}}"
    vars:
      - name: text
        type: shell
        params:
          cmd: |
            return "é"

I have also tried using return $([char]0x00E9) to no avail.

Expected behavior
Both and :ps_é return "é"

Screenshots
N/A

Logs

15:47:20 [daemon(10244)] [INFO] reading configs from: "C:\\Users\\[...]\\AppData\\Roaming\\espanso"
15:47:20 [daemon(10244)] [INFO] reading packages from: "C:\\Users\\[...]\\AppData\\Roaming\\espanso\\match\\packages"
15:47:20 [daemon(10244)] [INFO] using runtime dir: "C:\\Users\\[...]\\AppData\\Local\\espanso"
15:47:20 [daemon(10244)] [INFO] system info: Windows v10 (19045) - kernel: 19045
15:47:20 [daemon(10244)] [INFO] watching for changes in path: "C:\\Users\\[...]\\AppData\\Roaming\\espanso"
15:47:20 [daemon(10244)] [INFO] espanso version: 2.1.8
15:47:20 [daemon(10244)] [INFO] spawning the worker process...
15:47:20 [daemon(10244)] [INFO] binded to named pipe: \\.\pipe\espansodaemonv2
15:47:20 [worker(17852)] [INFO] reading configs from: "C:\\Users\\[...]\\AppData\\Roaming\\espanso"
15:47:20 [worker(17852)] [INFO] reading packages from: "C:\\Users\\[...]\\AppData\\Roaming\\espanso\\match\\packages"
15:47:20 [worker(17852)] [INFO] using runtime dir: "C:\\Users\\[...]\\AppData\\Local\\espanso"
15:47:20 [worker(17852)] [INFO] system info: Windows v10 (19045) - kernel: 19045
15:47:20 [worker(17852)] [INFO] binded to named pipe: \\.\pipe\espansoworkerv2
15:47:20 [worker(17852)] [INFO] using Win32AppInfoProvider
15:47:20 [worker(17852)] [INFO] monitoring the status of the daemon process
15:47:20 [worker(17852)] [INFO] using Win32Source
15:47:20 [worker(17852)] [INFO] using Win32Injector
15:47:20 [worker(17852)] [INFO] using Win32Clipboard

Setup information

  • OS: Windows 10 22H2 (19045.3570)
  • Version: 2.1.8
@phorcys420 phorcys420 added the bug Something isn't working label Oct 30, 2023
@phorcys420 phorcys420 changed the title Espanso does not support UTF-8 return from PowerShell Espanso does not support UTF-8 return values from PowerShell Oct 30, 2023
@smeech
Copy link
Collaborator

smeech commented Nov 21, 2023

Apart from the fact that the recommended way of using nested matches is as documented in https://espanso.org/docs/matches/basics/#nested-matches, your problem may relate to the return of non-English characters from Windows shells and Python, as also noted in Issue #1749.

@phorcys420
Copy link
Contributor Author

phorcys420 commented Nov 25, 2023

Apart from the fact that the recommended way of using nested matches is as documented in https://espanso.org/docs/matches/basics/#nested-matches

I don't use this as a way of using nested matches, this was only a quick proof of concept to show that regular triggers are able to return "é" but not from a powershell return.

your problem may relate to the return of non-English characters from Windows shells and Python, as also noted in Issue #1749.

Yes, that is what I implied in the title, sorry if that wasn't clear.

@AucaCoyan AucaCoyan added the windows Related to the Windows operating system label Nov 25, 2023
@smeech
Copy link
Collaborator

smeech commented Nov 25, 2023

Fair enough - thank you. I primarily wanted to link your Issue with the later one.

@kpym
Copy link

kpym commented Dec 16, 2023

This is the same issue as #1749. You need to tell PowerShell to operate in UTF8. You can do this permanently (in your config) or you can change the encoding just for your command, like this :

  - trigger: ":ps"
    replace: "{{text}}"
    vars:
      - name: text
        type: shell
        params:
          cmd: |
            [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
            return "é"

or you can use wsl instead of powershell (the default on Windows) as I pointed out in #1749.

@smeech smeech mentioned this issue Dec 16, 2023
21 tasks
@phorcys420
Copy link
Contributor Author

phorcys420 commented Dec 23, 2023

This is the same issue as #1749. You need to tell PowerShell to operate in UTF8.

Hey, thanks a lot for the workaround !
I'll try it as soon as I can ! This will help me a lot as this was my only problem with espanso so far :-)

You can do this permanently (in your config)

When you're saying this, do you mean by adding [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; to my $PROFILE ?

or you can use wsl instead of powershell (the default on Windows) as I pointed out in #1749.

I can't because everything I'm running was written in powershell so I might aswell run it directly in powershell, but thanks for the suggestion :-)

@kpym
Copy link

kpym commented Dec 23, 2023

When you're saying this, do you mean by adding [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; to my $PROFILE ?

This is one possibility, but it's not without its drawbacks : check this discussion.

@phorcys420
Copy link
Contributor Author

phorcys420 commented Dec 28, 2023

I can confirm this does work !

I don't know if I should close this issue though as I think it should be mentioned in the docs.

@kpym
Copy link

kpym commented Dec 28, 2023

I don't know if I should close this issue though as I think it should be mentioned in the docs.

If this is your request now, and you decide to keep it open, you should probably change the title to something like "Missing documentation about UTF-8 support in PowerShell" and change the label from bug to documentation.

There is already an open issue #1788 that mention the UTF-8 documention problem.

@smeech smeech added documentation Documentation related to this repo (for devs) and removed bug Something isn't working labels Dec 28, 2023
@smeech smeech closed this as completed Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation related to this repo (for devs) windows Related to the Windows operating system
Projects
None yet
Development

No branches or pull requests

4 participants