@@ -6,6 +6,7 @@ import Idris.Core.TT
6import Idris.Core.Evaluate (isDConName, isTConName, isFnName, normaliseAll)
6import Idris.Core.Evaluate (isDConName, isTConName, isFnName, normaliseAll)
8import Idris.AbsSyntax
8import Idris.AbsSyntax
9+import Idris.Colours (hStartColourise, hEndColourise)
9import Idris.Delaborate
10import Idris.Delaborate
10import Idris.Docstrings
11import Idris.Docstrings
11import Idris.IdeMode
12import Idris.IdeMode
@@ -17,7 +18,7 @@ import Control.Monad.Trans.Except (ExceptT (ExceptT), runExceptT)
18import System.Console.Haskeline.MonadException
19import System.Console.Haskeline.MonadException
19 (MonadException (controlIO), RunIO (RunIO))
20 (MonadException (controlIO), RunIO (RunIO))
20−import System.IO (stdout, Handle, hPutStrLn)
21+import System.IO (stdout, Handle, hPutStrLn, hPutStr)
21import System.FilePath (replaceExtension)
22import System.FilePath (replaceExtension)
23import Prelude hiding ((<$>))
24import Prelude hiding ((<$>))
@@ -45,7 +46,7 @@ iWarn fc err =
45 case fc of
46 case fc of
46 FC fn _ _ | fn /= "" -> text (show fc) <> colon <//> err
47 FC fn _ _ | fn /= "" -> text (show fc) <> colon <//> err
48− runIO . hPutStrLn h $ displayDecorated (consoleDecorate i) err'
49+ hWriteDoc h i err'
49 IdeMode n h ->
50 IdeMode n h ->
50 do err' <- iRender . fmap (fancifyAnnots i True) $ err
51 do err' <- iRender . fmap (fancifyAnnots i True) $ err
51 let (str, spans) = displaySpans err'
52 let (str, spans) = displaySpans err'
@@ -68,13 +69,23 @@ iRender d = do w <- getWidth
68 | otherwise -> do width <- runIO getScreenWidth
69 | otherwise -> do width <- runIO getScreenWidth
69 return $ renderPretty 0.8 width d
70 return $ renderPretty 0.8 width d
72+hWriteDoc :: Handle -> IState -> SimpleDoc OutputAnnotation -> Idris ()
73+hWriteDoc h ist rendered =
74+ do runIO $ displayDecoratedA
76+ (maybe (return ()) (hStartColourise h))
77+ (maybe (return ()) (hEndColourise h))
78+ (fmap (annotationColour ist) rendered)
79+ runIO $ hPutStr h "\n" -- newline translation on the output
80+ -- stream should take care of this for
71-- | Write a pretty-printed term to the console with semantic coloring
83-- | Write a pretty-printed term to the console with semantic coloring
72consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
84consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
73−consoleDisplayAnnotated h output = do ist <- getIState
85+consoleDisplayAnnotated h output =
74− rendered <- iRender $ output
87+ rendered <- iRender output
75− runIO . hPutStrLn h .
76− displayDecorated (consoleDecorate ist) $
77− rendered
88+ hWriteDoc h ist rendered
79iPrintTermWithType :: Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
90iPrintTermWithType :: Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
80iPrintTermWithType tm ty = iRenderResult (tm <+> colon <+> align ty)
91iPrintTermWithType tm ty = iRenderResult (tm <+> colon <+> align ty)
@@ -97,7 +108,8 @@ iRenderOutput doc =
97 do i <- getIState
108 do i <- getIState
98 case idris_outputmode i of
109 case idris_outputmode i of
99 RawOutput h -> do out <- iRender doc
110 RawOutput h -> do out <- iRender doc
100− runIO $ putStrLn (displayDecorated (consoleDecorate i) out)
111+ hWriteDoc h i out
101 IdeMode n h ->
113 IdeMode n h ->
102 do (str, spans) <- fmap displaySpans . iRender . fmap (fancifyAnnots i True) $ doc
114 do (str, spans) <- fmap displaySpans . iRender . fmap (fancifyAnnots i True) $ doc
103 let out = [toSExp str, toSExp spans]
115 let out = [toSExp str, toSExp spans]
@@ -168,7 +180,7 @@ idemodePutSExp cmd info = do i <- getIState
168iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
180iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
169iputGoal g = do i <- getIState
181iputGoal g = do i <- getIState
170 case idris_outputmode i of
182 case idris_outputmode i of
171− RawOutput h -> runIO $ hPutStrLn h (displayDecorated (consoleDecorate i) g)
183+ RawOutput h -> hWriteDoc h i g
172 IdeMode n h ->
184 IdeMode n h ->
173 let (str, spans) = displaySpans . fmap (fancifyAnnots i True) $ g
185 let (str, spans) = displaySpans . fmap (fancifyAnnots i True) $ g
174 goal = [toSExp str, toSExp spans]
186 goal = [toSExp str, toSExp spans]