Closed FichteFoll closed 8 years ago
This semi-works. Well, what I type gets send to the network as intended. Problem with everything that uses both stdout and stdin on the same console: whenever an output comes, the stuff you type gets "interrputed" as in, the stuff you type gets mixed together with the stuff from stdout.
I think it might not be bad to look into some text-ui libraries like urwid. Though since urwid is not asynchronous, it probably has to run in a separate thread.
I also noticed this, but would call a "works for now" on it.
It is mostly intended as an interface for debugging (eventually we should be able to fake server input too, maybe if the text line starts with <
?) and doesn't need to be loaded with features.
As discussed, this might make sense to be implemented as a plugin once a proper system is in place.
A bit research, urwid also takes asyncio event loop (didn't know it takes event loops at all, but then again, I never bothered looking deeper into it).
Here a short sample of how we should use it:
import asyncio
import urwid
txt = urwid.Text("Hello World")
fill = urwid.Filler(txt, 'top')
event_loop = urwid.AsyncioEventLoop(loop=asyncio.get_event_loop())
urwid_main = urwid.MainLoop(fill, event_loop=event_loop)
urwid_main.start()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.sleep(10))
urwid_main.stop()
Usually you would do urwid_main.run()
, but I found in the docs that you can run the event loop yourself, by calling .start()
and .stop()
before and after starting the loop.
If that were to be done using a plugin, we now know, that plugins have to be loaded very early, and there should be ways for the plugin to register to events before and after the asyncio event loop runs.
before and after the asyncio event loop runs.
Plugins must be loaded before connections to networks are opened. Since that happens when the network tasks are started in main.py
's .run_until_complete
, it obviously needs to happen before that, too, so no problem there.
I'm merging this for now since it works. We'll factor it out once plugins are a thing.
Works as you think it would. First word determines the network to send to (a list of available networks is printed at the beginning), any following text is sent to the connection direcly.
This is untested on UNIX!