{"id":13442294,"url":"https://github.com/greglook/puget","last_synced_at":"2025-05-16T02:08:16.498Z","repository":{"id":11755826,"uuid":"14288135","full_name":"greglook/puget","owner":"greglook","description":"Canonical Colorizing Clojure Printer","archived":false,"fork":false,"pushed_at":"2023-01-07T21:24:01.000Z","size":405,"stargazers_count":256,"open_issues_count":4,"forks_count":28,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-13T22:38:07.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greglook.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-11T00:58:18.000Z","updated_at":"2025-05-06T21:35:33.000Z","dependencies_parsed_at":"2023-01-13T16:39:05.573Z","dependency_job_id":null,"html_url":"https://github.com/greglook/puget","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greglook%2Fpuget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greglook%2Fpuget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greglook%2Fpuget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greglook%2Fpuget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greglook","download_url":"https://codeload.github.com/greglook/puget/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254284817,"owners_count":22045454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:43.996Z","updated_at":"2025-05-16T02:08:16.471Z","avatar_url":"https://github.com/greglook.png","language":"Clojure","funding_links":[],"categories":["Clojure","Libraries"],"sub_categories":[],"readme":"Puget\n=====\n\n[![Build Status](https://circleci.com/gh/greglook/puget.svg?style=shield\u0026circle-token=cce98d9ba9811c55b454e22db02c338f81d6b093)](https://circleci.com/gh/greglook/puget)\n[![Coverage Status](https://codecov.io/gh/greglook/puget/branch/main/graph/badge.svg)](https://codecov.io/gh/greglook/puget/branch/main)\n[![cljdoc](https://cljdoc.org/badge/mvxcvi/puget)](https://cljdoc.org/d/mvxcvi/puget/CURRENT)\n\nPuget is a Clojure library for printing Clojure and\n[EDN](https://github.com/edn-format/edn) values. Under the hood, Puget formats\ndata into _print documents_ and uses\n[fipp](https://github.com/brandonbloom/fipp) to render them.\n\n![output example](screenshot.png)\n\nPuget offers several features which set it apart from FIPP and Clojure's native\npretty-printing functions. [Syntax coloring](#syntax-coloring) is the most\nwidely used, followed by [canonical printing](#canonical-representation). Custom\nvalue rendering is supported using type dispatch to select [print\nhandlers](#type-extensions).\n\n## Installation\n\nPuget releases are published on Clojars. To use the latest version with\nLeiningen, add the following dependency to your project definition:\n\n[![Clojars Project](http://clojars.org/mvxcvi/puget/latest-version.svg)](http://clojars.org/mvxcvi/puget)\n\nSee [Whidbey](https://github.com/greglook/whidbey) for nREPL and Leiningen integration.\n\n## Usage\n\nPuget's printing is controlled by a map of options which configure things like\nprint width, sorting mode, color scheme and style, whether to print metadata,\nand so on. The default options are held in the dynamic var\n`puget.printer/*options*`, which can be bound using `with-options`. See the\n[`puget.printer`](https://cljdoc.org/d/mvxcvi/puget/CURRENT/api/puget.printer)\nnamespace documentation for the full set of options.\n\nThese options are used to construct a _printer_ to render values with. `pprint`\nand `pprint-str` will automatically create a `PrettyPrinter` record from the\ncurrent and passed options, or you can use `pretty-printer` or\n`canonical-printer` to construct one manually. `render-out` and `render-str`\ntake a printer and a value if you need maximum control over the printing.\n\n## Syntax Coloring\n\nPuget's first major feature is colorizing the printed data by rendering it with\nembedded markup. Different syntax elements are given different colors to make\nthe printed output much easier for humans to parse. This is similar to syntax\nhighlighting, but much easier since the code works directly with the data\ninstead of parsing it from text!\n\nElements are mapped to color codes by the `:color-scheme` option. The\n`:print-color` option can be set to enable colorization using the `with-color`\nmacro - alternately, the `cprint` function always prints with colored output\nenabled.\n\nPuget supports three different kinds of color markup:\n- `:ansi` (the default) adds ANSI color escapes for terminal outputs.\n- `:html-inline` adds HTML `span` elements with inline `style` attributes.\n- `:html-classes` adds `span` elements with semantic `class` attributes.\n\nSee the [`puget.color.ansi`](src/puget/color/ansi.clj) namespace for the\navailable ANSI color styles which can be applied to syntax elements.\n\n## Canonical Representation\n\nPuget also provides _canonical serialization_ of data. In most cases, if two\ndata values are equal, they should be printed identically. This is important for\nwhen the printed data is hashed, but it also makes it easier to process maps and\nother structures with similar contents.\n\nPuget uses the [arrangement](https://github.com/greglook/clj-arrangement)\nlibrary to sort the values in sets and the keys in maps so they are always\nprinted the same way. This can be disabled with the `:sort-keys` option, or\nenabled only for collections under a certain size.\n\nMost printing is done with the `PrettyPrinter` class, but the library also\noffers the `CanonicalPrinter` for serializing data in a stricter (and more\ncompact) fashion.\n\n```clojure\n=\u003e (require '[puget.printer :as puget])\n\n=\u003e (puget/pprint #{'x :a :z 3 1.0})\n#{1.0 3 :a :z x}\n\n=\u003e (def usd (java.util.Currency/getInstance \"USD\"))\n#'user/usd\n\n=\u003e (puget/pprint usd)\n#\u003cjava.util.Currency@4cc4ee24 USD\u003e\n\n=\u003e (puget/render-out (puget/canonical-printer) usd)\n; IllegalArgumentException: No defined representation for class java.util.Currency: USD\n```\n\n## Type Extensions\n\nAll of Clojure's primitive types are given their standard print representations.\nTo handle non-standard data types, Puget supports a mechanism to dispatch to\ncustom _print handlers_. These take precedence over the normal rendering\nmechanisms.\n\nThis can be used to provide an EDN tagged-literal representation for certain\ntypes, or just avoid trying to pretty-print types which the engine struggles\nwith (such as Datomic database values).\n\nBefore rendering a value, the printer checks for a `:print-handlers` function.\nIf available, it is called with the type of the value to be printed. If the\nlookup returns a handler, that function is called with the value and the result\nis used as the rendered format of the value.\n\nThe [`puget.dispatch`](https://cljdoc.org/d/mvxcvi/puget/CURRENT/api/puget.dispatch)\nnamespace has functions to help build handler lookup functions. The\n`inheritance-lookup` constructor provides semantics similar to Clojure's\nmultimethod dispatch.\n\nAs an example, extending `#inst` formatting to clj-time's `DateTime`:\n\n```clojure\n=\u003e (require '[clj-time.core :as t]\n            '[clj-time.format :as f])\n\n=\u003e (puget/pprint (t/now))\n#\u003corg.joda.time.DateTime 2014-05-14T00:58:40.922Z\u003e\n\n=\u003e (def time-handlers\n     {org.joda.time.DateTime\n      (puget/tagged-handler\n        'inst\n        (partial f/unparse (f/formatters :date-time)))})\n#'user/time-handlers\n\n=\u003e (puget/pprint (t/now) {:print-handlers time-handlers})\n#inst \"2014-05-14T01:05:53.885Z\"\n```\n\nIf no handler is specified for a given type and it's not a built-in EDN type,\nPuget refers to the `:print-fallback` option, which must be one of:\n- `:pretty` (the default) prints a colored representation of the unknown value\n  (not valid EDN!).\n- `:print` falls back to the standard `pr-str` representation.\n- `:error` throws an exception for types with no defined representation.\n- A function which will be called with the printer and the unknown value to\n  render, returning the formatted value.\n\n## License\n\nThis is free and unencumbered software released into the public domain.\nSee the UNLICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreglook%2Fpuget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreglook%2Fpuget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreglook%2Fpuget/lists"}