When the dockerpty is started, control is yielded to the container's PTY untilthe container exits, or the container's PTY is closed.

This is a safe operation and all resources are restored back to their originalstates.

## How it works

In a terminal, the three file descriptors stdin, stdout and stderr are allconnected to the controlling terminal (TTY). When you pass the `tty=True` flagto docker's `create_container()`, docker allocates a fake TTY inside thecontainer (a PTY) to which the container's stdin, stdout and stderr are allconnected.

The docker API provides a way to access the three sockets connected to the PTY.If with access to the host system's TTY file descriptors and the container'sPTY file descriptors, it is trivial to simply 'pipe' data written to these filedescriptors between the host and the container. Doing this makes the user'sterminal effectively become the pseudo-terminal from inside the container.

In reality it's a bit more complicated than this, since care must be taken toput the host terminal into raw mode (where keys such as enter are notinterpreted with any special meaning) and restore it on exit. Additionally, thecontainer's stdout and stderr streams along with `sys.stdin` must be madenon-blocking so that they can be used with `select()` without blocking the mainprocess. These attributes are restored on exit.

The size of a terminal cannot be controlled by sending data to stdin and canonly be controlled by the terminal program itself. Since the pseudo-terminal isrunning inside a real terminal, it is import that the size of the PTY be keptthe same as that of the presenting TTY. For this reason, docker provides an APIcall to resize the allocated PTY. A SIGWINCH handler is used to detect windowsize changes and resize the pseudo-terminal as needed.

## Planned

* Implement the "detach" functionality provided by the official docker client - Pressing <kbd>C-p</kbd><kbd>C-q</kbd> detaches from the PTY in docker * Any other keyboard shortcuts that users may think useful