getContents, getLine, etc.

Bernd Holzmüller <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.user
Organization ICS AG
Message-ID <[email protected]>
I recently wrote a getLine version that treats backspace correctly (you 
might wish to choose a better name, though :-):

-- getLine' correctly treats backspaces (erasing the deleted characters 
in output)
getLine' = liftM reverse $ getLine'' ""
 where getLine'' read = do
       c <- getChar
       if c=='\n' then return read else do
       if c=='\b'
          then do putStr " \b"
                  if null read then getLine'' "" else getLine'' (tail read)
          else getLine'' (c:read)

Regards,

-- 
Bernd Holzmüller
______________________________________________________
INFORMATIK CONSULTING SYSTEMS AG
Sonnenbergstraße 13               70184 Stuttgart
Telefon: +49 (0711) 21037-37      Fax: -75
mailto:[email protected]      http://www.ics-ag.de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.