From 3ee0e7596f55ebbe5eb99e2ba49dc4e2d7414262 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Tue, 8 May 2007 13:33:14 +0000 Subject: [PATCH] improvements to :history :hist displays at most the last steps (default 20). --- compiler/ghci/InteractiveUI.hs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 77acf89..a1d803c 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -74,6 +74,7 @@ import Data.Char import Data.Dynamic import Data.Array import Control.Monad as Monad +import Text.Printf import Foreign.StablePtr ( newStablePtr ) import GHC.Exts ( unsafeCoerce# ) @@ -1484,15 +1485,23 @@ deleteCmd argLine = do | otherwise = return () historyCmd :: String -> GHCi () -historyCmd = noArgs $ do - s <- getSession - resumes <- io $ GHC.getResumeContext s - case resumes of - [] -> io $ putStrLn "Not stopped at a breakpoint" - (r:rs) -> do - let hist = GHC.resumeHistory r - spans <- mapM (io . GHC.getHistorySpan s) hist - printForUser (vcat (map ppr spans)) +historyCmd arg + | null arg = history 20 + | all isDigit arg = history (read arg) + | otherwise = io $ putStrLn "Syntax: :history [num]" + where + history num = do + s <- getSession + resumes <- io $ GHC.getResumeContext s + case resumes of + [] -> io $ putStrLn "Not stopped at a breakpoint" + (r:rs) -> do + let hist = GHC.resumeHistory r + (took,rest) = splitAt num hist + spans <- mapM (io . GHC.getHistorySpan s) took + let nums = map (printf "-%-3d:") [(1::Int)..] + printForUser (vcat (zipWith (<+>) (map text nums) (map ppr spans))) + io $ putStrLn $ if null rest then "" else "..." backCmd :: String -> GHCi () backCmd = noArgs $ do -- 1.7.10.4