Coder Social home page Coder Social logo

jty's Introduction

jty

Utility functions for rich console output in the Janet Language.

Installation

jpm install https://github.com/dbridges/jty

Usage

Caveats

jty currently does not support unicode.

Layout

jty includes functions for basic single line string layouts:

(jty/pad-right "test" 6) ; => "test  "
(jty/pad-right "test" 6 ".") ; => "test.."

(jty/pad-left "test" 6) ; => "  test"
(jty/pad-left "test" 6 ".") ; => "..test"

(jty/fit-width "test" 3) ; => "te…"
(jty/fit-width "test" 6) ; => "test  "
(jty/fit-width "test" 6 :right) ; => "  test"

Formatting

jty includes functions for basic text formatting:

(print (jty/bold "bold") " "
       (jty/dim "dim") " "
       (jty/italic "italic") " "
       (jty/underline "underline") " "
       (jty/blink "blink") " "
       (jty/inverse "inverse") " "
       (jty/strikethrough "strikethrough"))

Colors

jty includes functions for foreground and background coloring with the standard 8 named colors, or using 8 bit or 24 bit coloring.

# Standard 8 foreground colors
(print (jty/fg :black "black") " "
       (jty/fg :red "red") " "
       (jty/fg :green "green") " "
       (jty/fg :yellow "yellow") " "
       (jty/fg :blue "blue") " "
       (jty/fg :magenta "magenta") " "
       (jty/fg :cyan "cyan") " "
       (jty/fg :white "white") " ")

# 8 bit foreground colors
(print (jty/fg 210 "J")
       (jty/fg 214 "a")
       (jty/fg 217 "n")
       (jty/fg 220 "e")
       (jty/fg 223 "t"))

# 24 bit foreground colors in RGB or hex
(print (jty/fg [9 165 184] "J")
       (jty/fg [7 149 175] "a")
       (jty/fg [7 123 165] "n")
       (jty/fg [7 113 155] "e")
       (jty/fg [7 101 145] "t") " "
       (jty/fg "#de6418" "L")
       (jty/fg "#de9518" "a")
       (jty/fg "#dec718" "n")
       (jty/fg "#d1de18" "g"))

# Standard 8 background colors
(print (jty/bg :black "black") " "
       (jty/bg :red "red") " "
       (jty/bg :green "green") " "
       (jty/bg :yellow "yellow") " "
       (jty/bg :blue "blue") " "
       (jty/bg :magenta "magenta") " "
       (jty/bg :cyan "cyan") " "
       (jty/bg :white "white") " ")

# 8 bit background colors
(print (jty/bg 210 " ")
       (jty/bg 214 " ")
       (jty/bg 217 " ")
       (jty/bg 220 " ")
       (jty/bg 223 " "))

# 24 bit background colors in RGB or hex
(print (jty/bg [9 165 184] " ")
       (jty/bg [7 149 175] " ")
       (jty/bg [7 123 165] " ")
       (jty/bg [7 113 155] " ")
       (jty/bg "#de6418" " ")
       (jty/bg "#de9518" " ")
       (jty/bg "#dec718" " ")
       (jty/bg "#d1de18" " "))

Cursor Movement

# Show/hide the cursor indicator
(jty/show-cursor)
(jty/hide-cursor)

# Move cursor to specific location
(jty/move-cursor [10 20])

# Move cursor up certain number of lines
(jty/move-cursor-up 3)

# Clear the line or screen
(jty/clear-line)
(jty/clear-screen)

Input

jty provides two helper functions for asking for input. Both functions can be provided with a default value.

(jty/prompt "Name") # prints "Name: " and waits for input.
(jty/prompt "Confirm" "Y") # returns "Y" if the user does not type input
(jty/prompt-number "Year") # loops until input can be parsed with scan-number
(jty/prompt-number "Year" 10) # return 10 if the user does not type input

Select Menu

jty provides a simple select menu to pick from a list of choices.

(jty/select "Select an option (j/k to move)" ["red" "blue" "green"])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.