packages feed

snippet-0.1.0.1: README.lhs

# Snippet

[![Release](https://codeberg.org/pbrisbin/snippet/badges/release.svg)](https://codeberg.org/pbrisbin/snippet/releases)
[![Hackage](https://img.shields.io/hackage/v/snippet.svg?style=flat)](https://hackage.haskell.org/package/snippet)
[![Stackage LTS](http://stackage.org/package/snippet/badge/lts)](http://stackage.org/lts/package/snippet)
[![Stackage Nightly](http://stackage.org/package/snippet/badge/nightly)](http://stackage.org/nightly/package/snippet)
[![CI](https://codeberg.org/pbrisbin/snippet/badges/workflows/ci.yml/badge.svg)](https://codeberg.org/pbrisbin/snippet/actions?workflows=ci.yml)

Pretty-print regions within source code files.

## 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 = 32
      , endLine = Just 44
      , 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:

![](./example.png)

Supplying an alternative `annToAnsi` function is how you can adjust colors.

## License

This package is licensed AGPLv3. See [COPYING](./COPYING).