Write out pretty JSON.
Move shell handling functions into separate module.
Sensible shutdown behaviour.

Finally got to grips with the shutdown behaviour. We now have a
separate shutdown channel which we may signal from the main thread
to shut down the whole conduit. This results in flushing (and closing)
the file handle and socket. The main thread then waits for the conduit
to close down competely before doing final cleanup and exiting.