I would like to suggest to do without xdotool (and xstata entirely), just relying on stata 16.1+.
The way I would see it is that Stata starts a python aiohttp server from within stata (non graphical is okay) and communicate back and forth from sublime to stata using this channel.
The aiohttp wrapper could have a POST http handler that accepts commands to be run (the Stata Python api allows arbitrary commands), prior to running a command it would do a "capture: log using /tmp/statalinuxEPOCHinMilliseconds, replace text", run the command and send the output as an HTTP answer to the POST query aforementioned; then delete ("log close _all" or such) the intermediary log file. Sublime would then display the result.
Edge cases and open questions:
terminal size (pass this in the POST query)
can Sublime display results "inline" in the same document?
would be good to use some sort of auth here; otherwise anyone could execute arbitrary commands on the stata "server".
images could be rendered inline? (a-la Terminus' imgcat?)
should be possible to colorize the output (simply: numbers would be using a color different from text or separation characters, read: ascii horizontal/vertical lines)
Happy to write a stub that starts the aiohttp thread within Stata and expose it via HTTP; let me know; happy to do that. I'd make it synchronous so there wouldn't be "merged commands" or "merged outputs".
I would like to suggest to do without xdotool (and xstata entirely), just relying on stata 16.1+. The way I would see it is that Stata starts a python aiohttp server from within stata (non graphical is okay) and communicate back and forth from sublime to stata using this channel.
The aiohttp wrapper could have a POST http handler that accepts commands to be run (the Stata Python api allows arbitrary commands), prior to running a command it would do a "capture: log using /tmp/statalinuxEPOCHinMilliseconds, replace text", run the command and send the output as an HTTP answer to the POST query aforementioned; then delete ("log close _all" or such) the intermediary log file. Sublime would then display the result.
Edge cases and open questions:
Happy to write a stub that starts the aiohttp thread within Stata and expose it via HTTP; let me know; happy to do that. I'd make it synchronous so there wouldn't be "merged commands" or "merged outputs".
Let me know if it's something you'd like to work together on. Note: it's not very different from what the jupyter stata kernel does, see https://github.com/TiesdeKok/ipystata/blob/master/ipystata/ipystata_magic.py#L326 at the difference that it can pretty print a few different objects.