handleTelnet' :: (String -> IO String) -> SockAddr -> Handle -> IO ()
handleTelnet' runCmd sa h = do
    hPutStrLn h "Ctrl-D to quit"
    hPutStr h "> "
    hFlush h
    c <- hLookAhead h
    unless (c == chr 4) $
        do  
            cmd <- fmap strip $ hGetLine h
            unless (cmd == ":q" || cmd == [chr 4]) $
                do
                    out <- runCmd cmd
                    hPutStrLn h out
                    hPutStrLn h ""
                    handleTelnet' runCmd sa h
handleTelnet' :: (String -> IO String) -> SockAddr -> Handle -> IO ()
handleTelnet' runCmd sa h = do
    hPutStrLn h "Ctrl-D to quit"
    hPutStr h "> "
    hFlush h
    c <- hLookAhead h
    unless (c == chr 4) $
        do  
            cmd <- fmap strip $ hGetLine h
            unless (cmd == ":q" || cmd == [chr 4]) $
                do
                    out <- runCmd cmd
                    hPutStrLn h out
                    hPutStrLn h ""
                    handleTelnet' runCmd sa h
handleTelnet' runCmd sa h = do
    hPutStrLn h "Ctrl-D to quit"
    hPutStr h "> "
    hFlush h
    c <- hLookAhead h
    unless (c == chr 4) $
        do  
            cmd <- fmap strip $ hGetLine h
            unless (cmd == ":q" || cmd == [chr 4]) $
                do
                    out <- runCmd cmd
                    hPutStrLn h out
                    hPutStrLn h ""
                    handleTelnet' runCmd sa h