Telne impl has to buffer the entire output of a command before sending via. TCP. This needs about 1kb of RAM for a minimal shell, and even then it's easy to truncate the tail of long command output.
The telnet server is well written - keep this base. Introduce a new psock/pthread for the "shell" interpreter layer so that shell commands can produce incremental output, one buffer at a time. This is the same mechanism used by the "cgi includes" part of the webserver.