command retrieval in Python shell
John Rickman (71) 646 posts |
Can anyone tell me if it is possible to retrieve the last command using a Google has lots on command retrieval but it is mostly about Linux. JR PS |
Martin Avison (27) 1494 posts |
Downloaded here at 12:07 yesterday. |
Timo Hartong (2813) 204 posts |
I don’t think RISCOS holds an archive of the commands as linux and windows do. But I’m not sure. Is there an updated version for python for RISCOS ? |
Steve Pampling (1551) 8170 posts |
Not by default, but there’s a module for that©1 you just have to load the right module. For this you will want LineEditor which some people think of as part of Zap, but it actually does the job for anything that accesses that aspect of the OS. 1 See what I did there? |
David Pitt (3386) 1248 posts |
Elsewhere CTRL-P and CTRL-N retrieve previous and next commands but on RISC OS Python 2.7.2 the result can be garbaged with control codes. |
Rick Murray (539) 13840 posts |
Oh… I didn’t even know they existed. I just use cursor up and down with LineEditor in the TaskWindow. |
David Pitt (3386) 1248 posts |
I can’t get that to work within Python at the |
Rick Murray (539) 13840 posts |
Ah… Well, it sounds like the Python prompt is dealing with stuff by itself, instead of calling OS_ReadLine to get input. That’s not unexpected – a program written in C (assuming it’s C) for another platform will likely use generic calls to get input instead of a RISC OS specific call; and because C treats I/O as files, it’s probably doing something like calling fgets() on the stdin stream. In other words, Python will need to implement its own command history. The LineEditor one won’t work as it has no way to know that you’re actually reading a line of input (as opposed to doing an INKEY). |
nemo (145) 2546 posts |
Uggh. No doubt absolutely true… and rather a downer considering the effort I put into my 100% Unicode version of ReadLine. Darn. |
John Rickman (71) 646 posts |
Uggh. No doubt absolutely true… I can confirm that. Ie retrieve works in a TaskWindow but not within the Python shell running in the TaskWindow. |
David Boddie (1934) 222 posts |
Is there a version of the readline module for RISC OS Python? |
nemo (145) 2546 posts |
I assume you mean readline.c which is the low-level implementation of readline in Python. It implements everything, including history and auto-completion. The readline API is pretty big. It would be interesting doing a RISC OS port that tried to defer all of that to Olly Betts’ Readline module for example. Obviously the OS version of Readline doesn’t do history or completion, so that part of the API would have to degrade in that case. I can see why it doesn’t. |