mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-14 07:51:12 +03:00
simplify paragraphyText, it's now much better behaved
This commit is contained in:
parent
bf312d314f
commit
d296266602
@ -49,7 +49,7 @@ displayDoc :: (Var v, Monad m)
|
|||||||
displayDoc ppe terms typeOf evaluated types t = go t
|
displayDoc ppe terms typeOf evaluated types t = go t
|
||||||
where
|
where
|
||||||
go (DD.DocJoin docs) = foldMap id <$> traverse go docs
|
go (DD.DocJoin docs) = foldMap id <$> traverse go docs
|
||||||
go (DD.DocBlob txt) = pure $ P.text txt
|
go (DD.DocBlob txt) = pure $ P.paragraphyText txt
|
||||||
go (DD.DocLink (DD.LinkTerm (Term.TermLink' r))) = pure $ P.underline (termName ppe r)
|
go (DD.DocLink (DD.LinkTerm (Term.TermLink' r))) = pure $ P.underline (termName ppe r)
|
||||||
go (DD.DocLink (DD.LinkType (Term.TypeLink' r))) = pure $ P.underline (typeName ppe r)
|
go (DD.DocLink (DD.LinkType (Term.TypeLink' r))) = pure $ P.underline (typeName ppe r)
|
||||||
go (DD.DocSource (DD.LinkTerm (Term.TermLink' r))) = prettyTerm terms r
|
go (DD.DocSource (DD.LinkTerm (Term.TermLink' r))) = prettyTerm terms r
|
||||||
|
@ -143,22 +143,15 @@ wrapImpl (p:ps) = wrap_ . Seq.fromList $
|
|||||||
wrapString :: (LL.ListLike s Char, IsString s) => String -> Pretty s
|
wrapString :: (LL.ListLike s Char, IsString s) => String -> Pretty s
|
||||||
wrapString s = wrap (lit $ fromString s)
|
wrapString s = wrap (lit $ fromString s)
|
||||||
|
|
||||||
-- 0. Preserve all leading and trailing spaces
|
-- 0. Preserve all leading and trailing whitespace
|
||||||
-- 1. Convert multiple adjacent blank lines to a single blank line.
|
-- 1. Preserve all newlines
|
||||||
-- 2. Combine adjacent non-blank lines into one line.
|
-- 2. Wrap all text in between newlines
|
||||||
-- 3. Wrap each remaining line.
|
|
||||||
paragraphyText :: (LL.ListLike s Char, IsString s) => Text -> Pretty s
|
paragraphyText :: (LL.ListLike s Char, IsString s) => Text -> Pretty s
|
||||||
paragraphyText t = case span isSpace (Text.unpack $ Text.dropWhileEnd isSpace t) of
|
paragraphyText t = text start <> inner <> text end where
|
||||||
(sp,t) -> string sp <> lines (go mempty t)
|
inner = sep "\n" . fmap (wrap . text) . Text.splitOn "\n" $ t'
|
||||||
where
|
(start, t0) = Text.span isSpace t
|
||||||
trailingSp = Text.takeWhileEnd isSpace t
|
t' = Text.dropWhileEnd isSpace t0
|
||||||
go acc [] = [wrap acc <> text trailingSp]
|
end = Text.takeWhileEnd isSpace t0
|
||||||
go acc (span isSpace -> (sp, rest)) =
|
|
||||||
if length (filter (=='\n') sp) < 2 then munch acc
|
|
||||||
else wrap acc : mempty : munch mempty
|
|
||||||
where
|
|
||||||
munch acc = case break isSpace rest of
|
|
||||||
(nonsp, rest) -> go (acc <> string nonsp) rest
|
|
||||||
|
|
||||||
wrap :: (LL.ListLike s Char, IsString s) => Pretty s -> Pretty s
|
wrap :: (LL.ListLike s Char, IsString s) => Pretty s -> Pretty s
|
||||||
wrap p = wrapImpl (toLeaves [p]) where
|
wrap p = wrapImpl (toLeaves [p]) where
|
||||||
|
@ -50,7 +50,7 @@ use .builtin
|
|||||||
|
|
||||||
docs.List.take = [:
|
docs.List.take = [:
|
||||||
|
|
||||||
`@List.take n xs` returns the first `n` elements of `xs`
|
`@List.take n xs` returns the first `n` elements of `xs`. (No need to add line breaks manually. The display command will do wrapping of text for you.)
|
||||||
|
|
||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ use .builtin
|
|||||||
|
|
||||||
docs.List.take = [:
|
docs.List.take = [:
|
||||||
|
|
||||||
`@List.take n xs` returns the first `n` elements of `xs`
|
`@List.take n xs` returns the first `n` elements of `xs`. (No need to add line breaks manually. The display command will do wrapping of text for you.)
|
||||||
|
|
||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
@ -147,7 +147,9 @@ Now that documentation is linked to the definition. We can view it if we like:
|
|||||||
|
|
||||||
.> display 1
|
.> display 1
|
||||||
|
|
||||||
`builtin.List.take n xs` returns the first `n` elements of `xs`
|
`builtin.List.take n xs` returns the first `n` elements of
|
||||||
|
`xs`. (No need to add line breaks manually. The display
|
||||||
|
command will do wrapping of text for you.)
|
||||||
|
|
||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
@ -166,7 +168,9 @@ Or there's also a convenient function, `docs`, which shows the `Doc` values that
|
|||||||
```ucm
|
```ucm
|
||||||
.> docs builtin.List.take
|
.> docs builtin.List.take
|
||||||
|
|
||||||
`builtin.List.take n xs` returns the first `n` elements of `xs`
|
`builtin.List.take n xs` returns the first `n` elements of
|
||||||
|
`xs`. (No need to add line breaks manually. The display
|
||||||
|
command will do wrapping of text for you.)
|
||||||
|
|
||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user