snippet: Pretty-print regions within source code files

[ agpl, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Pretty-print Regions of source-code, i.e. snippets.

This is meant to mimic tooling available in rust and used by tools such as sarif-fmt.

For example, focusing on a region within our README:

   ┌─ README.md:32:8
   │
32 │   main = do
   │ ╭────────^
33 │ │   let
34 │ │     region = Region
35 │ │       { startLine = 32
36 │ │       , endLine = Just 44
37 │ │       , startColumn = Just 8
38 │ │       , endColumn = Nothing
39 │ │       }
40 │ │
41 │ │   -- Returns Nothing if file is missing/empty or region is invalid
42 │ │   mSnippet <- snippetFromFile region "README.md"
43 │ │
44 │ │   traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet
   │ ╰────────────────────────────────────────────────────────────────────^

To see the code that produces this, and an image of the output (e.g. with color), view the README on Codeberg.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.0, 0.1.0.0, 0.1.0.1, 0.1.0.2
Change log CHANGELOG.md
Dependencies base (>=4.16.4.0 && <5), directory (>=1.3.6.2), prettyprinter (>=1.7.1), prettyprinter-ansi-terminal (>=1.1.3), text (>=1.2.5.0) [details]
License AGPL-3.0-only
Author
Maintainer Patrick Brisbin
Uploaded by PatrickBrisbin at 2026-10-28T18:25:54Z
Category Data
Home page https://codeberg.org/pbrisbin/snippet#readme
Bug tracker https://codeberg.org/pbrisbin/snippet/issues
Source repo head: git clone https://codeberg.org/pbrisbin/snippet
Distributions
Downloads 9 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-10-28 [all 1 reports]

Readme for snippet-0.1.0.2

[back to package description]

Snippet

Release Hackage Stackage LTS Stackage Nightly CI

Pretty-print regions within source code files.

Usage

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:

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

License

This package is licensed AGPLv3. See COPYING.