Skip to content

Commit 514fa08

Browse files
committed
Let render take a string to specify the render type
This seems cleaner than a boolean parameter.
1 parent 9be091e commit 514fa08

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Documentation
5353

5454
#### render
5555

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

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

@@ -65,9 +65,9 @@ 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)
68+
`style`
69+
: Whether to generate 'plain' or 'ANSI' terminal output. Must be
70+
either `'plain'` or `'ansi'`. Defaults to `'plain'`. (string)
7171

7272
### Doc construction
7373

src/HsLua/Module/DocLayout.hs

+9-2
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,22 @@ render = defun "render"
268268
"Maximum number of characters per line.\n" <>
269269
"A value of `nil`, the default, means that the text " <>
270270
"is not reflown.")
271-
<#> opt (boolParam "ansi" $
271+
<#> opt (parameter peekRenderStyle "string" "style" $
272272
"Whether to generate plain text or ANSI terminal output.\n" <>
273-
"Defaults to `false`.")
273+
"Must be either `'plain'` or `'ansi'`.\n" <>
274+
"Defaults to `'plain'`.")
274275
=#> functionResult pushText "string" "rendered doc"
275276
#? T.unlines
276277
[ "Render a [[Doc]]. The text is reflowed on breakable spaces to"
277278
, "match the given line length. Text is not reflowed if the line"
278279
, "line length parameter is omitted or nil."
279280
]
281+
where
282+
peekRenderStyle idx = peekByteString idx >>= \case
283+
"ansi" -> pure True
284+
"ANSI" -> pure True
285+
"plain" -> pure False
286+
style -> failPeek $ "Unknown rendering style: " <> style
280287

281288
--
282289
-- Querying

test/test-doclayout.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local test = tasty.test_case
99
local assert = tasty.assert
1010

1111
local function renderANSI (doc, cols)
12-
return doclayout.render(doc, cols, true)
12+
return doclayout.render(doc, cols, 'ansi')
1313
end
1414

1515
-- Check existence static fields

0 commit comments

Comments
 (0)