UltrosBot / Ultros

Connecting communities, one squid at a time! Ultros is a multi-protocol chat bot written in Python, designed with both the user and developer in mind
http://ultros.io
Artistic License 2.0
23 stars 7 forks source link

Console #66

Closed gdude2002 closed 9 years ago

gdude2002 commented 9 years ago

It's about time we looked at this. A working console with input is always a very useful thing to have - so, how should we implement one? A couple ideas I've had..

Any ideas, thoughts, etc would be appreciated, especially relating to implementation detail.

gdude2002 commented 9 years ago

Looking for input from @Adam01, @rakiru if possible

rakiru commented 9 years ago

This is Python - surely someone's already done this for us?

gdude2002 commented 9 years ago

I've been looking, trust me. The only viable thing is curses and that's not even available on windows.

rakiru commented 9 years ago

I've used curses of some sort on windows in python. It might've been in cygwin or something though, I guess.

Edit: Ok, there are python curses builds for windows, but they don't support unicode characters, so that's a dead-end (although does cmd even support unicode characters?).

Edit 2: Powershell probably does though I think, so yeah, that's not an option.

gdude2002 commented 9 years ago

@rakiru Just C libraries in general would be nice to avoid anyway since almost everything we do related to logging is pure-python.

So let's assume pure-python. Where do we go from there?

rakiru commented 9 years ago

Well, both IRC and Mumble partially rely on C libraries already, but I do agree that we should go with pure Python if possible. I'd say have a go writing a PoC of your first suggestion. The main problem I see is handling backspace etc., if you're having to print the input after any other output.

I'd also probably suggest that we make sure that anything someone might want to use sys.stdout for is possible to do from our stuff, and simply don't support directly using it. That may be easier said than done though, since it may be a library that tries to do that, rather than a plugin.

/randommumblings

gdude2002 commented 9 years ago

I don't think backspace would be a problem, but I'm wondering how exactly to get it. I think that readline might be a good library to work with, though.

gdude2002 commented 9 years ago

Actually, never mind, that isn't even close to the readline I was expecting. Hmm..

dequis commented 9 years ago

that isn't even close to the readline I was expecting

What were you expecting, then? Because this seems to be the standard solution for what it seems you're trying to do.

gdude2002 commented 9 years ago

@dequis something like https://github.com/qmx/jreadline

dequis commented 9 years ago

It's got all those features, it just happens to have an obtuse api designed in 1970.

gdude2002 commented 9 years ago

@dequis mind sharing a few pointers, then?

dequis commented 9 years ago

http://pymotw.com/2/readline/

You probably want to use emacs editing mode (the default, so skip the suggestion about set editing-mode vi), and if tab completion isn't needed, readline.parse_and_bind('') (empty config) + raw_input() is enough. Yep

Other config entries here: http://tiswww.case.edu/php/chet/readline/readline.html#SEC10

dequis commented 9 years ago

Logging and taking input simultaneously might be an issue:

http://stackoverflow.com/questions/5068846/how-to-output-messages-to-stdout-on-another-thread-while-reading-from-stdin-with

Otherwise: http://urwid.org/ - decent pythonic wrapper over curses.

gdude2002 commented 9 years ago

I'm going to drop this one and remove the console for now as it causes too many problems in a lot of edge cases.

I may revisit this in the future, though.