Skip to content

Commit 0b14f4d

Browse files
committed
Add support for ANSI to render
1 parent 1ae24ca commit 0b14f4d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Documentation
5353

5454
#### render
5555

56-
`render (doc[, colwidth])`
56+
`render (doc[, colwidth[, ansi]])`
5757

5858
Render the `Doc` using the given column width.
5959

@@ -65,6 +65,10 @@ Parameters:
6565
`colwidth`
6666
: Maximum number of characters per line
6767

68+
`ansi`
69+
: Whether to generate plain or ANSI terminal output. Defaults to
70+
`false`. (boolean)
71+
6872
### Doc construction
6973

7074
All functions return a fresh `Doc` element.

src/HsLua/Module/DocLayout.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import HsLua as Lua hiding (concat)
7676
import Text.DocLayout (Doc, (<+>), ($$), ($+$))
7777

7878
import qualified Data.Text as T
79+
import qualified Data.Text.Lazy as TL
7980
import qualified Text.DocLayout as Doc
8081

8182
--
@@ -243,9 +244,18 @@ typeDoc = deftype "Doc"
243244
-- line length parameter is omitted or nil.
244245
render :: LuaError e => DocumentedFunction e
245246
render = defun "render"
246-
### liftPure2 (flip Doc.render)
247+
### (\doc mbcolwidth useAnsi ->
248+
if useAnsi == Just True
249+
then pure $ TL.toStrict $ Doc.renderANSI mbcolwidth doc
250+
else pure $ Doc.renderPlain mbcolwidth doc)
247251
<#> docParam "doc"
248-
<#> opt (integralParam "colwidth" "planned maximum line length")
252+
<#> opt (integralParam "colwidth" $
253+
"Maximum number of characters per line.\n" <>
254+
"A value of `nil`, the default, means that the text " <>
255+
"is not reflown.")
256+
<#> opt (boolParam "ansi" $
257+
"Whether to generate plain text or ANSI terminal output.\n" <>
258+
"Defaults to `false`.")
249259
=#> functionResult pushText "string" "rendered doc"
250260
#? T.unlines
251261
[ "Render a [[Doc]]. The text is reflowed on breakable spaces to"

0 commit comments

Comments
 (0)