bling.bannerbanner- Returns a multi-line Figlet (ascii art) string with the provided:textoption.
bling.browseransi-sgr-string->browser-dev-console-array- Converts an ANSI SGR-tagged string to a format specifier-tagged string, with a corresponding vector of css style strings.
bling.core!?sgr- Temporarily silences debugging of sgr code printing.?sgr- For debugging of ANSI SGR tagged output.bling- Returns a styled string tagged with ANSI SGR codes.bling-colors- Array map of the bling color pallette with light, dark, and medium entries for each color.bling-colors*- Array map of the bling color pallette.callout- Uses a predesigned template to format and print a message block.file-info-str- Creates a file-info string consisting of the file name, line number and column number.highlighted-location- Gets position of last occurence of highlighting in a potentially multi-line string.point-of-interest- Formatted and decorated diagram of a form with line, column, and file info.print-bling- Sugar for(println (bling ...)).stringified- Stringifies form to a specified with and height, with optionally supplied printing-fn such aspprint.with-ascii-underline- Reformats a potentially multi-line string to include an ascii underline at a specificed location.with-floating-label- Annotates a line of text at supplied index with floating label.
bling.explainexplain-malli- Prints a Malli validation error callout block viabling.core/callout.
bling.hifihifi- Hi-fidelity, pretty-printed string with syntax-coloring.print-hifi- Prints a structurally formatted value with syntax-coloring based on user's preferred theme.
(banner m)Function.
Returns a multi-line Figlet (ascii art) string with the provided
:text option. Intended to render a "single line" banner,
consisting of multiple lines of constituent characters.
Can be optionally colorized with the :gradient option,
using a small set of pre-defined gradients:
(banner {:text "Hello", :gradient-colors [:green :blue]})
(banner {:text "Hello", :gradient-colors [:red :magenta]})
(banner {:text "Hello", :gradient-colors [:yellow :purple]})
(banner {:text "Hello", :gradient-colors [:orange :purple]})
(banner {:text "Hello", :gradient-colors [:cool :warm]})Can be colorized solid with bling.core/bling
(bling [:red (banner {:text "Hello"})])Options:
-
:textstring?- Required.
- The text to set in the banner.
-
:font-weight#{:bold "bold"}- Optional.
- If set to
:bold, each subchar in figlet characters will be bolded. Only applies when a gradient is set.
-
:gradient-colors#{[:yellow :purple] ["orange" "purple"] ["yellow" "purple"] ["red" "magenta"] [:red :magenta] ["green" "blue"] ["cool" "warm"] [:green :blue] [:cool :warm] [:orange :purple]}- Optional.
- Sets the beginning and end colors of the gradient. Expects a vector of 2 keywords.
-
:gradient-direction#{:to-right "to-left" :to-top "to-top" :to-left "to-bottom" "to-right" :to-bottom}- Optional.
- Direction of the gradient.
-
:gradient-shift[:int {:min 0, :max 5}]- Optional.
- Defaults to
0. - If gradient is
[:warm :cool]pair, this will shift the hue.
-
:contrastkeyword?- Optional.
- Defaults to
:medium. - If gradient is set, this will force an overall lighter or
darker tone. If the user has a
BLING_MOODenv var set, it will default to:highin order to optimize contrast for the users terminal theme (light or dark)
-
:margin-topint?- Optional.
- Defaults to
1. - Amount of margin (in newlines) at top, outside banner.
-
:margin-bottomint?- Optional.
- Defaults to
0. - Amount of margin (in newlines) at bottom, outside banner.
-
:margin-leftint?- Optional.
- Defaults to
0. - Amount of margin (in blank character spaces) at left, outside banner.
-
:margin-rightint?- Optional.
- Defaults to
0. - Amount of margin (in blank character spaces) at right, outside banner.
(ansi-sgr-string->browser-dev-console-array s)Function.
Converts an ANSI SGR-tagged string to a format specifier-tagged string, with a corresponding vector of css style strings. The resulting string and styles can be supplied to a browser development console to format messages. See https://developer.chrome.com/docs/devtools/console/format-style for more background.
Replaces all ANSI SGR tags in supplied string with CSS format specifier tag, "%c". Analyzes all ANSI SGR tags, and produces a vector of corresponding css style strings. Returns a vector of the format-specifier-tagged strings, followed by the contents of the styles array. In ClojureScript, returns an array.
To print the value, with formatting, to dev console: (.apply js/console.log js/console console-array)
Usage in ClojureScript
```clojure
(def
console-array
(ansi-sgr-string->browser-dev-console-array (bling [:red :foo])))
;; =>
["%c:foo%c"
"color: #bb4747"
"line-height: 1.45; color: default"]
(!?sgr s)Function.
Temporarily silences debugging of sgr code printing. Returns the value.
(?sgr s)Function.
For debugging of ANSI SGR tagged output.
Prints the value with escaped ANSI SGR codes so you can read them in terminal emulators (otherwise text would just get colored). Preserves coloring.
Returns the value.
(bling & coll)Function.
Returns a styled string tagged with ANSI SGR codes.
Takes an arbitrary number strings or hiccup-like vectors. Hiccup vectors can be nested.
Bold text
(bling [:bold "Bold text"])Red text
(bling [:red "Red text"])Italic text
(bling [:italic "Italic text"])Bold red italic text
(bling [:bold.red.italic "Bold red italic text"])Bold red italic text, order of tags doesn't matter
(bling [:italic.bold.red "Bold red italic text"])Bold red italic text, and blue text
(bling
[:italic.bold.red "Bold red italic text"]
" and "
[:blue "blue text"])Italic black on yellow text
(bling [:italic.black.yellow-bg "Black on yellow text"])Italic black on yellow text, with hiccup map syntax
(bling
[{:font-style :italic, :font-color :black, :background-color :yellow}
"Black on yellow text"])Bling color pallette
(bling [:red "Red text"])
(bling [:orange "Orange text"])
(bling [:yellow "Yellow text"])
(bling [:olive "Olive text"])
(bling [:green "Green text"])
(bling [:blue "Blue text"])
(bling [:purple "Purple text"])
(bling [:magenta "Magenta text"])
(bling [:gray "Gray text"])
(bling [:black "Black text"])
(bling [:white "White text"])Bling color aliases
(bling [:error "Error"])
(bling [:negative "Negative"])
(bling [:warning "Warning"])
(bling [:success "Success"])
(bling [:accent "Success"])
(bling [:neutral "Neutral"])
(bling [:subtle "Subtle"])Nested hiccup example
(print-bling
[:p "First paragraph"]
[:p
[:bold
"Bold, "
[:italic "bold italic, " [:red "bold italic red, "]]
"bold."]]
"Last line")Array map of the bling color pallette with light, dark, and medium entries for each color.
{...
"purple" {:sgr 141
:css "#af87ff"
:sgr-dark 129
:sgr-light 147
:css-dark "#af00ff"
:css-light "#afafff"}
"medium-purple" {:sgr 141 :css "#af87ff"}
"dark-purple" {:sgr 129 :css "#af00ff"}
"light-purple" {:sgr 147 :css "#afafff"}
...}Array map of the bling color pallette.
{...
"purple" {:sgr 141 :css "#af87ff"}
...}(callout x & args)Function.
Uses a predesigned template to format and print a message block.
Prints a message to the console with a block-based coloring motif.
Returns nil.
If the :data? option is set to true, it does not print anything, and
returns a data representation of the formatting and styling.
Callout uses any one of a number of predesigned templates to format a block
of information that is delineated by an optionally colored border motif.
The color of the border is determined by the value of the :type option,
or the :colorway option. The characteristics of this border are controlled
by the :theme option. By default, a label is printed in the block
start position.
For callouts of the type :error, :warning, or :info, the label
string will default to an uppercased version of that string, e.g.
{:type :INFO} => "INFO". If a :label option is supplied, that value is
used instead. When you want to omit label for callouts of the type :error,
:warning, or :info, you must explicitly set the :label option to an
empty string.
If two arguments are provided, the first should be a map of valid options.
Example call with all of the options
(callout {:type :error ; :warning, :info
;; :colorway :purple ; <- any bling palette color, overrides :type
;; :label "My label" ; overrides label assigned by :type
:side-label "My side label" ; must have a :label if you want a :side-label
:theme :sideline ; :sideline :sandwich :gutter
:label-theme :simple ; :simple :marquee
;; :padding-block 0
;; :padding-top 0
;; :padding-bottom 0
;; :padding-inline 2
;; :padding-left 2
;; :padding-right 0
;; :margin-top 1
;; :margin-botom 0
;; :margin-left 0
;; :data? true ; <- just returns string, no printing
:border-shape :sharp ; :round
:border-style :solid ; :double
:border-weight :normal ; :bold
:width 40
:min-width 40
;; --- The options below exclusive to :theme of :boxed ---
;; :border-char "*"
;; :vertical-border-char "**"
;; :max-width 100
;; :padding-block 1
;; :padding-inline 2
}
(bling [:bold (str "Line 1" "\n" "Line 2")]))Options:
-
:colorway#{"neutral" "magenta" "warning" "positive" :neutral "info" :green :positive "negative" :negative "error" "subtle" :warning "green" :info :error :magenta :subtle}- Optional.
- The color of the border, or gutter, depending on the value of
:theme.
-
:theme#{:boxed :sideline :sandwich :gutter}- Optional.
- Defaults to
:sideline. - Name of callout layout template.
-
:labelany?- Optional.
- Labels the callout.
In the case of a callout
:typeof:warning,:error, or:info, the value of the label will default toWARNING,ERROR, orINFO, respectively.
-
:side-labelany?- Optional.
- Side label to the the callout label. In the case of a callout
:typeof:warning,:error, or:info, the value of the label will default toWARNING,ERROR, orINFO, respectively.
-
:label-theme#{:simple :marquee}- Optional.
- Defaults to
:simple. - Name of label flavor.
-
:padding-blockint?- Optional.
- Defaults to
1. - Amount of padding (in newlines) at top and bottom, inside callout.
-
:padding-topint?- Optional.
- Defaults to
1. - Amount of padding (in newlines) at top, inside callout.
-
:padding-bottomint?- Optional.
- Defaults to
1. - Amount of padding (in newlines) at bottom, inside callout.
-
:padding-inlineint?- Optional.
- Defaults to
2. - Amount of padding (in blank character spaces) at left and right, inside callout.
-
:padding-leftint?- Optional.
- Defaults to
2. - Amount of padding (in blank character spaces) at left, inside callout.
-
:margin-topint?- Optional.
- Defaults to
1. - Amount of margin (in newlines) at top, outside callout. Only applies to terminal emulator printing.
-
:margin-bottomint?- Optional.
- Defaults to
0. - Amount of margin (in newlines) at bottom, outside callout. Only applies to terminal emulator printing.
-
:margin-leftint?- Optional.
- Defaults to
0. - Amount of margin (in blank character spaces) at left, outside callout.
-
:data?boolean?- Optional.
- Returns a data representation of result instead of printing it.
-
:header-padding-leftint?- Optional.
- Defaults to
2. - Amount of left margin (in character spaces) for the label, in the callout header
-
:header-gapint?- Optional.
- Defaults to
5. - The gap (in character spaces) the label and the optional side lable, in the callout header.
-
:border-style#{:double :solid}- Optional.
- Defaults to
:solid. - The style of box-drawing character used.
-
:border-weight#{:bold :normal}- Optional.
- Defaults to
:normal. - The weight of box-drawing character used. Applies only to
:border-styleof:solid
-
:border-shape#{:round :sharp}- Optional.
- Defaults to
:sharp. - The corner shape of the borders, either sharp or round. Only applies when
:border-styleis:solidAND:border-weightis:normal
-
:border-notches?boolean?- Optional.
- Defaults to
:false. - Only applies to
:sandwichcallout theme. Will use top-left-corner and bottom-right-corner box-drawing chars for first character of header and footer borders.
-
:widthpos-int?- Optional.
- Width of the box in number of chars, aka columns in terminal. If not set, will be the width of the terminal. If terminal width cannot be detected, will fallback to 80.
-
:min-widthpos-int?- Optional.
- Min width of box in number of chars, aka columns in
terminal. Overridden by the
:widthvalue, if set.
-
:border-charstring?- Optional.
- A char that will override the default box-drawing
-
:vertical-border-charstring?- Optional.
- A char that will override the default box-drawing character, for the vertical borders.
-
:horizontal-border-charstring?- Optional.
- A char that will override the default box-drawing character, for the horizontal borders.
-
:box-drawing-style#{:bold :thin-round :double "thin" :thin "thin-round" "double" "bold"}- Optional.
- The style of box-drawing character used.
-
:max-widthpos-int?- Optional.
- Max width of box in number of chars, aka columns in
terminal. Overridden by the
:widthvalue, if set.
(file-info-str {:keys [:file :line :column :line-style :column-style :file-style :style], :or {style {}}})Function.
Creates a file-info string consisting of the file name, line number and column number. Optionally styled with Bling.
Basic example
(file-info-str {:file "foo.cljc", :line 42, :column 44})
;; =>
"foo.cljc:42:44"Options:
-
:lineint?- Optional.
- Line number
-
:columnint?- Optional.
- Column number
-
:file-stylemap?- Optional.
- CSS style map for the file name
-
:line-stylemap?- Optional.
- CSS style map for the line number
-
:column-stylemap?- Optional.
- CSS style map for the column number
-
:stylemap?- Optional.
- CSS style map for file-info string
(highlighted-location s)
(highlighted-location s target-highlight-style)Function.
Gets position of last occurence of highlighting in a potentially
multi-line string. Designed to pinpoint highlighting that was
applied to a form using bling.hifi/hifi (with :find option).
If an :underline-char option is supplied, the map returned will
include a string that can be used as a distinct line with an ascii
underline for the supplied stringified form. This underline line is
optionally decorated with a supplied :text-decoration-style map.
If a :floating-annotation-text option is supplied, the string
will be annotated. This string is optionally decorated with a
supplied :floating-annotation-style map.
Options:
:class#{:highlight-error-universal :highlight-error-dark :highlight-error-light}- Optional.
- Highlight style class
(point-of-interest
{:keys
[form
line
column
header-file-info-style
header-file-name-style
header-line-number-style
header-column-number-style
margin-block
margin-top
margin-bottom
gutter-line-number-style],
:as opts})Function.
Formatted and decorated diagram of a form with line, column, and file info.
Provides the namespace, column, and line number and a representation of the specific form of interest.
The :line, :column, and :form options must all be present in
order for the info diagram to be rendered. If the :form option is supplied,
but any of the others are omitted, only the form will be rendered.
If the form is provided is a collection, it will be stringified and truncated at 33 chars.
To print a multi-line form, pre-format the :form value with
bling.core/stringified, or bling.hifi/hifi.
If you would like to print a multi-line form with individual subforms
highlighted, you can pre-format the :form value with some combo of
bling.hifi/hifi (with :find option supplied),
bling.core/with-ascii-underline, and bling.core/with-floating-label.
By default, the diagram is created with a leading and trailing newlines,
via a default value of 1 for :margin-block. This can be set to zero,
or increased, with the :margin-block option.
Basic Example
(point-of-interest
{:form (+ 1 true), :line 42, :column 11, :file "myfile.core"})With styled file-info
(point-of-interest
{:form (+ 1 true),
:header-file-name-style {:color :subtle, :font-style :italic},
:line 42,
:header-line-number-style {:color :red},
:gutter-line-number-style {:color :red, :font-style :italic},
:column 11,
:file "myfile.core"})With collection supplied as :form
(point-of-interest
{:form
{:a 1,
:b [333 444 555],
:c "aadfasdfasdfads",
:d "asdfasdfasdfasdfasdfasdf"},
:header-file-info-style {:color :subtle, :font-style :italic},
:line 42,
:column 11,
:file "myfile.core"})Options:
-
:filestring?- Optional.
- File or namespace
-
:header-file-info-stylemap?- Optional.
- File info style, in header of point-of-interest diagram.
This will apply default styles to
:header-file-name-style,:header-line-number-style,:header-column-number-style,
and:gutter-line-number-style.
-
:header-file-name-stylemap?- Optional.
- File name style, in header of point-of-interest diagram
-
:lineint?- Optional.
- Line number
-
:header-line-number-stylemap?- Optional.
- Line number style, in header of point-of-interest diagram
-
:gutter-line-number-stylemap?- Optional.
- Gutter line number style, in header of point-of-interest diagram
-
:columnint?- Optional.
- Column number
-
:header-column-number-stylemap?- Optional.
- Column number style, in header of point-of-interest diagram
-
:margin-blockint?- Optional.
- Defaults to
1. - Controls the number of blank lines above and below the diagram.
-
:margin-topint?- Optional.
- Defaults to
1. - Controls the number of blank lines above the diagram.
-
:margin-bottomint?- Optional.
- Defaults to
1. - Controls the number of blank lines below the diagram.
(print-bling & args)Function.
Sugar for (println (bling ...)).
In JVM Clojure, cljs(Node), and bb, print-bling is sugar for:
(println (bling [:bold.blue "my blue text"])).
In cljs(browser), print-bling is sugar for the the following:
(print-to-browser-dev-console (bling [:bold.blue "my blue text"])).
print bold text
(print-bling [:bold "Bold text"])(stringified form)
(stringified form {:keys [height width printing-fn]})Function.
Stringifies form to a specified with and height, with optionally
supplied printing-fn such as pprint
("with-ascii-underline[s {:keys [line-index underline-char text-decoration-style text-decoration-color text-decoration-weight] :or {text-decoration-style :wavy line-index ::unsupplied} :as opts}]")Function.
Reformats a potentially multi-line string to include an ascii underline at a specificed location.
If supplied value for :form is a multi-line string, and supplied
value for :line-index is an integer less than the number of lines
present, inserts an ascii underline below the specified row.
Options:
-
:offsetpos-int?- Required.
- Controls offset, in columns, of the underline. If not provided, defaults to index of first non-blank character in line first.
-
:widthpos-int?- Required.
- Defaults to
3. - Controls the width, in columns, of the underline. If not provided, defaults to the length of the line, minus leading blank spaces
-
:underline-charkeyword?- Optional.
- Char used to build the ascii underline.
Overrides
:text-decoration-style
-
:text-decoration-colorkeyword?- Optional.
- Controls the color of the underline.
-
:text-decoration-weight#{:bold "normal" :normal "bold"}- Optional.
- Controls the font-weight of the underline.
-
:text-decoration-style#{:double :wavy :solid :dashed :dotted}- Optional.
- Defaults to
:wavy. - Controls the ascii char used to construct the underline.
(with-floating-label s {:keys [line-index label-text label-style label-offset]})Function.
Annotates a line of text at supplied index with floating label.
This label is optionally decorated with a supplied :floating-annotation-style map.
Options:
-
:label-textstring?- Required.
- The text of the floating annotation.
-
:label-stylemap?- Optional.
- Controls the style of the floating annotation
-
:label-offsetpos-int?- Optional.
- Defaults to
3. - Controls offset of the floating annotation
(explain-malli schema v)
(explain-malli schema v opts)Macro.
Prints a Malli validation error callout block via bling.core/callout.
Within the block, the value is pretty-printed, potentially with syntax
coloring. The problem value is highlighted with the :highlight-error
class of the active fireworks theme, or the :highlight-error-underlined
class, if the value is not a collection.
If three arguments are provided, the third should be a map with the following optional keys:
-
:function-namestring?- Optional.
- The name of the function that can be used to construct the source location.
-
:spacing#{"compact" :compact}- Optional.
- If the value of
:spacingis set to:compact, the callout is compacted vertically.
-
:display-schema?boolean?- Optional.
- Displays the schema passed to the underlying call to
malli.core/explain.
-
:display-explain-data?boolean?- Optional.
- Displays the output of
malli.core/explainwithin the callout block.
-
:callout-optsmap?- Optional.
- A map of options for the underlying call to bling.core/callout.
-
:hifi-optsmap?- Optional.
- The options map for bling.hifi/hifi
-
:filestring?- Optional.
- The file name of the call site. This value be automatially supplied by the macro, so only use if you want to manually override
-
:lineint?- Optional.
- The line number of the call site. This value be automatially supplied by the macro, so only use if you want to manually override.
-
:columnint?- Optional.
- The column number of the call site. This value be automatially supplied by the macro, so only use if you want to manually override.
-
:highlighted-problem-section-labelstring?- Optional.
- Label for the highlighted problem diagram
-
:section-body-indentationpos-int?- Optional.
- Number of spaces to indent the body of each section
-
:preamble-section-labelstring?- Optional.
- The label of the preamble section
-
:preamble-section-bodystring?- Optional.
- The body of the preamble section
-
:success-messagestring?- Optional.
- The message to display if value passes schema validation
(hifi x)
(hifi x opts)Function.
Hi-fidelity, pretty-printed string with syntax-coloring.
Dispatches to fireworks.core/_p2.
More information about the available options can be found here
(print-hifi x)
(print-hifi x opts)Function.
Prints a structurally formatted value with syntax-coloring based on user's preferred theme. Dispatches to fireworks.core/_p2.
In JVM Clojure, cljs(Node), and bb, print-hifi is sugar for:
(println (bling.core/hifi x))
In cljs (browser dev consoles), print-hifi is sugar for the the following:
(->> (bling.core/hifi x)
bling.browser/ansi-sgr-string->browser-dev-console-array
(.apply js/console.log js/console))More information about the available options can be found here