[GHC] #3062: Adding a ":clear" clear-screen command to GHCi

GHC trac at galois.com
Mon Mar 2 21:57:59 EST 2009


#3062: Adding a ":clear" clear-screen command to GHCi
-----------------------------+----------------------------------------------
Reporter:  porges            |          Owner:                  
    Type:  feature request   |         Status:  new             
Priority:  normal            |      Component:  GHCi            
 Version:  6.11              |       Severity:  normal          
Keywords:                    |       Testcase:                  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
-----------------------------+----------------------------------------------
 I have written a (hopeful) patch for this. I say hopeful because I'm not
 sure if it even compiles (I don't have the space to compile GHC at the
 moment...).

 Anyway if this could be confirmed to work and then incorporated that would
 be nice :)

 {{{
 @@ -119,6 +119,7 @@
    ("browse!",   keepGoing (browseCmd True),    Nothing, completeModule),
    ("cd",       keepGoing changeDirectory,      Just
 filenameWordBreakChars, completeFilename),
    ("check",    keepGoing checkModule,          Nothing,
 completeHomeModule),
 +  ("clear", keepGoing clearScreen, Nothing, completeNone),
    ("continue",  keepGoing continueCmd,          Nothing, completeNone),
    ("cmd",       keepGoing cmdCmd,               Nothing,
 completeIdentifier),
    ("ctags",    keepGoing createCTagsFileCmd,   Just
 filenameWordBreakChars, completeFilename),
 @@ -200,6 +201,7 @@
   "   :browse[!] [[*]<mod>]       display the names defined by module
 <mod>\n" ++
   "                               (!: more details; *: all top-level
 names)\n" ++
   "   :cd <dir>                   change directory to <dir>\n" ++
 + "   :clear                      clear the screen\n" ++
   "   :cmd <expr>                 run the commands returned by <expr>::IO
 String\n" ++
   "   :ctags [<file>]             create tags file for Vi (default:
 \"tags\")\n" ++
   "   :def <cmd> <expr>           define a command :<cmd>\n" ++
 @@ -936,6 +938,15 @@
    prev_context <- GHC.getContext
    ok <- trySuccess $ GHC.load LoadAllTargets
    afterLoad ok False prev_context
 +
 +clearScreen :: String -> GHCi ()
 +clearScreen _ = do
 +  let cmd = case os of
 +    "windows" -> Just "cls"
 +    "linux" -> Just "clear"
 +    _ -> Nothing
 +  didnt_work <- maybe (return True) shellEscape cmd
 +  when didnt_work (io (putStrLn ("Error: unsupported operating system for
 command 'clear'. Please report a bug.")))

  changeDirectory :: String -> GHCi ()
  changeDirectory "" = do
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3062>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list