Skip to content

escherize/ice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ice

A lightweight terminal color formatting library for Clojure.

Ice Library Logo

Installation

deps.edn

{:deps 
 {io.github.escherize/ice {:git/sha "d55522c8f3dd078499f0eb9869cb2ddcc7e57b29"}}}

Usage

(require '[ice.core :as ice])

;; Basic colored output
;; p is for printing
(ice/p [:red "This text is red"])
(ice/p [:on-blue "This text has blue background"])
(ice/p [:bold "This text is bold"])

;; Combining colors with nesting
(ice/p [:red "This is red " [:blue "and this is blue"]])

;; Complex nested formatting
(ice/p [:red "Error: " [:bold "Operation failed"] " - please try again"])

;; Creating a color demo
(apply ice/p (vec 
               (mapcat (fn [color] [color (name color) " "]) 
                       (keys #'ice/colors))))

;; Getting colored string without printing (no newline added)
(def colored-text (ice/p-str [:green "Success!"]))
;; => Returns colored string without printing and without a trailing newline

;; Disable colors (useful for logging to files)
(binding [ice/*disable-colors* true]
  (ice/p [:red "This will not be colored"]))

;; Multiple arguments
(ice/p [:red "Error: "] [:bold "Failed!"] " Please try again.")

Functions

p

The p function prints colored text to *out*, always adding a newline at the end:

;; Print red text
(ice/p [:red "This is red"])

;; Print nested colors
(ice/p [:red "Red" [:blue " and blue"]])

;; Print multiple arguments
(ice/p [:red "Error:"] " " [:bold "Something went wrong"])

p-str

The p-str function returns a colored string without printing it and without the trailing newline:

;; Get red text as a string
(def red-text (ice/p-str [:red "This is red"]))
;; => "\033[31mThis is red\033[0m"

;; Use in string operations
(str "Prefix: " (ice/p-str [:green "Success"]) " :Suffix")
;; => "Prefix: \033[32mSuccess\033[0m :Suffix"

;; Useful for logging
(log/info (ice/p-str [:yellow "Warning:"] " " [:bold "Disk space low"]))

Note: Unlike many other Clojure string functions that add newlines, p-str does NOT add a trailing newline, so you can use it with println.

(def red-text (ice/p-str [:red "This is red"]))

(= "This is red" (ice/strip-color red-text))
;; => true

All the color options that can be used as the first element in vectors:

Text Colors

  • :red
  • :green
  • :yellow
  • :blue
  • :magenta
  • :cyan
  • :white
  • :gray/:grey

Background Colors

  • :on-red
  • :on-green
  • :on-yellow
  • :on-blue
  • :on-magenta
  • :on-cyan
  • :on-white
  • :on-gray/:on-grey

Text Formatting

  • :bold
  • :dark
  • :underline
  • :blink
  • :reverse-color
  • :concealed

License

Copyright ยฉ 2025 io.github.escherize

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at: https://www.eclipse.org/legal/epl-2.0/

About

๐Ÿ’  Iced out println

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors