openstenoproject / plover

Open source stenotype engine
http://opensteno.org/plover
GNU General Public License v2.0
2.36k stars 277 forks source link

Remotely enable/disable Plover #1439

Closed runxiyu closed 2 years ago

runxiyu commented 2 years ago

I use Vim in order to edit text. When I am in Normal Mode (where each key on the keyboard is a command), I want Plover to be automatically disabled. When I am in Insert Mode (where I enter, well, text), I want Plover to be enabled.

I've done this with the Fcitx input methods (Chinese Shuangpin, to be exact, which is basically the stenotype in Chinese) by adding these hooks to vim:

autocmd! InsertLeave * call system('fcitx-remote -c')
autocmd! InsertEnter *.cn.tex call system('fcitx-remote -o')

This causes fcitcx-remote -c to be executed every time I leave Insert Mode, which disables the input method, so Vim doesn't get messed up. Similarly, it does fcitx-remote -o to enable the input method when I enter Insert Mode, so that I could type Chinese.

Thus, I basically require Plover to have a command-line remote control interface (or maybe a FIFO-based remote control interface). I found plover_send_command which sounds like it's going to do the work. It isn't documented, so I went through my Python libs to find plover's send_command thing, which seems to send commands to a connection. The code is too hard to follow.

I would hope that someone knows how to remotely enable/disable Plover with a shell command or such. There are other purposes I need for this, for example, I actually want Plover toggle to be bound to a keybinding set by sxhkd, the Simple X Hotkey Daemon, and to automatically enable when I write a *.en file (that's how I do English files). Thanks!

A clear and concise description of what you're trying to do. E.g. "I'm trying to connect my Stentura 400SRT to Plover over USB but there's no output."

Uname: Linux prtlp 5.10.78-1-lts #1 SMP Thu, 11 Nov 2021 21:24:30 +0000 x86_64 GNU/Linux Distribution: Artix Linux, basically arch but no systemd Plover version: Plover 4.0.0.dev10 Hardware: Random laptop keyboard, switching to an Ergodox soon

P.S.: Any support for OpenBSD?

runxiyu commented 2 years ago

Fixed! After going through more source code and reading another issue, I found that lines after 343 in engine.py is what I need to read. In short:

plover_send_command toggle # toggles
plover_send_command suspend # disables
plover_send_command resume # enables
plover_send_command quit # exits
plover_send_command lookup # lookup a word

This is a feature that many people would want. I strongly recommend putting this into the official documentation; since I solved this, I'll close this issue.

benoit-pierre commented 2 years ago

The output related commands are: resume, suspend, and toggle. E.g.: plover -s send_command toggle to toggle output.

P.S.: Any support for OpenBSD?

This should work since #1306.

runxiyu commented 2 years ago

lol, commented within 30 seconds of each other thanks :D