snippet-0.1.0.0: README.lhs
# Snippet
## Usage
<!--
```haskell
module Main (main) where
import Text.Markdown.Unlit ()
```
-->
```haskell
import Prelude
import Data.Foldable (traverse_)
import Prettyprinter (reAnnotate)
import Prettyprinter.Render.Terminal (putDoc)
import Snippet
import Snippet.Pretty
main :: IO ()
main = do
let
region = Region
{ startLine = 24
, endLine = Just 36
, startColumn = Just 8
, endColumn = Nothing
}
-- Returns Nothing if file is missing/empty or region is invalid
mSnippet <- snippetFromFile region "README.md"
traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet
```
The above `Region` focuses just the body of the `do` block in this file.
Rendering it with the default `annToAnsi` looks like:

Supplying an alternative `annToAnsi` function is how you can adjust colors.
> [!NOTE]
>
> The simple `putDoc` function is fine for this toy example because the lines
> are narrow enough not to break. In real usage, you should implement your own
> layout using an [`Unbounded` `PageWidth`][unbounded].
[unbounded]: https://hackage-content.haskell.org/package/prettyprinter-1.7.2/docs/Prettyprinter.html#t:PageWidth
## License
This package is licensed AGPLv3. See [COPYING](./COPYING).