Skip to content

A small Unison library serving ANSI escape codes and sequences for use in the terminal

Notifications You must be signed in to change notification settings

samgqroberts/ansi-escape-sequences-unison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

ansi-escape-sequences-unison

A small Unison library serving ANSI escape codes and sequences for use in the terminal.

Functionality

Text styling

The main interface for text styling is the format function:

format : [Style] -> Text -> Text

For example, let's say we had a string defined like this:

testString = "unstyled, " ++ (format [Style.italic, Style.bgRed, Style.rgb (1, 2, 3)] "styled") ++ ", and unstyled again"

If we printed that to the terminal, we'd get this (result provided via a screenshot, to preserve styling): Screenshot

Cursor positioning and visibility

The cursor namespace contains the following functions for controlling the cursor:

  1.  back               (Nat -> Text)
  2.  down               (Nat -> Text)
  3.  forward            (Nat -> Text)
  4.  hide               (Text)
  5.  horizontalAbsolute (Nat -> Text)
  6.  nextLine           (Nat -> Text)
  7.  position           (Nat -> Nat -> Text)
  8.  previousLine       (Nat -> Text)
  9.  show               (Text)
  10. up                 (Nat -> Text)

For example, let's say we had a runnable function like so:

demo = '(printLine ("line" ++ back 3 ++ "ak" ++ forward 1 ++ "side"))

When we run it, we can expect it to print "line", go back 3 characters, overwrite the characters there with "ak", skip forward 1 character, then finish with "side":

.> run demo
lakeside

Erasing

The erase namespace contains the display and inLine functions for erasing part or all of the screen or line, respectively.

The top-level clear term will clear the entire screen and reset the cursor position.

Installation

Pull the code into ucm via:

pull https://github.com/samgqroberts/ansi-escape-sequences-unison:.v2 external.ansi_escape_sequences_unison.v2

Acknowledgements

About

A small Unison library serving ANSI escape codes and sequences for use in the terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published