Coder Social home page Coder Social logo

calvinmclean / survey Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 17 KB

A Gleam library to easily create rich and interactive prompts in the terminal for user input

License: Apache License 2.0

Gleam 100.00%
cli gleam gleam-lang terminal prompt user-input

survey's Introduction

survey

Package Version Hex Docs

A library to easily create rich and interactive prompts in the terminal.

Inpired by AlecAivazis/survey

Use survey.Question for String input and survey.Confirmation for Bool input.

gleam add survey
import survey
import gleam/option.{type Option, None, Some}

pub fn main() {
  let assert [
    #("first_name", survey.StringAnswer(first_name)),
    #("last_name", survey.StringAnswer(last_name)),
    #("survey_fan", survey.BoolAnswer(survey_fan)),
  ] =
    [
      #(
        "first_name",
        survey.new_question(
          prompt: "First Name:",
          help: Some("Please enter your first name"),
          default: None,
          validate: None,
          transform: None,
        ),
      ),
      #(
        "last_name",
        survey.new_question(
          prompt: "Last Name:",
          help: Some("Please enter your last name"),
          default: None,
          validate: None,
          transform: None,
        ),
      ),
      #(
        "survey_fan",
        survey.new_confirmation(
          prompt: "Are you a survey fan?:",
          help: Some("It's a great library"),
          default: Some(True),
          transform: Some(fn(_: Bool) -> Bool { True }),
        ),
      ),
    ]
    |> survey.ask_many(help: False)

  case survey_fan {
    True -> io.println("Hello, " <> first_name <> " " <> last_name <> "!")
    False -> io.println("I don't believe you")
  }
}
⟩ gleam run
   Compiled in 0.02s
    Running survey.main
First Name: Survey
Last Name: User
Are you a survey fan?: [Y/n] 
Hello, Survey User!

Further documentation can be found at https://hexdocs.pm/survey.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

survey's People

Contributors

calvinmclean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.