You are not logged in.

#1 2015-01-30 13:32:40

nbd
Member
Registered: 2014-08-04
Posts: 389

[SOLVED] Python curses-based shell with line editing?

I'd like to write a basic shell in Python, with primitive line editing capabilities. I know about cmd module, but I need multi-window capabilities within a terminal which I'd like to implement with curses module. However, curses works at low level and for implementing even rudimentary line editing functionality, one needs to do a lot of coding for primitive tasks such as characters inserting, deleting, moving the cursor and the like. I wonder, does there exists some "framework" or sample application  for creating shell-like application with Python-curses, which provides basic line-editing functionality?

I came across this example of an interactive curses-shell, but it lacks almost any editing functionality.

EDIT: After some research on the topic it seems that the required functionality can be implemented without reinventing the wheel via interaction of three modules: curses, curses.textbox and cmd.

EDIT2: Also bpython, proposed in the thread, seems like a good example.

Last edited by nbd (2015-01-31 09:58:23)


bing different

Offline

#2 2015-01-30 23:05:03

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 681

Re: [SOLVED] Python curses-based shell with line editing?

I guess you know about the venerable GNU readline which gives you command line editing, e.g. as used by bash. Has emacs and vi modes. Python has a standard module to interface to that. Also have a look at cmd2.

Last edited by bulletmark (2015-01-30 23:07:37)

Offline

#3 2015-01-30 23:30:58

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Python curses-based shell with line editing?

I would investigate how bpython works. It's a curses-based python alternative shell.

Scott

Offline

#4 2015-01-31 09:56:28

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [SOLVED] Python curses-based shell with line editing?

firecat53

Thanks! Seems like a good example!

bulltmark

Yes, I currently use 'readline' with 'cmd' and it has excellent functionality, but I couldn't figure out how to use it with 'curses'.


bing different

Offline

#5 2015-02-01 20:08:15

whitie
Member
Registered: 2011-03-13
Posts: 23

Re: [SOLVED] Python curses-based shell with line editing?

For curses based applications look at the urwid package.

Whitie

Offline

#6 2015-02-02 07:50:52

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [SOLVED] Python curses-based shell with line editing?

whitie wrote:

For curses based applications look at the urwid package.

Whitie

Yep, I saw it, but for my needs it's a bit over the top.


bing different

Offline

Board footer

Powered by FluxBB