rabbitgrowth / plover-tapey-tape

Plover paper tape plugin with hesitation bars and stroke suggestions
GNU General Public License v3.0
14 stars 4 forks source link

Dictionary definitions versus their displayed output in the log #4

Closed paulfioravanti closed 1 year ago

paulfioravanti commented 1 year ago

In my steno dictionaries, I use a lot of commands that use the the COMMAND:SHELL: syntax from the Plover Run Shell plugin, wrapped in a bash -ci '...' command (for reasons). Those entries can have quite long values like:

"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/actions/load.scpt'}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/actions/refresh.scpt'}{^^}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/application/activate-application.scpt Firefox'}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/application/activate-application.scpt \"Google Chrome\"'}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/application/use-web-application.scpt \"https://www.youtube.com\"'}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/actions/output-env-var.scpt EMAIL'}"
"{:COMMAND:SHELL:bash -ci 'osascript $STENO_COMMAND/application/focus-application.scpt Plover'}{:COMMAND:LOOKUP}"

$STENO_COMMAND just references the command directory of my steno dictionaries repository.

Tapey Tape outputting these values as-is to the log is absolutely fine from a functionality standpoint. However, when I'm in the situation of having limited horizontal room in the terminal that's showing the tape, I find I'd rather remove some of the cruft and have the above entries outputting like the following so they can fit on a single line:

"{:COMMAND: load.scpt}"
"{:COMMAND: refresh.scpt}{^^}"
"{:COMMAND: activate-application.scpt Firefox}"
"{:COMMAND: activate-application.scpt "Google Chrome"}"
"{:COMMAND: use-web-application.scpt "https://www.youtube.com"}"
"{:COMMAND: output-env-var.scpt EMAIL}"
"{:COMMAND: focus-application.scpt Plover}{:COMMAND:LOOKUP}"

I've been able to do this in a terribly evil way on my Tapey Tape fork to get me over the line (but really, eval just needs to go). My tapey-tape.json contains extra evil config to make those transformations possible:

"transformations": {
  "^{:COMMAND:SHELL:bash -ci 'osascript \$STENO_COMMAND/([a-z/]+)/([a-z-]+\.scpt.*)'}(.*)$": "\"{:COMMAND: \" + match.group(2) + \"}\" + match.group(3)"
}

So yeah...anyway, this brings up the reason for submitting the issue:

Do you have any opinion around the transformation of entry values before they get output to the tape: having a presentation layer, or set of user-specified conditions (like my evil config, but not evil), of some sort? I can see that transformation of entry values already happens to a subtle degree when a * is added to a value when a translation is corrected:

https://github.com/rabbitgrowth/plover-tapey-tape/blob/c31338c35f1e0b8a4c5a9783f684ace0323e1ced/plover_tapey_tape.py#L336

But what about for use cases like above, where having an abbreviated (or some other transformed) version of the value is desired? Is that kind of thing desired within Tapey Tape?

rabbitgrowth commented 1 year ago

Hi Paul, nice to see you here!

Thanks for the suggestion, but to me personally, regex search-and-replace feels too far from the core business of generating a paper tape to be included in the plugin itself.

Maybe it would make more sense to delegate to an external tool that specializes in text transformation, like sed?

$ tail -f tapey_tape.txt | sed -E "s/^{:COMMAND:SHELL:bash -ci 'osascript \\\$STENO_COMMAND\/([a-z\/]+)\/([a-z-]+\.scpt.*)'}(.*)$/{:COMMAND: \2}\3/"
paulfioravanti commented 1 year ago

Thanks for creating a great tool! Totally understand about the boundaries around Tapey Tape's core functionality, and thanks for the idea of delegating to an external filter (definitely better than eval)! I'll give that a try and see how it goes, and hopefully I can get rid of my fork :)

paulfioravanti commented 1 year ago

Just to close the loop on this, I did end up going back to default Tapey Tape, and extracting the code out to a shell file, which I'm calling from a dedicated iTerm2 terminal profile (which is assigned to a hotkey so I can call up a Tapey Tape window whenever I need one):

Cursor_and_Preferences_and_vim
rabbitgrowth commented 1 year ago

Looks great!