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

idea: restore command history #1

Open
jsbain opened this issue Apr 28, 2016 · 3 comments
Open

idea: restore command history #1

jsbain opened this issue Apr 28, 2016 · 3 comments

Comments

@jsbain
Copy link

jsbain commented Apr 28, 2016

[str(h) for h in UIApplication.sharedApplication().keyWindow().rootViewController().accessoryViewController().consoleViewController().history()]

exposes the current console command history as a list of strings. This can also be set via

UIApplication.sharedApplication().keyWindow().rootViewController().accessoryViewController().consoleViewController().history=['test','ing']

is it possible to enable a stdin hook which stores history to a file, which is then restored on reload? or perhaps an atexit which reads and stores current history.

@dgelessus
Copy link
Owner

dgelessus commented Apr 28, 2016

  1. I don't know anything about Objective-C, Swift or iOS app development, if this involves more than getting/setting the history property (?) then I may be the wrong person for the job :)
  2. I'm quite certain that interactive Python input does not go through normal stdin in any way, so I'm not sure what a stdin hook would be. (And would it be necessary if the history list is accessible via objc_util?) Of course "commands" can be implemented by saying builtins.save_history = object() and making the displayhook react specially to that, but then you might as well make it a normal function.
  3. Last I checked Pythonista wouldn't run atexits, I'll need to check that though. (Edit: still doesn't, tested with atexit.register(lambda: open(os.path.expanduser("~/Documents/atexit_test.txt"), "wb").close()).)

@jsbain
Copy link
Author

jsbain commented Apr 28, 2016

I thought in a recent beta that atexit was supported, though I don't think it runs when killed by the os for memory reasons, or when crashing, so maybe has little value.

I thought you had done some work monkey patching the _stdoutcatcher, but maybe my memory is fuzzy. My thinking would be to log to a file each console command as it is run, then restore in startup. I am not sure if there is another "standard" method to hook into console commands? I guess, for example, whenever you append to Out, we could store the new history commands....
Okay, I guess I know where to look now.

@dgelessus
Copy link
Owner

Ah, atexit hooks run when you do sys.exit(), not when the app exits.

What I did "back then" was related to the autocompletion in the interactive console. Before Pythonista 2 the completion list was built by injecting a bit of Python code that printed the completions to stdout, which was then captured by Pythonista and shown in the completion list. I managed to patch that so it would show a custom suggestion at the top of the list every time, but there was no way to get the full text of the partial line typed at that point (and no way to tell whether stdout was currently in "normal" or "autocomplete list" mode, so any patching may also have affected normal output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants