transistor1 / shellista

shellista - iOS shell written for Pythonista
https://omz-forums.appspot.com/pythonista/post/5302343285342208
78 stars 18 forks source link

Make a PyUI user interface for Shellista #10

Open transistor1 opened 10 years ago

transistor1 commented 10 years ago

It would be great if we could have a user interface that pops up for Shellista on top of your code the same way that the Pythonista Calculator example does as of v1.5.

Shellista should be able to run from the standard, command-line method, or from the popup window (might this also be an opportunity to provide other functionality, like tab completion?).

jsbain commented 10 years ago

I created a tab completion in my branch, which uses ui for the selection, but still uses console for input. Basically, you hit tab then enter, and it pops up autocomplete box. Then, you can continue typing, or press enter to submit. Klunky, since we can't update the console input, but seems to work.

I apologize, I forked latest branch ... But used an old version as the base. So diff is all f@@@d up. Basically, added ui to imports, and 3 functions, Script.precmd, tabcompl, and tapaction ... You should be able to pull just those bits to try.

dgelessus commented 10 years ago

(two months late reply) I actually just finished working on a UI wrapper for Shellista which is presented as a panel view in the console/docs window. It has separated input and output text areas - the output is non-editable, but selectable and scrollable; the input is one editable line that is always visible, and features a command history. In addition the last output line is shown in the input field, like you'd expect on a real terminal.

Unfortunately I can't post any (useful) code yet, I had to make a few changes to Shellista to allow custom input and output streams. I'll make a pull request if possible (my base copy is somewhat old) but for now here's a screenshot of how it looks like: image (the bottom line is the input text field, the cursor wasn't visible when I made the screenshot)

PS: Pull requested at #33

transistor1 commented 10 years ago

Nice! I played around with shellista running in a popup window several months ago - same thing; had tried to redirect stdin/stdout by using a file like object to replace the stdin/out streams. I found it tricky and it caused a lot of funky behavior. I recall having problems trying to implement readline as well because I couldnt get it to block while waiting for input. I had gotten it working but it was hackish. Unfortunately I wiped it out accidentally.

Sent from my phone On Sep 3, 2014 12:45 PM, "dgelessus" notifications@github.com wrote:

(two months late reply) I actually just finished working on a UI wrapper for Shellista which is presented as a panel view in the console/docs window. It has separated input and output text areas - the output is non-editable, but selectable and scrollable; the input is one editable line that is always visible, and features a command history. In addition the last output line is shown in the input field, like you'd expect on a real terminal.

Unfortunately I can't post any (useful) code yet, I had to make a few changes to Shellista to allow custom input and output streams. I'll make a pull request if possible (my base copy is somewhat old) but for now here's a screenshot of how it looks like: [image: image] https://cloud.githubusercontent.com/assets/6641959/4137701/be2ac7ac-3389-11e4-86c4-a95625b0a91d.jpg

— Reply to this email directly or view it on GitHub https://github.com/transistor1/shellista/issues/10#issuecomment-54327017 .

transistor1 commented 10 years ago

What did you do to redirect the output?

Sent from my phone On Sep 3, 2014 12:45 PM, "dgelessus" notifications@github.com wrote:

(two months late reply) I actually just finished working on a UI wrapper for Shellista which is presented as a panel view in the console/docs window. It has separated input and output text areas - the output is non-editable, but selectable and scrollable; the input is one editable line that is always visible, and features a command history. In addition the last output line is shown in the input field, like you'd expect on a real terminal.

Unfortunately I can't post any (useful) code yet, I had to make a few changes to Shellista to allow custom input and output streams. I'll make a pull request if possible (my base copy is somewhat old) but for now here's a screenshot of how it looks like: [image: image] https://cloud.githubusercontent.com/assets/6641959/4137701/be2ac7ac-3389-11e4-86c4-a95625b0a91d.jpg

— Reply to this email directly or view it on GitHub https://github.com/transistor1/shellista/issues/10#issuecomment-54327017 .

dgelessus commented 10 years ago

<walloftext> Coming to think of it, the UI script should work just as well as a popup window; I positioned all components in a dynamically resizing subview of the root view, in order to move the input line when the onscreen keyboard pops up. This layout should in fact work well with any view type, though I don't see the advantage of having a popup window. Once you tap outside the window it closes immediately, which doesn't allow for switching back and forth like with a panel. It is also very easy to accidentally tap away a popup.

As for I/O redirection, see #33 - I extended the Shellista() constructor to allow manual stdin/stdout overwrites like cmd.Cmd() does. In the ShellistaUI script I created a Shellista instance and modified it, turned off raw_input() usage so it would use read() instead - also a feature of cmd.Cmd(). This did the trick for the base Shellista.

Plugins however would still use the default stdin and stdout, as they are individual modules and have no reference to the currently running Shellista instance. I first tried a "safe" way of changing their stdin/stdout by iterating through all loaded plugins and replacing sys with a modified version that had stdin and stdout changed. I hoped that would change the streams for just the plugins and nothing else, but in fact it did nothing at all. So in the end I had to resort to changing stdin and stdout while a command is being executed, which I don't particularly like, as that can accidentally capture in/output from parallel tasks.

Now you might think that because I'm overwriting sys.stdin and sys.stdout anyway I could leave out the addition to the Shellista() constructor. That doesn't actually work though, whenever I overwrite stdin and stdout only via sys and not via the constructor, Pythonista inexplicably hangs when I launch the script. It looks like a UI threading issue to me, though I don't have any blocking pieces of code in my script. It doesn't matter though, the way I did it seems to work fine. </walloftext>