Liking cljdoc? Tell your friends :D

me.pmatiello/tui

This library provides functions for simple terminal user interfaces in Clojure. It offers functions for rendering styled text, printing to stdout and reading from stdin.

Usage

This library is available on the clojars repository. Refer to the link in the image below for instructions on how to add it as a dependency to a Clojure project.

Clojars Project

The public functions are located in the me.pmatiello.tui.core namespace. Refer to the docstrings and specs of these functions for usage details and examples.

Examples

Import the me.pmatiello.tui.core namespace to use the provided functions.

(require '[me.pmatiello.tui.core :as tui])

Rendering a page as a string:

(tui/render ["plain" " "  "text"]) 
; returns "plain text"
(tui/render [{:style [:bold] :body "styled"} " " {:style [:bold] :body "text"}])
; returns "styled text", in bold

Printing to stdout:

(tui/print "plain" "text")
; prints "plain text", doesn't add a line break
(tui/println {:style [:bold] :body "styled"} {:style [:bold] :body "text"})
; prints "styled text", in bold, adds a line break

Reading from stdin:

(tui/read-line)
; reads one line from stdin and return it
(tui/read-lines)
; reads lines from stdin until EOF (ctrl+D) and return them

Pages

Rendering and printing functions take pages as arguments.

SpecDescription
::specs/pageCollection of ::specs/text
::specs/textEither a ::specs/body or a ::specs/body+style
::specs/bodyString
::specs/body+styleMap with :body (::specs/body) and :style (::specs/style)
::specs/styleCollection of ::specs/style*
::specs/style*A supported style (see below)

That is, a page is a collection of texts. Texts can either be strings or maps containing a body and a list of styles.

Some valid texts are:

"plain text"
{:style [:bold :fg-blue] :body "styled text"}

Styles

These are the supported styles:

ANSI CodeDescription
:resetResets all attributes and colors to default.
:boldBold intensity.
:faintFaint intensity.
:italicItalicized.
:underlineUnderline.
:slow-blinkSlow blink.
:fast-blinkFast blink.
:reverse-videoReverses the foreground and background colors.
:concealConceals the text.
:strikeStrikethrough.
:weight-offUnsets bold or faint intensity.
:italic-offUnsets italics.
:underline-offUnsets underline.
:blink-offUnsets blinking.
:reverse-video-offUnsets reverse video.
:conceal-offUnsets text concealment.
:strike-offUnsets strikethrough.
:fg-blackBlack text.
:fg-redRed text.
:fg-greenGreen text.
:fg-yellowYellow text.
:fg-blueBlue text.
:fg-purplePurple text.
:fg-cyanCyan text.
:fg-whiteWhite text.
:fg-defaultDefault text.
:bg-blackBlack background.
:bg-redRed background.
:bg-greenGreen background.
:bg-yellowYellow background.
:bg-blueBlue background.
:bg-purplePurple background.
:bg-cyanCyan background.
:bg-whiteWhite background.
:bg-defaultDefault background.

Development

Information for developing this library.

Running tests

The following command will execute the unit tests:

% clj -X:test

Building

The following command will build a jar file:

% clj -T:build jar

To clean a previous build, run:

% clj -T:build clean

Releasing

Before releasing, update the library version in the build.clj file.

Make a commit and generate a new tag:

% git commit -a -m "Release: ${VERSION}"
% git tag -a "v${VERSION}" -m "Release: ${VERSION}"
% git push
% git push origin "v${VERSION}" 

To release to clojars, run:

% mvn deploy:deploy-file \
      -Dfile=target/tui-${VERSION}.jar \
      -DrepositoryId=clojars \
      -Durl=https://clojars.org/repo \
      -DpomFile=target/classes/META-INF/maven/me.pmatiello/tui/pom.xml

Notice that this step requires clojars to be configured as a server in the local ~/.m2/settings.xml file.

Contribution Policy

This software is open-source, but closed to contributions.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close