@@ -424,7 +424,7 @@ ideslavePutSExp cmd info = do i <- getIState
424iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
424iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
425iputGoal g = do i <- getIState
425iputGoal g = do i <- getIState
426 case idris_outputmode i of
426 case idris_outputmode i of
427− RawOutput -> runIO $ displayIO stdout g >> putStrLn ""
427+ RawOutput -> runIO $ putStrLn (displayDecorated (consoleDecorate i) g)
428 IdeSlave n -> runIO . putStrLn $ convSExp "write-goal" (displayS g "") n
428 IdeSlave n -> runIO . putStrLn $ convSExp "write-goal" (displayS g "") n
430isetPrompt :: String -> Idris ()
430isetPrompt :: String -> Idris ()
@@ -757,7 +757,7 @@ eqOpts = []
757elimName = sUN "__Elim"
757elimName = sUN "__Elim"
758elimMethElimTy = sUN "__elimTy"
758elimMethElimTy = sUN "__elimTy"
759elimMethElim = sUN "elim"
759elimMethElim = sUN "elim"
760−elimDecl = PClass "Type class for eliminators" defaultSyntax bi [] elimName [(sUN "scrutineeType", PType)]
760+elimDecl = PClass "Type class for eliminators" defaultSyntax bi [] elimName [(sUN "scrutineeType", PType)]
761 [PTy "" defaultSyntax bi [TotalFn] elimMethElimTy PType,
761 [PTy "" defaultSyntax bi [TotalFn] elimMethElimTy PType,
762 PTy "" defaultSyntax bi [TotalFn] elimMethElim (PRef bi elimMethElimTy)]
762 PTy "" defaultSyntax bi [TotalFn] elimMethElim (PRef bi elimMethElimTy)]
@@ -1722,3 +1722,224 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
1722 mkUniq (PTactics ts) = liftM PTactics (mapM mkUniqT ts)
1722 mkUniq (PTactics ts) = liftM PTactics (mapM mkUniqT ts)
1723 mkUniq t = return t
1723 mkUniq t = return t
1726+---------------------------------------------------------
1728+---------------------------------------------------------
1730+instance Pretty PTerm OutputAnnotation where
1731+ pretty = prettyImp False
1733+-- | Colourise annotations according to an Idris state. It ignores the names
1734+-- in the annotation, as there's no good way to show extended information on a
1736+consoleDecorate :: IState -> OutputAnnotation -> String -> String
1737+consoleDecorate ist _ | not (idris_colourRepl ist) = id
1738+consoleDecorate ist (AnnBoundName _ True) = colouriseImplicit (idris_colourTheme ist)
1739+consoleDecorate ist (AnnBoundName _ False) = colouriseBound (idris_colourTheme ist)
1740+consoleDecorate ist (AnnName n _ _) = let ctxt = tt_ctxt ist
1741+ theme = idris_colourTheme ist
1743+ _ | isDConName n ctxt -> colouriseData theme
1744+ _ | isFnName n ctxt -> colouriseFun theme
1745+ _ | isTConName n ctxt -> colouriseType theme
1746+ _ | otherwise -> id -- don't colourise unknown names
1748+-- | Pretty-print a high-level closed Idris term
1749+prettyImp :: Bool -- ^^ whether to show implicits
1750+ -> PTerm -- ^^ the term to pretty-print
1751+ -> Doc OutputAnnotation
1752+prettyImp impl = pprintPTerm impl []
1754+-- | Pretty-print a high-level Idris term in some bindings context
1755+pprintPTerm :: Bool -- ^^ whether to show implicits
1756+ -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1757+ -> PTerm -- ^^ the term to pretty-print
1758+ -> Doc OutputAnnotation
1759+pprintPTerm impl bnd = prettySe 10 bnd
1761+ prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1762+ prettySe p bnd (PQuote r) =
1763+ if size r > breakingSize then
1764+ text "![" <> line <> pretty r <> text "]"
1766+ text "![" <> pretty r <> text "]"
1767+ prettySe p bnd (PPatvar fc n) = pretty n
1768+ prettySe p bnd (PRef fc n) = prettyName impl bnd n
1769+ prettySe p bnd (PLam n ty sc) =
1771+ if size sc > breakingSize then
1772+ text "\\" <> bindingOf n False <+> text "=>" <> line <> prettySe 10 ((n, False):bnd) sc
1774+ text "\\" <> bindingOf n False <+> text "=>" <+> prettySe 10 ((n, False):bnd) sc
1775+ prettySe p bnd (PLet n ty v sc) =
1777+ if size sc > breakingSize then
1778+ text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <>
1779+ nest nestingSize (prettySe 10 ((n, False):bnd) sc)
1781+ text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <+>
1782+ prettySe 10 ((n, False):bnd) sc
1783+ prettySe p bnd (PPi (Exp l s _ _) n ty sc)
1784+ | n `elem` allNamesIn sc || impl =
1785+ let open = (if l then text "|" else empty) <> lparen in
1787+ if size sc > breakingSize then
1788+ enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1789+ st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1791+ enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1792+ st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1795+ if size sc > breakingSize then
1796+ prettySe 0 bnd ty <+> st <+> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1798+ prettySe 0 bnd ty <+> st <+> text "->" <+> prettySe 10 ((n, False):bnd) sc
1802+ Static -> text "[static]" <> space
1804+ prettySe p bnd (PPi (Imp l s _ _) n ty sc)
1806+ let open = if l then text "|" <> lbrace else lbrace in
1808+ if size sc > breakingSize then
1809+ open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1810+ st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1812+ open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1813+ st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1814+ | otherwise = prettySe 10 ((n, True):bnd) sc
1818+ Static -> text "[static]" <> space
1820+ prettySe p bnd (PPi (Constraint _ _ _) n ty sc) =
1822+ if size sc > breakingSize then
1823+ prettySe 10 bnd ty <+> text "=>" <+> prettySe 10 ((n, True):bnd) sc
1825+ prettySe 10 bnd ty <+> text "=>" <> line <> prettySe 10 ((n, True):bnd) sc
1826+ prettySe p bnd (PPi (TacImp _ _ s _) n ty sc) =
1828+ if size sc > breakingSize then
1829+ lbrace <> text "tacimp" <+> bindingOf n True <+> colon <+> prettySe 10 bnd ty <>
1830+ rbrace <+> text "->" <> line <> prettySe 10 ((n, True):bnd) sc
1832+ lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1833+ rbrace <+> text "->" <+> prettySe 10 ((n, True):bnd) sc
1834+ prettySe p bnd (PApp _ (PRef _ f) [])
1835+ | not impl = pretty f
1836+ prettySe p bnd (PAppBind _ (PRef _ f) [])
1837+ | not impl = text "!" <+> pretty f
1838+ prettySe p bnd (PApp _ (PRef _ op@(UN nm)) args)
1839+ | not (tnull nm) &&
1840+ length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1841+ let [l, r] = getExps args in
1843+ if size r > breakingSize then
1844+ prettySe 1 bnd l <+> prettyName impl bnd op <> line <> prettySe 0 bnd r
1846+ prettySe 1 bnd l <+> prettyName impl bnd op <+> prettySe 0 bnd r
1847+ prettySe p bnd (PApp _ f as) =
1848+ let args = getExps as in
1850+ prettySe 1 bnd f <+>
1851+ align (hsep (if impl
1852+ then map (prettyArgS bnd) as
1853+ else map (prettyArgSe bnd) args))
1854+ prettySe p bnd (PCase _ scr opts) =
1855+ text "case" <+> prettySe 10 bnd scr <+> text "of" <> prettyBody
1857+ prettyBody = foldr (<>) empty $ intersperse (text "|") $ map sc opts
1859+ sc (l, r) = nest nestingSize $ prettySe 10 bnd l <+> text "=>" <+> prettySe 10 bnd r
1860+ prettySe p bnd (PHidden tm) = text "." <> prettySe 0 bnd tm
1861+ prettySe p bnd (PRefl _ _) = annotate (AnnName eqCon Nothing Nothing) $ text "refl"
1862+ prettySe p bnd (PResolveTC _) = text "resolvetc"
1863+ prettySe p bnd (PTrue _) = annotate (AnnName unitTy Nothing Nothing) $ text "()"
1864+ prettySe p bnd (PFalse _) = annotate (AnnName falseTy Nothing Nothing) $ text "_|_"
1865+ prettySe p bnd (PEq _ l r) =
1867+ if size r > breakingSize then
1868+ prettySe 10 bnd l <+> eq <> nest nestingSize (prettySe 10 bnd r)
1870+ prettySe 10 bnd l <+> eq <+> prettySe 10 bnd r
1871+ where eq = annotate (AnnName eqTy Nothing Nothing) (text "=")
1872+ prettySe p bnd (PRewrite _ l r _) =
1874+ if size r > breakingSize then
1875+ text "rewrite" <+> prettySe 10 bnd l <+> text "in" <> nest nestingSize (prettySe 10 bnd r)
1877+ text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1878+ prettySe p bnd (PTyped l r) =
1879+ lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
1880+ prettySe p bnd (PPair _ l r) =
1881+ if size r > breakingSize then
1882+ lparen <> prettySe 10 bnd l <> text "," <>
1883+ line <> prettySe 10 bnd r <> rparen
1885+ lparen <> prettySe 10 bnd l <> text "," <+> prettySe 10 bnd r <> rparen
1886+ prettySe p bnd (PDPair _ l t r) =
1887+ if size r > breakingSize then
1888+ lparen <> prettySe 10 bnd l <+> text "**" <>
1889+ line <> prettySe 10 bnd r <> rparen
1891+ lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1892+ prettySe p bnd (PAlternative a as) =
1893+ lparen <> text "|" <> prettyAs <> text "|" <> rparen
1896+ foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10 bnd) as
1897+ prettySe p bnd PType = text "Type"
1898+ prettySe p bnd (PConstant c) = pretty c
1899+ -- XXX: add pretty for tactics
1900+ prettySe p bnd (PProof ts) =
1901+ text "proof" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1902+ prettySe p bnd (PTactics ts) =
1903+ text "tactics" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1904+ prettySe p bnd (PMetavar n) = text "?" <> pretty n
1905+ prettySe p bnd (PReturn f) = text "return"
1906+ prettySe p bnd PImpossible = text "impossible"
1907+ prettySe p bnd Placeholder = text "_"
1908+ prettySe p bnd (PDoBlock _) = text "do block pretty not implemented"
1909+ prettySe p bnd (PElabError s) = pretty s
1911+ prettySe p bnd _ = text "test"
1913+ prettyArgS bnd (PImp _ _ _ n tm _) = prettyArgSi bnd (n, tm)
1914+ prettyArgS bnd (PExp _ _ tm _) = prettyArgSe bnd tm
1915+ prettyArgS bnd (PConstraint _ _ tm _) = prettyArgSc bnd tm
1916+ prettyArgS bnd (PTacImplicit _ _ n _ tm _) = prettyArgSti bnd (n, tm)
1918+ prettyArgSe bnd arg = prettySe 0 bnd arg
1919+ prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1920+ prettyArgSc bnd val = lbrace <> lbrace <> prettySe 10 bnd val <> rbrace <> rbrace
1921+ prettyArgSti bnd (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1924+ bracket outer inner doc
1925+ | inner > outer = lparen <> doc <> rparen
1928+-- | Pretty-printer helper for the binding site of a name
1929+bindingOf :: Name -- ^^ the bound name
1930+ -> Bool -- ^^ whether the name is implicit
1931+ -> Doc OutputAnnotation
1932+bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1934+-- | Pretty-printer helper for names that attaches the correct annotations
1935+prettyName :: Bool -- ^^ whether to show namespaces
1936+ -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1937+ -> Name -- ^^ the name to pprint
1938+ -> Doc OutputAnnotation
1939+prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1940+ | otherwise = annotate (AnnName n Nothing Nothing) (text (strName n))
1941+ where strName (UN n) = T.unpack n
1942+ strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1943+ | otherwise = strName n
1944+ strName (MN i s) = "{" ++ T.unpack s ++ show i ++ "}"
1945+ strName other = show other