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
27ihWarn :: Handle -> FC -> Doc OutputAnnotation -> Idris ()
28ihWarn h fc err = do i <- getIState
29 case idris_outputmode i of
31 do err' <- iRender . fmap (fancifyAnnots i) $
33 then text (show fc) <> colon <//> err
35 runIO . hPutStrLn h $ displayDecorated (consoleDecorate i) err'
37 do err' <- iRender . fmap (fancifyAnnots i) $ err
38 let (str, spans) = displaySpans err'
40 convSExp "warning" (fc_fname fc, fc_start fc, fc_end fc, str, spans) n
42iRender :: Doc a -> Idris (SimpleDoc a)
43iRender d = do w <- getWidth
45 let ideSlave = case idris_outputmode ist of
49 InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
50 ColsWide n -> return $
52 then renderPretty 1.0 1000000000 d
53 else renderPretty 0.8 n d
54 AutomaticWidth | ideSlave -> return $ renderPretty 1.0 1000000000 d
55 | otherwise -> do width <- runIO getScreenWidth
56 return $ renderPretty 0.8 width d
58-- | Write a pretty-printed term to the console with semantic coloring
59consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
60consoleDisplayAnnotated h output = do ist <- getIState
61 rendered <- iRender $ output
63 displayDecorated (consoleDecorate ist) $
66ihPrintTermWithType :: Handle -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
67ihPrintTermWithType h tm ty = ihRenderResult h (tm <+> colon <+> align ty)
69-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
70ihPrintFunTypes :: Handle -> [(Name, Bool)] -> Name -> [(Name, PTerm)] -> Idris ()
71ihPrintFunTypes h bnd n [] = ihPrintError h $ "No such variable " ++ show n
72ihPrintFunTypes h bnd n overloads = do ist <- getIState
73 let ppo = ppOptionIst ist
74 let infixes = idris_infixes ist
75 let output = vsep (map (uncurry (ppOverload ppo infixes)) overloads)
76 ihRenderResult h output
77 where fullName n = prettyName True True bnd n
78 ppOverload ppo infixes n tm =
79 fullName n <+> colon <+> align (pprintPTerm ppo bnd [] infixes tm)
81ihRenderResult :: Handle -> Doc OutputAnnotation -> Idris ()
82ihRenderResult h d = do ist <- getIState
83 case idris_outputmode ist of
84 RawOutput -> consoleDisplayAnnotated h d
85 IdeSlave n -> ideSlaveReturnAnnotated n h d
87ideSlaveReturnWithStatus :: String -> Integer -> Handle -> Doc OutputAnnotation -> Idris ()
88ideSlaveReturnWithStatus status n h out = do
90 (str, spans) <- fmap displaySpans .
92 fmap (fancifyAnnots ist) $
94 let good = [SymbolAtom status, toSExp str, toSExp spans]
95 runIO . hPutStrLn h $ convSExp "return" good n
98-- | Write pretty-printed output to IDESlave with semantic annotations
99ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
100ideSlaveReturnAnnotated = ideSlaveReturnWithStatus "ok"
102-- | Show an error with semantic highlighting
103ihRenderError :: Handle -> Doc OutputAnnotation -> Idris ()
104ihRenderError h e = do ist <- getIState
105 case idris_outputmode ist of
106 RawOutput -> consoleDisplayAnnotated h e
107 IdeSlave n -> ideSlaveReturnWithStatus "error" n h e
109ihPrintWithStatus :: String -> Handle -> String -> Idris ()
110ihPrintWithStatus status h s = do
112 case idris_outputmode i of
113 RawOutput -> case s of
115 s -> runIO $ hPutStrLn h s
117 let good = SexpList [SymbolAtom status, toSExp s] in
118 runIO $ hPutStrLn h $ convSExp "return" good n
121ihPrintResult :: Handle -> String -> Idris ()
122ihPrintResult = ihPrintWithStatus "ok"
124ihPrintError :: Handle -> String -> Idris ()
125ihPrintError = ihPrintWithStatus "error"
127ihputStrLn :: Handle -> String -> Idris ()
128ihputStrLn h s = do i <- getIState
129 case idris_outputmode i of
130 RawOutput -> runIO $ hPutStrLn h s
131 IdeSlave n -> runIO . hPutStrLn h $ convSExp "write-string" s n
133iputStrLn = ihputStrLn stdout
134iPrintError = ihPrintError stdout
135iPrintResult = ihPrintResult stdout
138ideslavePutSExp :: SExpable a => String -> a -> Idris ()
139ideslavePutSExp cmd info = do i <- getIState
140 case idris_outputmode i of
141 IdeSlave n -> runIO . putStrLn $ convSExp cmd info n
144-- this needs some typing magic and more structured output towards emacs
145iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
146iputGoal g = do i <- getIState
147 case idris_outputmode i of
148 RawOutput -> runIO $ putStrLn (displayDecorated (consoleDecorate i) g)
149 IdeSlave n -> runIO . putStrLn $
150 convSExp "write-goal" (displayS (fmap (fancifyAnnots i) g) "") n
152-- | Warn about totality problems without failing to compile
153warnTotality :: Idris ()
154warnTotality = do ist <- getIState
155 mapM_ (warn ist) (nub (idris_totcheckfail ist))
156 where warn ist (fc, e) = iWarn fc (pprintErr ist (Msg e))
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