GithubHelp home page GithubHelp logo

rigzad / prompt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silbermm/prompt

0.0 0.0 0.0 1.91 MB

Build interactive CLI's in Elixir

Home Page: https://git.sr.ht/~ahappydeath/prompt

License: GNU General Public License v3.0

Elixir 100.00%

prompt's Introduction

HEADS UP

All future development will happen at https://git.sr.ht/~ahappydeath/prompt

prompt_with_text_lighter

Hex.pm

Terminal UI Library for Elixir

Run in Livebook

Motivation

To create a really great development experience and API for Elixir developers that want to build commandline tools.

Installation

Add prompt to your list of dependencies in mix.exs:

def deps do
  [
    {:prompt, "~> 0.8.0"}
  ]
end

Read the official documentation

Basic Usage

All of the following commands take a keyword list of options for things like text color and positioning.

Display text on the screen

Prompt.display/2

Prompt.display("Hello, world!")

Ask the user for input

Prompt.text/2 Useful for prompting the user to enter freeform text

Prompt.text("Enter info here")

Will display:

> Enter info here:

and wait for the user to enter text

Ask the user for a password

Prompt.password/2 When you need to hide the input that the user types

Prompt.password("Enter password")

Ask the user for confirmation

Prompt.confirm/2

Prompt.confirm("Are you sure?")

Will display:

> Are you sure? (Y/n):

and will allow the user to just press [enter] to confirm

If you'd prefer n to be the default pass the default_answer option

Prompt.confirm("Are you sure?", default_answer: :no)

Returns :yes or :no based on the answer

Custom confirmation choices

Prompt.choice/2 Sometimes yes/no aren't the only choices a user can make, this method allows you to pass any choices as the confirmation.

Prompt.choice("Accept, Reload or Cancel", accept: "a", reload: "r", cancel: "c")

displays

> Accept, Reload or Cancel (A/r/c):

Returns the key of the answer i.e :accept, :reload or cancel in this exammple

List of selections

Prompt.select/2 To show the user a list of options to select from

Prompt.select("Choose a protocol", ["file://", "ssh://", "ftp://"])

Displays:

  [1] file://
  [2] ssh://
  [3] ftp://
> Choose a protocol [1-3]:

and returns a string of their choice

Tables

Prompt.table/2 To show a table of data

Prompt.table([["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]])

Will display

> +-------+------+---------+----------+
  | Hello | from | the     | terminal |
  | this  | is   | another | row      |
  +-------+------+---------+----------+

Advanced Usage with Subcommands

To use the more advanced features, see the official documentation

Example

For a complete example, take a look at Slim - a cherry-picking tool

prompt's People

Contributors

silbermm avatar rigzad avatar fozcodes avatar

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.