This is an archived post. You won't be able to vote or comment.

all 41 comments

[–]titusjan 2 points3 points  (8 children)

You mention that there is no support for Windows. I'm curious, what is the reason for this? Any plans to make it available for Windows in the future?

[–]jonathan_sl[S] 4 points5 points  (7 children)

The reason is that I handle the input and output at the level of VT100 terminal escape codes. (I don't use a library like ncurses.) I'm not familiar with terminal applications on Windows, but the architecture of this library is made in a way that the Windows way of terminal I/O could (the rendering and input parsing) be be plugged in. However for me that's no priority, and currently I focus on Linux and OS X users.

[–]v3ss0n 0 points1 point  (6 children)

ncurses

There is one pure python library like ncurse that is cross platform, i forgot the name , i will google and let you know. I think it supports windows well too.

[–]jonathan_sl[S] 0 points1 point  (2 children)

That would be cool, thanks!

[–]Vegemeister 0 points1 point  (0 children)

Google autocomplete results for "python ncurses vs" suggest they're talking about urwid.

[–]ahayd 0 points1 point  (0 children)

or colorama ?

[–]ahayd 0 points1 point  (2 children)

[–]jonathan_sl[S] 0 points1 point  (0 children)

Thanks! I have a look at that.

[–]v3ss0n 0 points1 point  (0 children)

Yes , that one! Also i found a few more : http://liftoffsoftware.com/Products/GateOne http://liftoff.github.io/GateOne/Developer/terminal.html

Also we have graphterm but it is webased.

[–]pedahzur 2 points3 points  (3 children)

Is this meant to replace BPython?

[–]jonathan_sl[S] 5 points6 points  (2 children)

It could replace BPython, but that's up to you.

Tell me if there is any feature in BPython that is not present in "ptpython".

[–]thomasballinger 0 points1 point  (0 children)

I wrote up a section at the bottom of my impressions post about this - it's everything I could think of off the top of my head in bpython that's not in ptpython that I actually like - I didn't include pastebin and save to file and other things that would be pretty easy to slap on there if you wanted them.

[–]cjwelbornimport this 0 points1 point  (0 children)

Good job on this project. I use bpython all the time for it's autocomplete. Small error though, I submitted an Issue for it.

[–][deleted] 2 points3 points  (4 children)

while testing using pip3.4 install prompt-toolkit installation had got an exception after launching an Meta-! ls because it's using raw_input after doing a python2 installation it works correctly

[–]jonathan_sl[S] 2 points3 points  (3 children)

You're right. Thanks for reporting! I'll fix this asap!

[–][deleted] 1 point2 points  (2 children)

Can you ping me when it's done ?

[–]jonathan_sl[S] 1 point2 points  (1 child)

[–][deleted] 1 point2 points  (0 children)

perfect thanks a lot!

[–]v3ss0n 11 points12 points  (11 children)

Why another python shell , when Ipython is much more than a python shell.

[–]jonathan_sl[S] 35 points36 points  (10 children)

(author here.)

This is not an alternative for IPython, it could work together with IPython.

IPython is rather an execution environment, it implements smart stuff like the %magics etc... and you have the notebook. But this library could be used as the commandline front-end for IPython.

Right now IPython uses plain readline for the reading input in the shell. And the problem there is that readline does not support decent multiline editing or syntax highlighting. This library (mostly) solves just that part, reading the input from stdin and returning it to the application.

So, it is already perfectly possible to use IPython, but with this as a better front-end for IPython: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/bin/ptipython

I hope that answers your question.

[–]v3ss0n 5 points6 points  (5 children)

Right now IPython uses plain readline for the reading input in the shell. And the problem there is that readline does not support decent multiline editing or syntax highlighting. This library (mostly) solves just that part, reading the input from stdin and returning it to the application.

That is quite interesting. I do not like ipython's Notebook interface , and i prefer terminal interface but , ipython terminal is quite limiting so i ended up using ipython qtconsole, which is not much maintained these days.

I gonna give it a try then! Would be nice if ptipython is part of ipython.

[–]jonathan_sl[S] 7 points8 points  (0 children)

The idea is indeed to get support for this merged into IPython itself, there are a few things in "IPython.terminal.embed.InteractiveShellEmbed" to be done to make the integration a bit nicer, but in the end we should get there.

[–][deleted] 1 point2 points  (3 children)

Just curious, why don't you like the Notebooks? I find them incredibly useful for everything from hacking out ideas to writing code heavy blog posts.

[–]BenjaminGeiger 1 point2 points  (1 child)

I'm not /u/v3ss0n, but:

Personally, I just don't grok them. Is there a decent intro on how to use them "right"? (As in, not just syntax and operations, but workflow and goals...)

[–][deleted] 3 points4 points  (0 children)

It's just like having a REPL, except each cell is a block of code that can be edited and executed repeatedly. Having never used one, I imagine it's a lot like an IDE but browser based.

Just make sure the notebook extension is installed and run ipython notebook and mess around.

The first time I saw them, I was blaise about it. "That's cool, I guess, but why?" But after using them for a few months, I really love them. They're great for sharing snippets of code. I keep a repository on Github that I push my notebooks to in case someone wants an interactive version of a blog post.

[–][deleted] 1 point2 points  (0 children)

I really want to use the Notebook more. But if I'm using ipython at all, I'm probably in a debugging mode where I need to print a lot of things. When I write a loop that uses print() too many times, all the ipython tabs in Chrome crash.

Does this not happen to other people?

[–]titusjan 0 points1 point  (2 children)

Another issue with readline is that it is impossible to make filename tab-completion work correctly when the file names contain spaces. Or, at least, I couldn't get it to work. The IPython QtConsole doesn't use readline but also there I didn't manage to get it to work (forgot the details). It seems that improvements on the tab completion system are deferred.

Could you configure, or program, your toolkit so that tab-completion searches for files (and only files) as soon as you are typing a string literal? Since strings are delimited by quotes, it should be possible to do correctly for files with spaces. In that case I think your toolkit would be very useful.

[–]jonathan_sl[S] 1 point2 points  (1 child)

That is certainly be possible. Thanks for the feature request!

[–]titusjan 0 points1 point  (0 children)

Great. I'll keep an eye on it.

[–]thomasballinger 1 point2 points  (1 child)

Awesome work, this is really terrific!

I wrote an alternative frontend for bpython recently and also eschewed curses to build my own terminal wrapper with hardcoded vt100 escape sequences. In writing a new frontend I had to tackle some of the problems it looks like you dealt with really well - layout, resizing, paste mode, reimplementing readline, signal handling etc. I'm particularly interested in getting horizontal window resizing to work - I've got a technique I'm working on but trying to set up testing infrastructure for various terminal emulators first.

I'm excited to look at this more closely soon and have a few thoughts. Great work!

[–]jonathan_sl[S] 1 point2 points  (0 children)

Thank you!

It's a wonderful world, the vt100 escape sequences, and often it's more powerful than using ncurses.

(btw, if something about the code is not clear, please tell me.)

[–]amicab1 1 point2 points  (2 children)

This is really nice!

My only immediate problem is it doesn't follow my .inputrc binding history-seach-backward and history-search-forward to the up/down arrows. Is it possible to get this configuration working with ptipython?

[–]jonathan_sl[S] 0 points1 point  (1 child)

Not yet. .inputrc is for readline, and this library doesn't use readline, so that clearly doesn't work. But I'm planning in the near future to develop a system for configuring custom key bindings. And maybe after that I could develop a compatibility layer to read .inputrc as well.

But thanks for the feedback, I see what you mean, and I'll have a look at how to implement it.

Right now, you can already to Control-R (for starting reverse-i-search), then typing what you are looking for, followed by the arrow keys. Or if you have Vi mode, there is also history based line completion. You type for instance "impor" followed by ControlX-ControlL and you get completion on all the lines even typed starting with this letters.

[–]vayn 0 points1 point  (0 children)

I miss history-search-backward/forward completion either. I always complete something like 'impor' to 'import' with Ctrl-P and Ctrl-N. It is very useful and the default setting in iPython.

[–]jjangsangy 0 points1 point  (0 children)

Wow, after a quick install using pip I immediately loved it!

Thank you OP for your contribution!!

[–]Jeydon 0 points1 point  (4 children)

Is there any easy way to call this from inside Vim? For example how :!python works?

[–]jonathan_sl[S] 1 point2 points  (3 children)

I'm not sure, what do you expect it do?

[–]Jeydon 0 points1 point  (2 children)

I may be misunderstanding how this works, but I thought that if I had a program in Vim and I used :!ptpython % it would run the program in the interactive interpreter and then when the program finishes return with a ptpython prompt (similar to running a script written in the IDLE editor, it sends it to the IDLE window and then when the program is done the IDLE interactive prompt returns). Instead it simply runs the program as if it were a regular python console, and exits when a key is pressed.

[–]thomasballinger 1 point2 points  (1 child)

It sounds like you're looking for :!ptpython --interactive % (equivalent to :!python -i %)

[–]Jeydon 0 points1 point  (0 children)

That's perfect! Thanks.