0 | module Idris.Pretty.Render
4 | import Idris.REPL.Opts
6 | import Libraries.Text.PrettyPrint.Prettyprinter
7 | import public Libraries.Text.PrettyPrint.Prettyprinter.Render.Terminal
13 | getPageWidth : {auto o : Ref ROpts REPLOpts} -> Core PageWidth
15 | consoleWidth <- getConsoleWidth
16 | case consoleWidth of
18 | cols <- coreLift getTermCols
19 | pure $
if cols == 0 then Unbounded else AvailablePerLine cols 1
20 | Just 0 => pure $
Unbounded
21 | Just cw => pure $
AvailablePerLine (cast cw) 1
24 | render' : PageWidth ->
25 | Maybe (ann -> AnsiStyle) ->
27 | render' pageWidth stylerAnn doc = do
28 | let opts = MkLayoutOptions pageWidth
29 | let layout = layoutPretty opts doc
30 | renderString $
case stylerAnn of
31 | Just stylerAnn => reAnnotateS stylerAnn layout
32 | Nothing => unAnnotateS layout
35 | render : {auto o : Ref ROpts REPLOpts} ->
36 | (ann -> AnsiStyle) ->
37 | Doc ann -> Core String
38 | render stylerAnn doc = pure $
render' !getPageWidth (toMaybe !getColor stylerAnn) doc
41 | renderWithoutColor : {auto o : Ref ROpts REPLOpts} -> Doc ann -> Core String
42 | renderWithoutColor doc = do
43 | pageWidth <- getPageWidth
44 | let opts = MkLayoutOptions pageWidth
45 | let layout = layoutPretty opts doc
46 | pure $
renderString $
unAnnotateS layout
49 | renderWithSpans : {auto o : Ref ROpts REPLOpts} ->
51 | Core (String, List (Span ann))
52 | renderWithSpans doc = do
53 | pageWidth <- getPageWidth
54 | let opts = MkLayoutOptions pageWidth
55 | let layout = layoutPretty opts doc
56 | pure $
displaySpans layout