Ticket #3062 (closed feature request: wontfix)

Opened 4 years ago

Last modified 4 years ago

Adding a ":clear" clear-screen command to GHCi

Reported by: porges Owned by:
Priority: normal Milestone:
Component: GHCi Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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

Change History

Changed 4 years ago by judah

You can use ghci macros to do this:

 http://haskell.org/haskellwiki/GHC/GHCi

Add the following line to your ~/.ghci file:

:def clear \_ -> return $ ":!clear"

Changed 4 years ago by simonmar

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to wontfix

I don't think this is something we need to add to GHCi. e.g. just hitting Ctrl-L does it for me.

Note: See TracTickets for help on using tickets.