Skip to content

Commit

Permalink
Change options to be optional map (not varargs key/values)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlship committed Jan 6, 2016
1 parent 99802d5 commit 4cded27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Improved docstrings for ANSI font constants and functions.

**Incompatible change:** write-binary now expects an optional map (not a varargs of keys and values)
for options such as :ascii and :line-bytes.

## 0.1.20 - 4 Dec 2015

Pretty will identify repeating stack frames (for example, from an infinite loop)
Expand Down
Binary file modified docs/images/write-binary.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions src/io/aviso/binary.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns io.aviso.binary
"Utilities for formatting binary data (byte arrays) or binary deltas."
(:import (java.lang StringBuilder))
(:require [io.aviso
[ansi :as ansi]
[columns :as c]
Expand Down Expand Up @@ -88,10 +87,10 @@
- [[BinaryData]] to write
- option keys and values:
`:ascii` boolean
:ascii - boolean
: true to enable ASCII mode
`:line-bytes` number
:line-bytes - number
: number of bytes per line (defaults to 16 for ASCII, 32 otherwise)
In ASCII mode, the output is 16 bytes per line, but each line includes the ASCII printable characters:
Expand All @@ -104,10 +103,11 @@
A placeholder character (a space with magenta background) is used for any non-printable
character."
([data]
(write-binary *out* data))
([writer data & {show-ascii? :ascii
per-line-option :line-bytes}]
(let [per-line (or per-line-option
(write-binary *out* data nil))
([writer data options]
(let [{show-ascii? :ascii
per-line-option :line-bytes} options
per-line (or per-line-option
(if show-ascii? bytes-per-ascii-line bytes-per-line))
formatter (apply c/format-columns
(if show-ascii?
Expand All @@ -122,8 +122,10 @@

(defn format-binary
"Formats the data using [[write-binary]] and returns the result as a string."
[data & options]
(apply w/into-string write-binary data options))
([data]
(format-binary data nil))
([data options]
(apply w/into-string write-binary data options)))

(defn- match?
[byte-offset data-length data alternate-length alternate]
Expand Down

0 comments on commit 4cded27

Please sign in to comment.