1module Idris.Output where
4import Idris.Core.Evaluate (isDConName, isTConName, isFnName)
12import Util.ScreenSize (getScreenWidth)
16import System.IO (stdout, Handle, hPutStrLn)
18import Data.Char (isAlpha)
20import Data.Maybe (fromMaybe)
22pshow :: IState -> Err -> String
23pshow ist err = displayDecorated (consoleDecorate ist) .
25 fmap (fancifyAnnots ist) $ pprintErr ist err
27iWarn :: FC -> Doc OutputAnnotation -> Idris ()
30 case idris_outputmode i of
32 do err' <- iRender . fmap (fancifyAnnots i) $
34 then text (show fc) <> colon <//> err
36 runIO . hPutStrLn h $ displayDecorated (consoleDecorate i) err'
38 do err' <- iRender . fmap (fancifyAnnots i) $ err
39 let (str, spans) = displaySpans err'
41 convSExp "warning" (fc_fname fc, fc_start fc, fc_end fc, str, spans) n
43iRender :: Doc a -> Idris (SimpleDoc a)
44iRender d = do w <- getWidth
46 let ideSlave = case idris_outputmode ist of
50 InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
51 ColsWide n -> return $
53 then renderPretty 1.0 1000000000 d
54 else renderPretty 0.8 n d
55 AutomaticWidth | ideSlave -> return $ renderPretty 1.0 1000000000 d
56 | otherwise -> do width <- runIO getScreenWidth
57 return $ renderPretty 0.8 width d
59-- | Write a pretty-printed term to the console with semantic coloring
60consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
61consoleDisplayAnnotated h output = do ist <- getIState
62 rendered <- iRender $ output
64 displayDecorated (consoleDecorate ist) $
67iPrintTermWithType :: Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
68iPrintTermWithType tm ty = iRenderResult (tm <+> colon <+> align ty)
70-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
71iPrintFunTypes :: [(Name, Bool)] -> Name -> [(Name, PTerm)] -> Idris ()
72iPrintFunTypes bnd n [] = iPrintError $ "No such variable " ++ show n
73iPrintFunTypes bnd n overloads = do ist <- getIState
74 let ppo = ppOptionIst ist
75 let infixes = idris_infixes ist
76 let output = vsep (map (uncurry (ppOverload ppo infixes)) overloads)
78 where fullName n = prettyName True True bnd n
79 ppOverload ppo infixes n tm =
80 fullName n <+> colon <+> align (pprintPTerm ppo bnd [] infixes tm)
82iRenderOutput :: Doc OutputAnnotation -> Idris ()
85 case idris_outputmode i of
86 RawOutput h -> do out <- iRender doc
87 runIO $ putStrLn (displayDecorated (consoleDecorate i) out)
89 do (str, spans) <- fmap displaySpans . iRender . fmap (fancifyAnnots i) $ doc
90 let out = [toSExp str, toSExp spans]
91 runIO . hPutStrLn h $ convSExp "write-decorated" out n
93iRenderResult :: Doc OutputAnnotation -> Idris ()
94iRenderResult d = do ist <- getIState
95 case idris_outputmode ist of
96 RawOutput h -> consoleDisplayAnnotated h d
97 IdeSlave n h -> ideSlaveReturnAnnotated n h d
99ideSlaveReturnWithStatus :: String -> Integer -> Handle -> Doc OutputAnnotation -> Idris ()
100ideSlaveReturnWithStatus status n h out = do
102 (str, spans) <- fmap displaySpans .
104 fmap (fancifyAnnots ist) $
106 let good = [SymbolAtom status, toSExp str, toSExp spans]
107 runIO . hPutStrLn h $ convSExp "return" good n
110-- | Write pretty-printed output to IDESlave with semantic annotations
111ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
112ideSlaveReturnAnnotated = ideSlaveReturnWithStatus "ok"
114-- | Show an error with semantic highlighting
115iRenderError :: Doc OutputAnnotation -> Idris ()
116iRenderError e = do ist <- getIState
117 case idris_outputmode ist of
118 RawOutput h -> consoleDisplayAnnotated h e
119 IdeSlave n h -> ideSlaveReturnWithStatus "error" n h e
121iPrintWithStatus :: String -> String -> Idris ()
122iPrintWithStatus status s = do
124 case idris_outputmode i of
125 RawOutput h -> case s of
127 s -> runIO $ hPutStrLn h s
129 let good = SexpList [SymbolAtom status, toSExp s] in
130 runIO $ hPutStrLn h $ convSExp "return" good n
133iPrintResult :: String -> Idris ()
134iPrintResult = iPrintWithStatus "ok"
136iPrintError :: String -> Idris ()
137iPrintError = iPrintWithStatus "error"
139iputStrLn :: String -> Idris ()
140iputStrLn s = do i <- getIState
141 case idris_outputmode i of
142 RawOutput h -> runIO $ hPutStrLn h s
143 IdeSlave n h -> runIO . hPutStrLn h $ convSExp "write-string" s n
146ideslavePutSExp :: SExpable a => String -> a -> Idris ()
147ideslavePutSExp cmd info = do i <- getIState
148 case idris_outputmode i of
149 IdeSlave n h -> runIO . hPutStrLn h $ convSExp cmd info n
152-- TODO: send structured output similar to the metavariable list
153iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
154iputGoal g = do i <- getIState
155 case idris_outputmode i of
156 RawOutput h -> runIO $ hPutStrLn h (displayDecorated (consoleDecorate i) g)
158 let (str, spans) = displaySpans . fmap (fancifyAnnots i) $ g
159 goal = [toSExp str, toSExp spans]
160 in runIO . hPutStrLn h $ convSExp "write-goal" goal n
162-- | Warn about totality problems without failing to compile
163warnTotality :: Idris ()
164warnTotality = do ist <- getIState
165 mapM_ (warn ist) (nub (idris_totcheckfail ist))
166 where warn ist (fc, e) = iWarn fc (pprintErr ist (Msg e))
169printUndefinedNames :: [Name] -> Doc OutputAnnotation
170printUndefinedNames ns = text "Undefined " <> names <> text "."
171 where names = encloseSep empty empty (char ',') $ map ppName ns
172 ppName = prettyName True True []
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list